Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
25 / 25
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
StatusCommand
100.00% covered (success)
100.00%
25 / 25
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
 run
100.00% covered (success)
100.00%
24 / 24
100.00% covered (success)
100.00%
1 / 1
9
1<?php
2
3declare(strict_types=1);
4
5namespace Celemas\Verba\Command;
6
7use Celemas\Cli\Command;
8use Celemas\Cli\Opts;
9use Celemas\Verba\Tool\Domain;
10use Celemas\Verba\Tool\Status;
11
12/**
13 * `i18n:status` — report translation gaps per domain and locale. `--strict`
14 * exits non-zero when anything is missing, untranslated, or obsolete;
15 * `--where` lists the source locations of the gaps.
16 *
17 * @api
18 */
19final class StatusCommand extends Command
20{
21    protected string $group = 'i18n';
22    protected string $prefix = 'i18n';
23    protected string $name = 'status';
24    protected string $description = 'Report translation gaps per domain and locale';
25
26    /**
27     * @param list<Domain> $domains
28     */
29    public function __construct(
30        private readonly array $domains,
31    ) {}
32
33    #[\Override]
34    public function run(): int
35    {
36        $opts = new Opts();
37        $strict = $opts->has('--strict');
38        $where = $opts->has('--where');
39        $clean = true;
40
41        foreach ($this->domains as $domain) {
42            $report = new Status($domain)->run();
43            $clean = $clean && $report->clean();
44            $this->echoln("i18n: {$report->domain}");
45
46            foreach ($report->locales as $locale => $stat) {
47                $this->echoln(sprintf(
48                    '  %s  %d/%d translated, %d missing, %d untranslated, %d obsolete',
49                    $locale,
50                    $stat['translated'],
51                    $stat['total'],
52                    $stat['missing'],
53                    $stat['untranslated'],
54                    $stat['obsolete'],
55                ));
56
57                if ($where) {
58                    foreach ($stat['locations'] as $location) {
59                        $this->echoln('    ' . $location);
60                    }
61                }
62            }
63
64            foreach ($report->warnings as $warning) {
65                $this->warn('  ' . $warning);
66            }
67        }
68
69        return $strict && !$clean ? 1 : 0;
70    }
71}