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

move-elevator / composer-translation-validator / 18560103885

16 Oct 2025 11:42AM UTC coverage: 95.519%. Remained the same
18560103885

Pull #73

github

jackd248
refactor: remove unnecessary type hint from MismatchValidator
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

93.55
/src/Validator/XliffSchemaValidator.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\Validator;
15

16
use Exception;
17
use MoveElevator\ComposerTranslationValidator\Parser\{ParserInterface, XliffParser};
18
use MoveElevator\ComposerTranslationValidator\Result\Issue;
19
use Symfony\Component\Config\Util\XmlUtils;
20
use Symfony\Component\Translation\Util\XliffUtils;
21

22
use function sprintf;
23

24
/**
25
 * XliffSchemaValidator.
26
 *
27
 * @author Konrad Michalik <km@move-elevator.de>
28
 * @license GPL-3.0-or-later
29
 */
30
class XliffSchemaValidator extends AbstractValidator implements ValidatorInterface
31
{
32
    public function processFile(ParserInterface $file): array
7✔
33
    {
34
        try {
35
            /*
36
             * With XmlUtils::loadFile() we always get a strange symfony error related to global composer autoloading issue.
37
             *      Call to undefined method Symfony\Component\Filesystem\Filesystem::readFile()
38
             */
39
            if (!file_exists($file->getFilePath())) {
7✔
40
                $this->logger?->error('File does not exist: '.$file->getFileName());
2✔
41

42
                return [];
2✔
43
            }
44

45
            $fileContent = file_get_contents($file->getFilePath());
5✔
46
            if (false === $fileContent) {
5✔
UNCOV
47
                $this->logger?->error('Failed to read file: '.$file->getFileName());
×
48

UNCOV
49
                return [];
×
50
            }
51
            $dom = XmlUtils::parse($fileContent);
5✔
52
            $errors = XliffUtils::validateSchema($dom);
4✔
53
        } catch (Exception $e) {
2✔
54
            if (str_contains($e->getMessage(), 'No support implemented for loading XLIFF version')) {
2✔
55
                $this->logger?->notice(sprintf('Skipping %s: %s', $this->getShortName(), $e->getMessage()));
1✔
56
            } else {
57
                $this->logger?->error('Failed to validate XML schema: '.$e->getMessage());
1✔
58
            }
59

60
            return [];
2✔
61
        }
62

63
        if (!empty($errors)) {
3✔
64
            return $errors;
1✔
65
        }
66

67
        return [];
2✔
68
    }
69

70
    public function formatIssueMessage(Issue $issue, string $prefix = ''): string
8✔
71
    {
72
        $details = $issue->getDetails();
8✔
73

74
        // Since AbstractValidator creates one Issue per error array,
75
        // $details is the individual error array, not an array of errors
76
        if (isset($details['message'])) {
8✔
77
            $message = $details['message'];
5✔
78
            $line = isset($details['line']) ? " (Line: {$details['line']})" : '';
5✔
79
            $code = isset($details['code']) ? " (Code: {$details['code']})" : '';
5✔
80
            $level = $details['level'] ?? 'ERROR';
5✔
81

82
            $color = 'ERROR' === strtoupper((string) $level) ? 'red' : 'yellow';
5✔
83
            $levelText = ucfirst(strtolower((string) $level));
5✔
84

85
            return "- <fg=$color>$levelText</> {$prefix}$message$line$code";
5✔
86
        }
87

88
        return "- <fg=red>Error</> {$prefix}Schema validation error";
3✔
89
    }
90

91
    /**
92
     * @return class-string<ParserInterface>[]
93
     */
94
    public function supportsParser(): array
3✔
95
    {
96
        return [XliffParser::class];
3✔
97
    }
98
}
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