• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

move-elevator / composer-translation-validator / 15991591801

01 Jul 2025 06:26AM UTC coverage: 85.714% (-3.9%) from 89.647%
15991591801

Pull #11

github

web-flow
Merge 770fcc207 into da6f9b819
Pull Request #11: feat: add json output format

77 of 102 new or added lines in 6 files covered. (75.49%)

3 existing lines in 2 files now uncovered.

402 of 469 relevant lines covered (85.71%)

2.26 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.67
/src/Validator/MismatchValidator.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace MoveElevator\ComposerTranslationValidator\Validator;
6

7
use MoveElevator\ComposerTranslationValidator\Parser\ParserInterface;
8
use MoveElevator\ComposerTranslationValidator\Parser\XliffParser;
9
use MoveElevator\ComposerTranslationValidator\Parser\YamlParser;
10
use Symfony\Component\Console\Helper\Table;
11
use Symfony\Component\Console\Helper\TableStyle;
12
use Symfony\Component\Console\Input\InputInterface;
13
use Symfony\Component\Console\Output\OutputInterface;
14

15
class MismatchValidator extends AbstractValidator implements ValidatorInterface
16
{
17
    /** @var array<string, array<string>> */
18
    protected array $keyArray = [];
19

20
    public function processFile(ParserInterface $file): array
4✔
21
    {
22
        $keys = $file->extractKeys();
4✔
23

24
        if (!$keys) {
4✔
25
            $this->logger?->error('The source file '.$file->getFileName().' is not valid.');
1✔
26

27
            return [];
1✔
28
        }
29
        foreach ($keys as $key) {
3✔
30
            $value = $file->getContentByKey($key);
3✔
31
            $this->keyArray[$file->getFileName()][$key] = $value ?? null;
3✔
32
        }
33

34
        return [];
3✔
35
    }
36

37
    public function postProcess(): void
2✔
38
    {
39
        $allKeys = [];
2✔
40
        foreach ($this->keyArray as $values) {
2✔
41
            $allKeys[] = array_keys($values);
2✔
42
        }
43
        $allKeys = array_unique(array_merge(...$allKeys));
2✔
44

45
        foreach ($allKeys as $key) {
2✔
46
            $missingInSome = false;
2✔
47
            foreach ($this->keyArray as $keys) {
2✔
48
                if (!array_key_exists($key, $keys)) {
2✔
49
                    $missingInSome = true;
1✔
50
                    break;
1✔
51
                }
52
            }
53
            if ($missingInSome) {
2✔
54
                $result = [
1✔
55
                    'key' => $key,
1✔
56
                    'files' => [],
1✔
57
                ];
1✔
58
                foreach ($this->keyArray as $file => $keys) {
1✔
59
                    $result['files'][] = [
1✔
60
                        'file' => $file,
1✔
61
                        'value' => array_key_exists($key, $keys)
1✔
62
                        ? $keys[$key]
1✔
63
                        : null,
64
                    ];
1✔
65
                }
66
                $this->issues[] = $result;
1✔
67
            }
68
        }
69
    }
70

71
    /**
72
     * @param array<string, array<int, array{
73
     *     key: string,
74
     *     files: array<int, array{
75
     *         file: string,
76
     *         value: string|null
77
     *     }>
78
     * }>> $issueSets
79
     */
80
    public function renderIssueSets(InputInterface $input, OutputInterface $output, array $issueSets): void
1✔
81
    {
82
        $rows = [];
1✔
83
        $header = ['Key'];
1✔
84
        $allFiles = [];
1✔
85

86
        // Sammle alle Dateinamen (Spalten) und baue die Zeilen
87
        foreach ($issueSets as $issuesPerFile) {
1✔
88
            foreach ($issuesPerFile as $issues) {
1✔
89
                $key = $issues['key'];
1✔
90
                $files = $issues['files'];
1✔
91
                if (empty($allFiles)) {
1✔
92
                    $allFiles = array_column($files, 'file');
1✔
93
                    $header = array_merge(['Key'], array_map(static fn ($f) => "<fg=red>$f</>", $allFiles));
1✔
94
                }
95
                $row = [$key];
1✔
96
                foreach ($files as $fileInfo) {
1✔
97
                    $row[] = $fileInfo['value'] ?? '<fg=yellow><missing></>';
1✔
98
                }
99
                $rows[] = $row;
1✔
100
            }
101
        }
102

103
        (new Table($output))
1✔
104
            ->setHeaders($header)
1✔
105
            ->setRows($rows)
1✔
106
            ->setStyle(
1✔
107
                (new TableStyle())
1✔
108
                    ->setCellHeaderFormat('%s')
1✔
109
            )
1✔
110
            ->render();
1✔
111
    }
112

113
    public function explain(): string
1✔
114
    {
115
        return 'This validator checks for keys that are present in some files but not in others. '
1✔
116
            .'It helps to identify mismatches in translation keys across different translation files.';
1✔
117
    }
118

119
    /**
120
     * @return class-string<ParserInterface>[]
121
     */
UNCOV
122
    public function supportsParser(): array
×
123
    {
UNCOV
124
        return [XliffParser::class, YamlParser::class];
×
125
    }
126
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc