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

move-elevator / composer-translation-validator / 16260669765

14 Jul 2025 07:25AM UTC coverage: 96.418% (+0.09%) from 96.329%
16260669765

push

github

web-flow
Merge pull request #32 from move-elevator/support-php

feat: add support for PHP translation files and update validators

73 of 74 new or added lines in 11 files covered. (98.65%)

1588 of 1647 relevant lines covered (96.42%)

7.53 hits per line

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

92.31
/src/FileDetector/DirectoryFileDetector.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace MoveElevator\ComposerTranslationValidator\FileDetector;
6

7
class DirectoryFileDetector implements DetectorInterface
8
{
9
    /**
10
     * Maps translation files organized by language directories.
11
     * Examples:
12
     * - lang/en/messages.php, lang/de/messages.php (Laravel style)
13
     * - resources/lang/en/auth.php, resources/lang/fr/auth.php (Laravel style)
14
     * - translations/en/messages.php, translations/de/messages.php (directory-based).
15
     *
16
     * @param array<int, string> $files
17
     *
18
     * @return array<string, array<int, string>>
19
     */
20
    public function mapTranslationSet(array $files): array
10✔
21
    {
22
        $groups = [];
10✔
23

24
        foreach ($files as $file) {
10✔
25
            $pathParts = explode('/', str_replace('\\', '/', $file));
9✔
26
            $fileName = array_pop($pathParts);
9✔
27
            $languageDir = array_pop($pathParts);
9✔
28

29
            if (!$fileName || !$languageDir) {
9✔
NEW
30
                continue;
×
31
            }
32

33
            // Check if this follows directory-based pattern: lang_code/filename.ext
34
            if (
35
                preg_match('/^[a-z]{2}(?:[-_][A-Z]{2})?$/', $languageDir)
9✔
36
                && preg_match('/^([^.]+)\.(php|json|ya?ml|xlf|xliff)$/i', $fileName, $matches)
9✔
37
            ) {
38
                $key = $matches[1];
8✔
39
                $groups[$key][] = $file;
8✔
40
            }
41
        }
42

43
        return $groups;
10✔
44
    }
45
}
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