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

move-elevator / composer-translation-validator / 16213114267

11 Jul 2025 06:09AM UTC coverage: 93.814% (-0.1%) from 93.963%
16213114267

push

github

web-flow
Merge pull request #25 from move-elevator/xliff-schema-1.0

fix: skip xliff schema 1.0 issue

1 of 4 new or added lines in 2 files covered. (25.0%)

1183 of 1261 relevant lines covered (93.81%)

6.37 hits per line

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

80.0
/src/Validator/XliffSchemaValidator.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\XliffParser;
9
use MoveElevator\ComposerTranslationValidator\Result\Issue;
10
use Symfony\Component\Config\Util\XmlUtils;
11
use Symfony\Component\Translation\Util\XliffUtils;
12

13
class XliffSchemaValidator extends AbstractValidator implements ValidatorInterface
14
{
15
    public function processFile(ParserInterface $file): array
3✔
16
    {
17
        try {
18
            /*
19
             * With XmlUtils::loadFile() we always get a strange symfony error related to global composer autoloading issue.
20
             *      Call to undefined method Symfony\Component\Filesystem\Filesystem::readFile()
21
             */
22
            if (!file_exists($file->getFilePath())) {
3✔
23
                $this->logger?->error('File does not exist: '.$file->getFileName());
1✔
24

25
                return [];
1✔
26
            }
27

28
            $fileContent = file_get_contents($file->getFilePath());
2✔
29
            if (false === $fileContent) {
2✔
30
                $this->logger?->error('Failed to read file: '.$file->getFileName());
×
31

32
                return [];
×
33
            }
34
            $dom = XmlUtils::parse($fileContent);
2✔
35
            $errors = XliffUtils::validateSchema($dom);
2✔
36
        } catch (\Exception $e) {
×
NEW
37
            if (str_contains($e->getMessage(), 'No support implemented for loading XLIFF version')) {
×
NEW
38
                $this->logger?->notice(sprintf('Skipping %s: %s', $this->getShortName(), $e->getMessage()));
×
39
            } else {
NEW
40
                $this->logger?->error('Failed to validate XML schema: '.$e->getMessage());
×
41
            }
42

43
            return [];
×
44
        }
45

46
        if (!empty($errors)) {
2✔
47
            return $errors;
1✔
48
        }
49

50
        return [];
1✔
51
    }
52

53
    public function formatIssueMessage(Issue $issue, string $prefix = ''): string
4✔
54
    {
55
        $details = $issue->getDetails();
4✔
56
        $messages = [];
4✔
57

58
        foreach ($details as $error) {
4✔
59
            if (is_array($error)) {
3✔
60
                $message = $error['message'] ?? 'Schema validation error';
3✔
61
                $line = isset($error['line']) ? " (Line: {$error['line']})" : '';
3✔
62
                $code = isset($error['code']) ? " (Code: {$error['code']})" : '';
3✔
63
                $level = $error['level'] ?? 'ERROR';
3✔
64

65
                $color = 'ERROR' === strtoupper($level) ? 'red' : 'yellow';
3✔
66
                $levelText = ucfirst(strtolower($level));
3✔
67

68
                $messages[] = "- <fg=$color>$levelText</> {$prefix}$message$line$code";
3✔
69
            }
70
        }
71

72
        if (empty($messages)) {
4✔
73
            $messages[] = "- <fg=red>Error</> {$prefix}Schema validation error";
1✔
74
        }
75

76
        return implode("\n", $messages);
4✔
77
    }
78

79
    /**
80
     * @return class-string<ParserInterface>[]
81
     */
82
    public function supportsParser(): array
1✔
83
    {
84
        return [XliffParser::class];
1✔
85
    }
86
}
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

© 2026 Coveralls, Inc