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

move-elevator / composer-translation-validator / 16589228037

29 Jul 2025 07:11AM UTC coverage: 96.6% (-0.009%) from 96.609%
16589228037

Pull #59

github

jackd248
refactor: update validation test assertions and enhance property visibility in validation summary
Pull Request #59: refactor: domain architecture

121 of 125 new or added lines in 10 files covered. (96.8%)

8 existing lines in 4 files now uncovered.

2358 of 2441 relevant lines covered (96.6%)

8.14 hits per line

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

90.32
/src/Config/ConfigReader.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\Config;
25

26
use JsonException;
27

28
class ConfigReader
29
{
30
    private const AUTO_DETECTION_FILES = [
31
        'translation-validator.php',
32
        'translation-validator.json',
33
        'translation-validator.yaml',
34
        'translation-validator.yml',
35
    ];
36

37
    public function __construct(private readonly ConfigFileReader $fileReader = new ConfigFileReader()) {}
31✔
38

39
    /**
40
     * @throws JsonException
41
     */
42
    public function read(string $configPath): TranslationValidatorConfig
26✔
43
    {
44
        return $this->fileReader->readAsConfig($configPath);
26✔
45
    }
46

47
    public function autoDetect(?string $workingDirectory = null): ?TranslationValidatorConfig
5✔
48
    {
49
        $workingDirectory ??= getcwd();
5✔
50

51
        if (!$workingDirectory) {
5✔
UNCOV
52
            return null;
×
53
        }
54

55
        foreach (self::AUTO_DETECTION_FILES as $filename) {
5✔
56
            $configPath = $workingDirectory.DIRECTORY_SEPARATOR.$filename;
5✔
57
            if (file_exists($configPath)) {
5✔
58
                return $this->read($configPath);
3✔
59
            }
60
        }
61

62
        return null;
2✔
63
    }
64

65
    /**
66
     * @throws JsonException
67
     */
68
    public function readFromComposerJson(string $composerJsonPath): ?TranslationValidatorConfig
6✔
69
    {
70
        if (!file_exists($composerJsonPath)) {
6✔
71
            return null;
1✔
72
        }
73

74
        $content = file_get_contents($composerJsonPath);
5✔
75
        if (false === $content) {
5✔
UNCOV
76
            return null;
×
77
        }
78

79
        $composerData = json_decode($content, true, 512, JSON_THROW_ON_ERROR);
5✔
80
        if (!is_array($composerData)) {
4✔
UNCOV
81
            return null;
×
82
        }
83

84
        $configFilePath = $composerData['extra']['translation-validator']['config-file'] ?? null;
4✔
85
        if (!$configFilePath) {
4✔
86
            return null;
1✔
87
        }
88

89
        $composerDir = dirname($composerJsonPath);
3✔
90
        $absoluteConfigPath = $this->resolveConfigPath($configFilePath, $composerDir);
3✔
91

92
        return $this->read($absoluteConfigPath);
3✔
93
    }
94

95
    private function resolveConfigPath(string $configPath, string $basePath): string
3✔
96
    {
97
        if (str_starts_with($configPath, '/') || preg_match('/^[a-zA-Z]:[\\/]/', $configPath)) {
3✔
98
            return $configPath;
1✔
99
        }
100

101
        return $basePath.DIRECTORY_SEPARATOR.$configPath;
2✔
102
    }
103
}
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