YamlRepository::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace hanneskod\readmetester\Config;
6
7
use Symfony\Component\Yaml\Yaml;
8
use Symfony\Component\Yaml\Exception\ParseException;
9
10
final class YamlRepository implements RepositoryInterface
11
{
12
    private string $filename;
13
14
    public function __construct(string $filename)
15
    {
16
        $this->filename = $filename;
17
    }
18
19
    public function getConfigs(): array
20
    {
21
        if (!is_file($this->filename) || !is_readable($this->filename)) {
22
            throw new \RuntimeException("Unable to read configs from {$this->filename}");
23
        }
24
25
        try {
26
            return Yaml::parseFile($this->filename);
0 ignored issues
show
Bug Best Practice introduced by
The expression return Symfony\Component...seFile($this->filename) also could return the type Symfony\Component\Yaml\Tag\TaggedValue|null|string which is incompatible with the return type mandated by hanneskod\readmetester\C...Interface::getConfigs() of array<string,mixed>.
Loading history...
27
        } catch (ParseException $exception) {
28
            throw new \RuntimeException("Unable to parse '{$this->filename}': {$exception->getMessage()}");
29
        }
30
    }
31
32
    public function getRepositoryName(): string
33
    {
34
        return $this->filename;
35
    }
36
}
37