• 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

98.21
/src/Result/ValidationRun.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace MoveElevator\ComposerTranslationValidator\Result;
6

7
use MoveElevator\ComposerTranslationValidator\FileDetector\FileSet;
8
use MoveElevator\ComposerTranslationValidator\Parser\ParserCache;
9
use MoveElevator\ComposerTranslationValidator\Validator\ResultType;
10
use MoveElevator\ComposerTranslationValidator\Validator\ValidatorInterface;
11
use Psr\Log\LoggerInterface;
12

13
class ValidationRun
14
{
15
    public function __construct(
11✔
16
        private readonly LoggerInterface $logger,
17
    ) {
18
    }
11✔
19

20
    /**
21
     * @param array<FileSet>                          $fileSets
22
     * @param array<class-string<ValidatorInterface>> $validatorClasses
23
     */
24
    public function executeFor(array $fileSets, array $validatorClasses): ValidationResult
11✔
25
    {
26
        $startTime = microtime(true);
11✔
27
        $validatorInstances = [];
11✔
28
        $validatorFileSetPairs = [];
11✔
29
        $overallResult = ResultType::SUCCESS;
11✔
30
        $filesChecked = 0;
11✔
31

32
        foreach ($fileSets as $fileSet) {
11✔
33
            $filesChecked += count($fileSet->getFiles());
8✔
34
            foreach ($validatorClasses as $validatorClass) {
8✔
35
                $validatorInstance = new $validatorClass($this->logger);
7✔
36
                /** @var class-string<\MoveElevator\ComposerTranslationValidator\Parser\ParserInterface> $parserClass */
37
                $parserClass = $fileSet->getParser();
7✔
38
                $result = $validatorInstance->validate($fileSet->getFiles(), $parserClass);
7✔
39
                if (!empty($result)) {
7✔
40
                    $overallResult = $overallResult->max($validatorInstance->resultTypeOnValidationFailure());
6✔
41
                    $validatorInstances[] = $validatorInstance;
6✔
42
                    $validatorFileSetPairs[] = [
6✔
43
                        'validator' => $validatorInstance,
6✔
44
                        'fileSet' => $fileSet,
6✔
45
                    ];
6✔
46
                }
47
            }
48
        }
49

50
        $keysChecked = $this->countKeysChecked($fileSets);
11✔
51

52
        $validatorsRun = count($validatorClasses);
11✔
53

54
        // Get cache statistics before clearing cache
55
        $cacheStats = ParserCache::getCacheStats();
11✔
56
        $parsersCached = $cacheStats['cached_parsers'];
11✔
57

58
        $executionTime = microtime(true) - $startTime;
11✔
59
        $statistics = new ValidationStatistics(
11✔
60
            $executionTime,
11✔
61
            $filesChecked,
11✔
62
            $keysChecked,
11✔
63
            $validatorsRun,
11✔
64
            $parsersCached
11✔
65
        );
11✔
66

67
        $validationResult = new ValidationResult($validatorInstances, $overallResult, $validatorFileSetPairs, $statistics);
11✔
68
        ParserCache::clear();
11✔
69

70
        return $validationResult;
11✔
71
    }
72

73
    /**
74
     * @param array<string, array<string, array<string, array<string>>>> $allFiles
75
     *
76
     * @return array<FileSet>
77
     */
78
    public static function createFileSetsFromArray(array $allFiles): array
4✔
79
    {
80
        $fileSets = [];
4✔
81

82
        foreach ($allFiles as $parser => $paths) {
4✔
83
            foreach ($paths as $path => $translationSets) {
3✔
84
                foreach ($translationSets as $setKey => $files) {
3✔
85
                    $fileSets[] = new FileSet($parser, $path, $setKey, $files);
3✔
86
                }
87
            }
88
        }
89

90
        return $fileSets;
4✔
91
    }
92

93
    /**
94
     * @param array<FileSet> $fileSets
95
     */
96
    private function countKeysChecked(array $fileSets): int
11✔
97
    {
98
        $keysChecked = 0;
11✔
99

100
        foreach ($fileSets as $fileSet) {
11✔
101
            $parserClass = $fileSet->getParser();
8✔
102

103
            foreach ($fileSet->getFiles() as $file) {
8✔
104
                try {
105
                    $parser = ParserCache::get($file, $parserClass);
8✔
106
                    if (false === $parser) {
4✔
NEW
107
                        continue;
×
108
                    }
109
                    $keys = $parser->extractKeys();
4✔
110
                    if (is_array($keys)) {
3✔
111
                        $keysChecked += count($keys);
3✔
112
                    }
113
                } catch (\Throwable) {
5✔
114
                    // Skip files that can't be parsed
115
                }
116
            }
117
        }
118

119
        return $keysChecked;
11✔
120
    }
121
}
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