Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
24 / 24
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
StatusCommand
100.00% covered (success)
100.00%
24 / 24
100.00% covered (success)
100.00%
2 / 2
10
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%
23 / 23
100.00% covered (success)
100.00%
1 / 1
9
1<?php
2
3declare(strict_types=1);
4
5namespace Celema\Verba\Command;
6
7use Celema\Console\Args;
8use Celema\Console\Command;
9use Celema\Console\Io;
10use Celema\Console\Opt;
11use Celema\Verba\Tool\Domain;
12use Celema\Verba\Tool\Status;
13
14/**
15 * `i18n:status` — report translation gaps per domain and locale.
16 *
17 * @api
18 */
19#[Command('i18n:status', 'Report translation gaps per domain and locale')]
20#[Opt('--strict', 'Exit non-zero when anything is missing, untranslated, or obsolete')]
21#[Opt('--where', 'List the source locations of the gaps')]
22final class StatusCommand
23{
24    /**
25     * @param list<Domain> $domains
26     */
27    public function __construct(
28        private readonly array $domains,
29    ) {}
30
31    public function __invoke(Args $args, Io $io): int
32    {
33        $strict = $args->has('--strict');
34        $where = $args->has('--where');
35        $clean = true;
36
37        foreach ($this->domains as $domain) {
38            $report = new Status($domain)->run();
39            $clean = $clean && $report->clean();
40            $io->echoln("i18n: {$report->domain}");
41
42            foreach ($report->locales as $locale => $stat) {
43                $io->echoln(sprintf(
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->echoln('    ' . $location);
56                    }
57                }
58            }
59
60            foreach ($report->warnings as $warning) {
61                $io->warn('  ' . $warning);
62            }
63        }
64
65        return $strict && !$clean ? 1 : 0;
66    }
67}