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

move-elevator / composer-translation-validator / 16390319464

19 Jul 2025 03:54PM UTC coverage: 96.554% (-0.009%) from 96.563%
16390319464

Pull #39

github

jackd248
feat: add file headers to all PHP files for licensing and attribution
Pull Request #39: feat: add file headers to all PHP files for licensing and attribution

108 of 118 new or added lines in 32 files covered. (91.53%)

1737 of 1799 relevant lines covered (96.55%)

8.05 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
/*
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\Validator;
25

26
use Exception;
27
use MoveElevator\ComposerTranslationValidator\Parser\ParserInterface;
28
use MoveElevator\ComposerTranslationValidator\Parser\XliffParser;
29
use MoveElevator\ComposerTranslationValidator\Result\Issue;
30
use Symfony\Component\Config\Util\XmlUtils;
31
use Symfony\Component\Translation\Util\XliffUtils;
32

33
class XliffSchemaValidator extends AbstractValidator implements ValidatorInterface
34
{
35
    public function processFile(ParserInterface $file): array
3✔
36
    {
37
        try {
38
            /*
39
             * With XmlUtils::loadFile() we always get a strange symfony error related to global composer autoloading issue.
40
             *      Call to undefined method Symfony\Component\Filesystem\Filesystem::readFile()
41
             */
42
            if (!file_exists($file->getFilePath())) {
3✔
43
                $this->logger?->error('File does not exist: '.$file->getFileName());
1✔
44

45
                return [];
1✔
46
            }
47

48
            $fileContent = file_get_contents($file->getFilePath());
2✔
49
            if (false === $fileContent) {
2✔
50
                $this->logger?->error('Failed to read file: '.$file->getFileName());
×
51

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

63
            return [];
×
64
        }
65

66
        if (!empty($errors)) {
2✔
67
            return $errors;
1✔
68
        }
69

70
        return [];
1✔
71
    }
72

73
    public function formatIssueMessage(Issue $issue, string $prefix = ''): string
4✔
74
    {
75
        $details = $issue->getDetails();
4✔
76
        $messages = [];
4✔
77

78
        foreach ($details as $error) {
4✔
79
            if (is_array($error)) {
3✔
80
                $message = $error['message'] ?? 'Schema validation error';
3✔
81
                $line = isset($error['line']) ? " (Line: {$error['line']})" : '';
3✔
82
                $code = isset($error['code']) ? " (Code: {$error['code']})" : '';
3✔
83
                $level = $error['level'] ?? 'ERROR';
3✔
84

85
                $color = 'ERROR' === strtoupper($level) ? 'red' : 'yellow';
3✔
86
                $levelText = ucfirst(strtolower($level));
3✔
87

88
                $messages[] = "- <fg=$color>$levelText</> {$prefix}$message$line$code";
3✔
89
            }
90
        }
91

92
        if (empty($messages)) {
4✔
93
            $messages[] = "- <fg=red>Error</> {$prefix}Schema validation error";
1✔
94
        }
95

96
        return implode("\n", $messages);
4✔
97
    }
98

99
    /**
100
     * @return class-string<ParserInterface>[]
101
     */
102
    public function supportsParser(): array
1✔
103
    {
104
        return [XliffParser::class];
1✔
105
    }
106
}
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