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

move-elevator / composer-translation-validator / 16213481303

11 Jul 2025 06:33AM UTC coverage: 95.336% (+1.5%) from 93.814%
16213481303

Pull #26

github

jackd248
feat: implement configuration factory and file reader for translation validator
Pull Request #26: feat: implement configuration factory and file reader for translation validator

213 of 218 new or added lines in 7 files covered. (97.71%)

1206 of 1265 relevant lines covered (95.34%)

7.27 hits per line

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

96.83
/src/Result/AbstractValidationResultRenderer.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace MoveElevator\ComposerTranslationValidator\Result;
6

7
use MoveElevator\ComposerTranslationValidator\Validator\ResultType;
8
use Symfony\Component\Console\Output\OutputInterface;
9

10
abstract class AbstractValidationResultRenderer implements ValidationResultRendererInterface
11
{
12
    public function __construct(
65✔
13
        protected readonly OutputInterface $output,
14
        protected readonly bool $dryRun = false,
15
        protected readonly bool $strict = false,
16
    ) {
17
    }
65✔
18

19
    protected function generateMessage(ValidationResult $validationResult): string
46✔
20
    {
21
        $resultType = $validationResult->getOverallResult();
46✔
22

23
        if (!$resultType->notFullySuccessful()) {
46✔
24
            return 'Language validation succeeded.';
13✔
25
        }
26

27
        return match (true) {
28
            $this->dryRun && ResultType::ERROR === $resultType => 'Language validation failed with errors in dry-run mode.',
33✔
29
            $this->dryRun && ResultType::WARNING === $resultType => 'Language validation completed with warnings in dry-run mode.',
28✔
30
            $this->strict && ResultType::WARNING === $resultType => 'Language validation failed with warnings in strict mode.',
27✔
31
            ResultType::ERROR === $resultType => 'Language validation failed with errors.',
22✔
32
            ResultType::WARNING === $resultType => 'Language validation completed with warnings.',
9✔
33
            default => 'Language validation failed.',
33✔
34
        };
35
    }
36

37
    /**
38
     * @return array<string, array<string, mixed>>
39
     */
40
    protected function groupIssuesByFile(ValidationResult $validationResult): array
40✔
41
    {
42
        $validatorPairs = $validationResult->getValidatorFileSetPairs();
40✔
43

44
        if (empty($validatorPairs)) {
40✔
45
            return [];
23✔
46
        }
47

48
        $groupedByFile = [];
17✔
49

50
        foreach ($validatorPairs as $pair) {
17✔
51
            $validator = $pair['validator'];
17✔
52
            $fileSet = $pair['fileSet'];
17✔
53

54
            if (!$validator->hasIssues()) {
17✔
NEW
55
                continue;
×
56
            }
57

58
            $distributedIssues = $validator->distributeIssuesForDisplay($fileSet);
17✔
59

60
            foreach ($distributedIssues as $filePath => $issues) {
17✔
61
                $normalizedPath = $this->normalizePath($filePath);
14✔
62

63
                if (!isset($groupedByFile[$normalizedPath])) {
14✔
64
                    $groupedByFile[$normalizedPath] = [];
14✔
65
                }
66

67
                $validatorName = $validator->getShortName();
14✔
68
                if (!isset($groupedByFile[$normalizedPath][$validatorName])) {
14✔
69
                    $groupedByFile[$normalizedPath][$validatorName] = [
14✔
70
                        'validator' => $validator,
14✔
71
                        'type' => $validator->resultTypeOnValidationFailure()->toString(),
14✔
72
                        'issues' => [],
14✔
73
                    ];
14✔
74
                }
75

76
                foreach ($issues as $issue) {
14✔
77
                    $groupedByFile[$normalizedPath][$validatorName]['issues'][] = $issue;
14✔
78
                }
79
            }
80
        }
81

82
        return $groupedByFile;
17✔
83
    }
84

85
    protected function normalizePath(string $path): string
16✔
86
    {
87
        $realPath = realpath($path);
16✔
88
        if (false === $realPath) {
16✔
89
            $normalizedPath = rtrim($path, DIRECTORY_SEPARATOR);
15✔
90
            if (str_starts_with($normalizedPath, './')) {
15✔
91
                $normalizedPath = substr($normalizedPath, 2);
1✔
92
            }
93

94
            return $normalizedPath;
15✔
95
        }
96

97
        $cwd = realpath(getcwd()).DIRECTORY_SEPARATOR;
1✔
98
        $normalizedPath = rtrim($realPath, DIRECTORY_SEPARATOR);
1✔
99

100
        if (str_starts_with($normalizedPath.DIRECTORY_SEPARATOR, $cwd)) {
1✔
101
            return substr($normalizedPath, strlen($cwd));
1✔
102
        }
103

NEW
104
        return $normalizedPath;
×
105
    }
106

107
    /**
108
     * @return array<string, mixed>
109
     */
110
    protected function formatStatisticsForOutput(ValidationResult $validationResult): array
22✔
111
    {
112
        $statistics = $validationResult->getStatistics();
22✔
113
        if (null === $statistics) {
22✔
114
            return [];
16✔
115
        }
116

117
        return [
6✔
118
            'execution_time' => $statistics->getExecutionTime(),
6✔
119
            'execution_time_formatted' => $statistics->getExecutionTimeFormatted(),
6✔
120
            'files_checked' => $statistics->getFilesChecked(),
6✔
121
            'keys_checked' => $statistics->getKeysChecked(),
6✔
122
            'validators_run' => $statistics->getValidatorsRun(),
6✔
123
            'parsers_cached' => $statistics->getParsersCached(),
6✔
124
        ];
6✔
125
    }
126

127
    protected function calculateExitCode(ValidationResult $validationResult): int
45✔
128
    {
129
        return $validationResult->getOverallResult()->resolveErrorToCommandExitCode($this->dryRun, $this->strict);
45✔
130
    }
131
}
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