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

move-elevator / composer-translation-validator / 16268282793

14 Jul 2025 01:32PM UTC coverage: 95.769% (-0.4%) from 96.161%
16268282793

Pull #35

github

jackd248
refactor: enhance test assertions and improve variable type hints
Pull Request #35: build: update phpstan level to 7

30 of 38 new or added lines in 9 files covered. (78.95%)

2 existing lines in 1 file now uncovered.

1675 of 1749 relevant lines covered (95.77%)

7.55 hits per line

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

90.63
/src/Config/ConfigReader.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace MoveElevator\ComposerTranslationValidator\Config;
6

7
class ConfigReader
8
{
9
    private const AUTO_DETECTION_FILES = [
10
        'translation-validator.php',
11
        'translation-validator.json',
12
        'translation-validator.yaml',
13
        'translation-validator.yml',
14
    ];
15

16
    public function __construct(
31✔
17
        private readonly ConfigFileReader $fileReader = new ConfigFileReader(),
18
    ) {
19
    }
31✔
20

21
    /**
22
     * @throws \JsonException
23
     */
24
    public function read(string $configPath): TranslationValidatorConfig
26✔
25
    {
26
        return $this->fileReader->readAsConfig($configPath);
26✔
27
    }
28

29
    public function autoDetect(?string $workingDirectory = null): ?TranslationValidatorConfig
5✔
30
    {
31
        $workingDirectory ??= getcwd();
5✔
32

33
        if (!$workingDirectory) {
5✔
34
            return null;
×
35
        }
36

37
        foreach (self::AUTO_DETECTION_FILES as $filename) {
5✔
38
            $configPath = $workingDirectory.DIRECTORY_SEPARATOR.$filename;
5✔
39
            if (file_exists($configPath)) {
5✔
40
                return $this->read($configPath);
3✔
41
            }
42
        }
43

44
        return null;
2✔
45
    }
46

47
    /**
48
     * @throws \JsonException
49
     */
50
    public function readFromComposerJson(string $composerJsonPath): ?TranslationValidatorConfig
6✔
51
    {
52
        if (!file_exists($composerJsonPath)) {
6✔
53
            return null;
1✔
54
        }
55

56
        $content = file_get_contents($composerJsonPath);
5✔
57
        if (false === $content) {
5✔
NEW
58
            return null;
×
59
        }
60

61
        $composerData = json_decode($content, true, 512, JSON_THROW_ON_ERROR);
5✔
62
        if (!is_array($composerData)) {
4✔
63
            return null;
×
64
        }
65

66
        $configFilePath = $composerData['extra']['translation-validator']['config-file'] ?? null;
4✔
67
        if (!$configFilePath) {
4✔
68
            return null;
1✔
69
        }
70

71
        $composerDir = dirname($composerJsonPath);
3✔
72
        $absoluteConfigPath = $this->resolveConfigPath($configFilePath, $composerDir);
3✔
73

74
        return $this->read($absoluteConfigPath);
3✔
75
    }
76

77
    private function resolveConfigPath(string $configPath, string $basePath): string
3✔
78
    {
79
        if (str_starts_with($configPath, '/') || preg_match('/^[a-zA-Z]:[\\/]/', $configPath)) {
3✔
80
            return $configPath;
1✔
81
        }
82

83
        return $basePath.DIRECTORY_SEPARATOR.$configPath;
2✔
84
    }
85
}
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