UserConfigRepository   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 12
c 1
b 0
f 0
dl 0
loc 29
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 4
A getConfigs() 0 3 1
A getRepositoryName() 0 3 1
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