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
 __invoke
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 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\Sync;
13
14/**
15 * `i18n:sync` — extract messages and reconcile every domain's catalog files.
16 *
17 * @api
18 */
19#[Command('i18n:sync', 'Extract messages and reconcile catalog files')]
20#[Opt('--prune', 'Drop obsolete messages from the catalogs')]
21final class SyncCommand
22{
23    /**
24     * @param list<Domain> $domains
25     */
26    public function __construct(
27        private readonly array $domains,
28    ) {}
29
30    public function __invoke(Args $args, Io $io): int
31    {
32        $prune = $args->has('--prune');
33
34        foreach ($this->domains as $domain) {
35            $report = new Sync($domain, $prune)->run();
36            $io->echoln("i18n: {$report->domain}");
37
38            foreach ($report->locales as $locale => $stat) {
39                $io->echoln(sprintf(
40                    '  %s  %d messages, %d added, %d obsolete%s',
41                    $locale,
42                    $stat['total'],
43                    $stat['added'],
44                    $stat['obsolete'],
45                    $stat['changed'] ? '' : ' (unchanged)',
46                ));
47            }
48
49            foreach ($report->warnings as $warning) {
50                $io->warn('  ' . $warning);
51            }
52        }
53
54        return 0;
55    }
56}