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

move-elevator / composer-translation-validator / 16570845868

28 Jul 2025 01:48PM UTC coverage: 96.532% (-0.1%) from 96.658%
16570845868

push

github

web-flow
Merge pull request #55 from move-elevator/fix-prefix-file-detector

fix: enhance PrefixFileDetector to support common translation file patterns and update validation configuration

6 of 8 new or added lines in 1 file covered. (75.0%)

1 existing line in 1 file now uncovered.

2171 of 2249 relevant lines covered (96.53%)

8.43 hits per line

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

78.57
/src/FileDetector/PrefixFileDetector.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\FileDetector;
25

26
class PrefixFileDetector implements DetectorInterface
27
{
28
    /**
29
     * @param array<int, string> $files
30
     *
31
     * @return array<string, array<int, string>>
32
     */
33
    public function mapTranslationSet(array $files): array
5✔
34
    {
35
        $groups = [];
5✔
36

37
        foreach ($files as $file) {
5✔
38
            $basename = basename($file);
4✔
39
            if (preg_match('/^([a-z]{2}(?:[-_][A-Z]{2})?)\.(.+)$/i', $basename, $matches)) {
4✔
40
                // Language prefix pattern (e.g., de.messages.xlf -> key: messages.xlf)
41
                $key = $matches[2];
2✔
42
                $groups[$key][] = $file;
2✔
43
            } elseif (preg_match('/^(locallang|messages|validation|errors|labels|translations?|test)\./', $basename)) {
4✔
44
                // Common translation file patterns (e.g., messages.xlf -> key: messages.xlf)
45
                $key = $basename;
4✔
46
                $groups[$key][] = $file;
4✔
NEW
47
            } elseif (preg_match('/^[^.]+\.(xlf|xliff|json|ya?ml|php)$/i', $basename) && !preg_match('/(config|validator|setting)/', $basename)) {
×
48
                // Generic translation files, but exclude config/validator files
NEW
49
                $key = $basename;
×
UNCOV
50
                $groups[$key][] = $file;
×
51
            }
52
        }
53

54
        return $groups;
5✔
55
    }
56
}
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