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

move-elevator / composer-translation-validator / 16273482336

14 Jul 2025 05:23PM UTC coverage: 95.945% (-0.2%) from 96.161%
16273482336

Pull #35

github

web-flow
Merge 337d2716f into d26b001b4
Pull Request #35: build: update phpstan level to 7

33 of 41 new or added lines in 10 files covered. (80.49%)

1680 of 1751 relevant lines covered (95.95%)

7.57 hits per line

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

95.71
/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
        $normalizedPath = rtrim($realPath, DIRECTORY_SEPARATOR);
1✔
98

99
        $cwd = getcwd();
1✔
100
        if (false === $cwd) {
1✔
NEW
101
            return $normalizedPath;
×
102
        }
103
        $realCwd = realpath($cwd);
1✔
104
        if (false === $realCwd) {
1✔
NEW
105
            return $normalizedPath;
×
106
        }
107
        $cwd = $realCwd.DIRECTORY_SEPARATOR;
1✔
108

109
        if (str_starts_with($normalizedPath.DIRECTORY_SEPARATOR, $cwd)) {
1✔
110
            return substr($normalizedPath, strlen($cwd));
1✔
111
        }
112

113
        return $normalizedPath;
×
114
    }
115

116
    /**
117
     * @return array<string, mixed>
118
     */
119
    protected function formatStatisticsForOutput(ValidationResult $validationResult): array
29✔
120
    {
121
        $statistics = $validationResult->getStatistics();
29✔
122
        if (null === $statistics) {
29✔
123
            return [];
23✔
124
        }
125

126
        return [
6✔
127
            'execution_time' => $statistics->getExecutionTime(),
6✔
128
            'execution_time_formatted' => $statistics->getExecutionTimeFormatted(),
6✔
129
            'files_checked' => $statistics->getFilesChecked(),
6✔
130
            'keys_checked' => $statistics->getKeysChecked(),
6✔
131
            'validators_run' => $statistics->getValidatorsRun(),
6✔
132
            'parsers_cached' => $statistics->getParsersCached(),
6✔
133
        ];
6✔
134
    }
135

136
    protected function calculateExitCode(ValidationResult $validationResult): int
54✔
137
    {
138
        return $validationResult->getOverallResult()
54✔
139
            ->resolveErrorToCommandExitCode($this->dryRun, $this->strict);
54✔
140
    }
141
}
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