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

move-elevator / composer-translation-validator / 16588667316

29 Jul 2025 06:40AM UTC coverage: 96.242% (-0.4%) from 96.609%
16588667316

Pull #59

github

jackd248
refactor: streamline constructor syntax and improve property visibility in configuration classes
Pull Request #59: refactor: domain architecture

119 of 132 new or added lines in 10 files covered. (90.15%)

3 existing lines in 1 file now uncovered.

2356 of 2448 relevant lines covered (96.24%)

8.19 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 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
    }
84✔
34

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

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

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

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

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

64
        $groupedByFile = [];
31✔
65

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

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

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

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

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

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

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

98
        return $groupedByFile;
31✔
99
    }
100

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

110
            return $normalizedPath;
26✔
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
36✔
136
    {
137
        $statistics = $validationResult->getStatistics();
36✔
138
        if (null === $statistics) {
36✔
139
            return [];
29✔
140
        }
141

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

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