Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
SyncCommand
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
2 / 2
8
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%
17 / 17
100.00% covered (success)
100.00%
1 / 1
7
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\Sync;
12
13/**
14 * `i18n:sync` — extract messages and reconcile every domain's catalog files.
15 *
16 * @api
17 */
18#[Command('i18n:sync', 'Extract messages and reconcile catalog files')]
19final class SyncCommand
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('Drop obsolete messages from the catalogs')]
31        bool $prune = false,
32    ): int {
33        foreach ($this->domains as $domain) {
34            $report = new Sync($domain, $prune)->run();
35            $io->line('i18n: %s', $report->domain);
36
37            foreach ($report->locales as $locale => $stat) {
38                $io->line(
39                    '  %s  %d messages, %d added, %d obsolete%s',
40                    $locale,
41                    $stat['total'],
42                    $stat['added'],
43                    $stat['obsolete'],
44                    $stat['changed'] ? '' : ' (unchanged)',
45                );
46
47                foreach ($stat['vanished'] as $id) {
48                    $io->line('    %s: %s', $prune ? 'dropped' : 'parked', $id);
49                }
50            }
51
52            foreach ($report->warnings as $warning) {
53                $io->warn('  %s', $warning);
54            }
55        }
56
57        return 0;
58    }
59}