UserConfigRepository::__construct()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 4
nc 3
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace hanneskod\readmetester\Config;
6
7
use Symfony\Component\Yaml\Yaml;
8
9
final class UserConfigRepository implements RepositoryInterface
10
{
11
    public const CONFIG_FILENAME = 'readme-tester.yaml';
12
    public const DIST_CONFIG_FILENAME = 'readme-tester.yaml.dist';
13
14
    /** @var array<string, mixed> */
15
    private array $configs = [];
16
17
    private string $name = '';
18
19
    public function __construct()
20
    {
21
        foreach ([self::CONFIG_FILENAME, self::DIST_CONFIG_FILENAME] as $filename) {
22
            if (is_file($filename) && is_readable($filename)) {
23
                $this->configs = (array)Yaml::parseFile($filename);
24
                $this->name = $filename;
25
                break;
26
            }
27
        }
28
    }
29
30
    public function getConfigs(): array
31
    {
32
        return $this->configs;
33
    }
34
35
    public function getRepositoryName(): string
36
    {
37
        return $this->name;
38
    }
39
}
40