Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
26 / 26
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
StatusCommand
100.00% covered (success)
100.00%
26 / 26
100.00% covered (success)
100.00%
2 / 2
12
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __invoke
100.00% covered (success)
100.00%
25 / 25
100.00% covered (success)
100.00%
1 / 1
11
1<?php
2
3declare(strict_types=1);
4
5namespace Celema\Verba\Command;
6
7use Celema\Console\Command;
8use Celema\Console\Io;
9use Celema\Console\Opt;
10use Celema\Verba\Tool\Domain;
11use Celema\Verba\Tool\Status;
12
13/**
14 * `i18n:status` — report translation gaps per domain and locale.
15 *
16 * @api
17 */
18#[Command('i18n:status', 'Report translation gaps per domain and locale')]
19final class StatusCommand
20{
21    /**
22     * @param list<Domain> $domains
23     */
24    public function __construct(
25        private readonly array $domains,
26    ) {}
27
28    public function __invoke(
29        Io $io,
30        #[Opt('Exit non-zero when anything is missing, untranslated, or obsolete')]
31        bool $strict = false,
32        #[Opt('List the source locations of the gaps and the obsolete ids')]
33        bool $where = false,
34    ): int {
35        $clean = true;
36
37        foreach ($this->domains as $domain) {
38            $report = new Status($domain)->run();
39            $clean = $clean && $report->clean();
40            $io->line('i18n: %s', $report->domain);
41
42            foreach ($report->locales as $locale => $stat) {
43                $io->line(
44                    '  %s  %d/%d translated, %d missing, %d untranslated, %d obsolete',
45                    $locale,
46                    $stat['translated'],
47                    $stat['total'],
48                    $stat['missing'],
49                    $stat['untranslated'],
50                    $stat['obsolete'],
51                );
52
53                if ($where) {
54                    foreach ($stat['locations'] as $location) {
55                        $io->line('    %s', $location);
56                    }
57
58                    // Vanished ids are still in the live section; a sync parks them.
59                    foreach ($stat['vanished'] as $id) {
60                        $io->line('    vanished: %s', $id);
61                    }
62
63                    foreach ($stat['parked'] as $id) {
64                        $io->line('    parked: %s', $id);
65                    }
66                }
67            }
68
69            foreach ($report->warnings as $warning) {
70                $io->warn('  %s', $warning);
71            }
72        }
73
74        return $strict && !$clean ? 1 : 0;
75    }
76}