Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
SyncCommand
100.00% covered (success)
100.00%
17 / 17
100.00% covered (success)
100.00%
2 / 2
6
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%
16 / 16
100.00% covered (success)
100.00%
1 / 1
5
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\Sync;
11
12/**
13 * `i18n:sync` — extract messages and reconcile every domain's catalog files.
14 *
15 * @api
16 */
17final class SyncCommand extends Command
18{
19    protected string $group = 'i18n';
20    protected string $prefix = 'i18n';
21    protected string $name = 'sync';
22    protected string $description = 'Extract messages and reconcile catalog files';
23
24    /**
25     * @param list<Domain> $domains
26     */
27    public function __construct(
28        private readonly array $domains,
29    ) {}
30
31    #[\Override]
32    public function run(): int
33    {
34        $prune = new Opts()->has('--prune');
35
36        foreach ($this->domains as $domain) {
37            $report = new Sync($domain, $prune)->run();
38            $this->echoln("i18n: {$report->domain}");
39
40            foreach ($report->locales as $locale => $stat) {
41                $this->echoln(sprintf(
42                    '  %s  %d messages, %d added, %d obsolete%s',
43                    $locale,
44                    $stat['total'],
45                    $stat['added'],
46                    $stat['obsolete'],
47                    $stat['changed'] ? '' : ' (unchanged)',
48                ));
49            }
50
51            foreach ($report->warnings as $warning) {
52                $this->warn('  ' . $warning);
53            }
54        }
55
56        return 0;
57    }
58}