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

move-elevator / composer-translation-validator / 16214487995

11 Jul 2025 07:33AM UTC coverage: 95.347% (+1.5%) from 93.814%
16214487995

push

github

web-flow
Merge pull request #26 from move-elevator/code-improvement

feat: implement configuration factory and file reader for translation validator

216 of 221 new or added lines in 7 files covered. (97.74%)

1209 of 1268 relevant lines covered (95.35%)

7.97 hits per line

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

98.41
/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(
74✔
13
        protected readonly OutputInterface $output,
14
        protected readonly bool $dryRun = false,
15
        protected readonly bool $strict = false,
16
    ) {
17
    }
74✔
18

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

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

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

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

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

48
        $groupedByFile = [];
24✔
49

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

54
            if (!$validator->hasIssues()) {
24✔
55
                continue;
1✔
56
            }
57

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

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

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

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

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

82
        return $groupedByFile;
24✔
83
    }
84

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

94
            return $normalizedPath;
21✔
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
29✔
111
    {
112
        $statistics = $validationResult->getStatistics();
29✔
113
        if (null === $statistics) {
29✔
114
            return [];
23✔
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
54✔
128
    {
129
        return $validationResult->getOverallResult()->resolveErrorToCommandExitCode($this->dryRun, $this->strict);
54✔
130
    }
131
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc