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

move-elevator / composer-translation-validator / 18559927341

16 Oct 2025 11:35AM UTC coverage: 95.519%. Remained the same
18559927341

Pull #73

github

jackd248
build: add php-cs-fixer-preset
Pull Request #73: build: add php-cs-fixer-preset

206 of 210 new or added lines in 16 files covered. (98.1%)

91 existing lines in 20 files now uncovered.

2345 of 2455 relevant lines covered (95.52%)

7.73 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
/*
6
 * This file is part of the "composer-translation-validator" Composer plugin.
7
 *
8
 * (c) 2025 Konrad Michalik <km@move-elevator.de>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13

14
namespace MoveElevator\ComposerTranslationValidator\Result;
15

16
use MoveElevator\ComposerTranslationValidator\Validator\ResultType;
17
use Symfony\Component\Console\Output\OutputInterface;
18

19
use function strlen;
20

21
/**
22
 * AbstractValidationResultRenderer.
23
 *
24
 * @author Konrad Michalik <km@move-elevator.de>
25
 * @license GPL-3.0-or-later
26
 */
27
abstract class AbstractValidationResultRenderer implements ValidationResultRendererInterface
28
{
29
    public function __construct(
65✔
30
        protected readonly OutputInterface $output,
31
        protected readonly bool $dryRun = false,
32
        protected readonly bool $strict = false,
33
    ) {}
65✔
34

35
    protected function generateMessage(ValidationResult $validationResult): string
47✔
36
    {
37
        $resultType = $validationResult->getOverallResult();
47✔
38

39
        if (!$resultType->notFullySuccessful()) {
47✔
40
            return 'Language validation succeeded.';
14✔
41
        }
42

43
        return match (true) {
44
            $this->dryRun && ResultType::ERROR === $resultType => 'Language validation failed with errors in dry-run mode.',
33✔
45
            $this->dryRun && ResultType::WARNING === $resultType => 'Language validation completed with warnings in dry-run mode.',
28✔
46
            $this->strict && ResultType::WARNING === $resultType => 'Language validation failed with warnings in strict mode.',
27✔
47
            ResultType::ERROR === $resultType => 'Language validation failed with errors.',
22✔
48
            ResultType::WARNING === $resultType => 'Language validation completed with warnings.',
9✔
49
            default => 'Language validation failed.',
33✔
50
        };
51
    }
52

53
    /**
54
     * @return array<string, array<string, mixed>>
55
     */
56
    protected function groupIssuesByFile(ValidationResult $validationResult): array
41✔
57
    {
58
        $validatorPairs = $validationResult->getValidatorFileSetPairs();
41✔
59

60
        if (empty($validatorPairs)) {
41✔
61
            return [];
18✔
62
        }
63

64
        $groupedByFile = [];
23✔
65

66
        foreach ($validatorPairs as $pair) {
23✔
67
            $validator = $pair['validator'];
23✔
68
            $fileSet = $pair['fileSet'];
23✔
69

70
            if (!$validator->hasIssues()) {
23✔
71
                continue;
3✔
72
            }
73

74
            $distributedIssues = $validator->distributeIssuesForDisplay($fileSet);
20✔
75

76
            foreach ($distributedIssues as $filePath => $issues) {
20✔
77
                $normalizedPath = $this->normalizePath($filePath);
17✔
78

79
                if (!isset($groupedByFile[$normalizedPath])) {
17✔
80
                    $groupedByFile[$normalizedPath] = [];
17✔
81
                }
82

83
                $validatorName = $validator->getShortName();
17✔
84
                if (!isset($groupedByFile[$normalizedPath][$validatorName])) {
17✔
85
                    $groupedByFile[$normalizedPath][$validatorName] = [
17✔
86
                        'validator' => $validator,
17✔
87
                        'type' => $validator->resultTypeOnValidationFailure()->toString(),
17✔
88
                        'issues' => [],
17✔
89
                    ];
17✔
90
                }
91

92
                foreach ($issues as $issue) {
17✔
93
                    $groupedByFile[$normalizedPath][$validatorName]['issues'][] = $issue;
17✔
94
                }
95
            }
96
        }
97

98
        return $groupedByFile;
23✔
99
    }
100

101
    protected function normalizePath(string $path): string
19✔
102
    {
103
        $realPath = realpath($path);
19✔
104
        if (false === $realPath) {
19✔
105
            $normalizedPath = rtrim($path, \DIRECTORY_SEPARATOR);
18✔
106
            if (str_starts_with($normalizedPath, './')) {
18✔
107
                $normalizedPath = substr($normalizedPath, 2);
1✔
108
            }
109

110
            return $normalizedPath;
18✔
111
        }
112

113
        $normalizedPath = rtrim($realPath, \DIRECTORY_SEPARATOR);
1✔
114

115
        $cwd = getcwd();
1✔
116
        if (false === $cwd) {
1✔
UNCOV
117
            return $normalizedPath;
×
118
        }
119
        $realCwd = realpath($cwd);
1✔
120
        if (false === $realCwd) {
1✔
UNCOV
121
            return $normalizedPath;
×
122
        }
123
        $cwd = $realCwd.\DIRECTORY_SEPARATOR;
1✔
124

125
        if (str_starts_with($normalizedPath.\DIRECTORY_SEPARATOR, $cwd)) {
1✔
126
            return substr($normalizedPath, strlen($cwd));
1✔
127
        }
128

UNCOV
129
        return $normalizedPath;
×
130
    }
131

132
    /**
133
     * @return array<string, mixed>
134
     */
135
    protected function formatStatisticsForOutput(ValidationResult $validationResult): array
28✔
136
    {
137
        $statistics = $validationResult->getStatistics();
28✔
138
        if (null === $statistics) {
28✔
139
            return [];
23✔
140
        }
141

142
        return [
5✔
143
            'execution_time' => $statistics->getExecutionTime(),
5✔
144
            'execution_time_formatted' => $statistics->getExecutionTimeFormatted(),
5✔
145
            'files_checked' => $statistics->getFilesChecked(),
5✔
146
            'keys_checked' => $statistics->getKeysChecked(),
5✔
147
            'validators_run' => $statistics->getValidatorsRun(),
5✔
148
            'parsers_cached' => $statistics->getParsersCached(),
5✔
149
        ];
5✔
150
    }
151

152
    protected function calculateExitCode(ValidationResult $validationResult): int
46✔
153
    {
154
        return $validationResult->getOverallResult()
46✔
155
            ->resolveErrorToCommandExitCode($this->dryRun, $this->strict);
46✔
156
    }
157
}
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

© 2025 Coveralls, Inc