Config   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 5
dl 0
loc 41
ccs 0
cts 27
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setParam() 0 4 1
B readTrumpetFile() 0 30 6
1
<?php declare(strict_types=1);
2
3
namespace Bigwhoop\Trumpet\Config;
4
5
use Bigwhoop\Trumpet\Config\Params\Param;
6
use Bigwhoop\Trumpet\Exceptions\InvalidArgumentException;
7
use Symfony\Component\Yaml\Yaml;
8
9
final class Config
10
{
11
    /** @var Param[] */
12
    private $params = [];
13
14
    public function setParam(string $name, Param $param)
15
    {
16
        $this->params[$name] = $param;
17
    }
18
    
19
    public function readTrumpetFile(string $path): Presentation
20
    {
21
        if (!is_readable($path)) {
22
            throw new InvalidArgumentException("Trumpet file '$path' must exist and be readable.");
23
        }
24
25
        $yaml = file_get_contents($path);
26
27
        try {
28
            $data = Yaml::parse($yaml, true, true);
29
        } catch (\Throwable $t) {
0 ignored issues
show
Bug introduced by
The class Throwable does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
30
            throw new ConfigException($t->getMessage(), 0, $t);
31
        }
32
33
        if (!is_array($data)) {
34
            throw new ConfigException("Trumpet file '$path' is invalid. It probably is empty.");
35
        }
36
37
        $presentation = new Presentation();
38
39
        foreach ($data as $key => $value) {
40
            if (!array_key_exists($key, $this->params)) {
41
                throw new ConfigException("Trumpet file contains a key '$key' which is not supported.");
42
            }
43
44
            $this->params[$key]->parse($value, $presentation);
45
        }
46
47
        return $presentation;
48
    }
49
}
50