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

move-elevator / composer-translation-validator / 16003193252

01 Jul 2025 03:09PM UTC coverage: 90.062% (-2.5%) from 92.521%
16003193252

Pull #13

github

web-flow
Merge 47aec355a into abafa7911
Pull Request #13: feat: introduce ResultType enum for improved validation result handling

13 of 26 new or added lines in 3 files covered. (50.0%)

12 existing lines in 1 file now uncovered.

435 of 483 relevant lines covered (90.06%)

2.78 hits per line

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

67.57
/src/Validator/AbstractValidator.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace MoveElevator\ComposerTranslationValidator\Validator;
6

7
use MoveElevator\ComposerTranslationValidator\Parser\ParserInterface;
8
use MoveElevator\ComposerTranslationValidator\Parser\ParserRegistry;
9
use Psr\Log\LoggerInterface;
10

11
abstract class AbstractValidator
12
{
13
    /** @var array<string, array<mixed>> */
14
    protected array $issues = [];
15

16
    public function __construct(protected ?LoggerInterface $logger = null)
23✔
17
    {
18
    }
23✔
19

20
    /**
21
     * @param string[]                           $files
22
     * @param class-string<ParserInterface>|null $parserClass
23
     *
24
     * @return array<string, array<mixed>>
25
     *
26
     * @throws \ReflectionException
27
     */
28
    public function validate(array $files, ?string $parserClass): array
3✔
29
    {
30
        $classPart = strrchr(static::class, '\\');
3✔
31
        $name = false !== $classPart ? substr($classPart, 1) : static::class;
3✔
32
        $this->logger->debug(
3✔
33
            sprintf(
3✔
34
                '> Checking for <options=bold,underscore>%s</> ...',
3✔
35
                $name
3✔
36
            )
3✔
37
        );
3✔
38

39
        foreach ($files as $filePath) {
3✔
40
            $file = new ($parserClass ?: ParserRegistry::resolveParserClass($filePath))($filePath);
3✔
41
            /* @var ParserInterface $file */
42

43
            if (!in_array($file::class, $this->supportsParser(), true)) {
3✔
44
                $this->logger?->debug(
×
45
                    sprintf(
×
46
                        'The file <fg=cyan>%s</> is not supported by the validator <fg=red>%s</>.',
×
47
                        $file->getFileName(),
×
48
                        static::class
×
49
                    )
×
50
                );
×
51
                continue;
×
52
            }
53

54
            $this->logger->debug('> Checking language file: <fg=gray>'.$file->getFileDirectory().'</><fg=cyan>'.$file->getFileName().'</> ...');
3✔
55

56
            $validationResult = $this->processFile($file);
3✔
57
            if (!empty($validationResult)) {
3✔
58
                $this->issues[] = [
1✔
59
                    'file' => $file->getFileName(),
1✔
60
                    'issues' => $validationResult,
1✔
61
                    'parser' => $file::class,
1✔
62
                    'type' => $name,
1✔
63
                ];
1✔
64
            }
65
        }
66

67
        $this->postProcess();
3✔
68

69
        return $this->issues;
3✔
70
    }
71

72
    /**
73
     * @return array<mixed>
74
     */
75
    abstract protected function processFile(ParserInterface $file): array;
76

77
    /**
78
     * @return class-string<ParserInterface>[]
79
     */
80
    abstract public function supportsParser(): array;
81

82
    public function postProcess(): void
×
83
    {
84
        // This method can be overridden by subclasses to perform additional processing after validation.
85
    }
×
86

NEW
87
    public function resultTypeOnValidationFailure(): ResultType
×
88
    {
NEW
89
        return ResultType::ERROR;
×
90
    }
91
}
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