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

move-elevator / composer-translation-validator / 16589183308

29 Jul 2025 07:08AM UTC coverage: 96.6% (-0.009%) from 96.609%
16589183308

Pull #59

github

jackd248
refactor: improve variable naming for clarity in validation summary and update test assertion for null result
Pull Request #59: refactor: domain architecture

121 of 125 new or added lines in 10 files covered. (96.8%)

8 existing lines in 4 files now uncovered.

2358 of 2441 relevant lines covered (96.6%)

8.14 hits per line

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

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

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the Composer plugin "composer-translation-validator".
7
 *
8
 * Copyright (C) 2025 Konrad Michalik <km@move-elevator.de>
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation, either version 3 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22
 */
23

24
namespace MoveElevator\ComposerTranslationValidator\Result;
25

26
use MoveElevator\ComposerTranslationValidator\Validator\ResultType;
27
use Symfony\Component\Console\Output\OutputInterface;
28

29
abstract class AbstractValidationResultRenderer implements ValidationResultRendererInterface
30
{
31
    public function __construct(protected OutputInterface $output, protected bool $dryRun = false, protected bool $strict = false) {}
84✔
32

33
    protected function generateMessage(ValidationResult $validationResult): string
62✔
34
    {
35
        $resultType = $validationResult->getOverallResult();
62✔
36

37
        if (!$resultType->notFullySuccessful()) {
62✔
38
            return 'Language validation succeeded.';
18✔
39
        }
40

41
        return match (true) {
42
            $this->dryRun && ResultType::ERROR === $resultType => 'Language validation failed with errors in dry-run mode.',
44✔
43
            $this->dryRun && ResultType::WARNING === $resultType => 'Language validation completed with warnings in dry-run mode.',
38✔
44
            $this->strict && ResultType::WARNING === $resultType => 'Language validation failed with warnings in strict mode.',
37✔
45
            ResultType::ERROR === $resultType => 'Language validation failed with errors.',
31✔
46
            ResultType::WARNING === $resultType => 'Language validation completed with warnings.',
11✔
47
            default => 'Language validation failed.',
44✔
48
        };
49
    }
50

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

58
        if (empty($validatorPairs)) {
56✔
59
            return [];
25✔
60
        }
61

62
        $groupedByFile = [];
31✔
63

64
        foreach ($validatorPairs as $pair) {
31✔
65
            $validator = $pair['validator'];
31✔
66
            $fileSet = $pair['fileSet'];
31✔
67

68
            if (!$validator->hasIssues()) {
31✔
69
                continue;
3✔
70
            }
71

72
            $distributedIssues = $validator->distributeIssuesForDisplay($fileSet);
28✔
73

74
            foreach ($distributedIssues as $filePath => $issues) {
28✔
75
                $normalizedPath = $this->normalizePath($filePath);
25✔
76

77
                if (!isset($groupedByFile[$normalizedPath])) {
25✔
78
                    $groupedByFile[$normalizedPath] = [];
25✔
79
                }
80

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

90
                foreach ($issues as $issue) {
25✔
91
                    $groupedByFile[$normalizedPath][$validatorName]['issues'][] = $issue;
25✔
92
                }
93
            }
94
        }
95

96
        return $groupedByFile;
31✔
97
    }
98

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

108
            return $normalizedPath;
26✔
109
        }
110

111
        $normalizedPath = rtrim($realPath, DIRECTORY_SEPARATOR);
1✔
112

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

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

UNCOV
127
        return $normalizedPath;
×
128
    }
129

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

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

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