YamlRepository   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

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

3 Methods

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