Completed
Push — master ( 83b89e...48455b )
by Hannes
04:08 queued 02:15
created

ManagedSettings::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace inroutephp\inroute\Compiler\Settings;
6
7
use inroutephp\inroute\Compiler\Exception\UnknownSettingException;
8
9
final class ManagedSettings implements SettingsInterface
10
{
11
    /**
12
     * @var SettingsInterface[]
13
     */
14
    private $repos;
15
16
    public function __construct(SettingsInterface ...$settings)
17
    {
18
        $this->repos = $settings;
19
    }
20
21
    public function loadSettings(SettingsInterface $repo): void
22
    {
23
        array_unshift($this->repos, $repo);
24
    }
25
26
    public function getSetting(string $name)
27
    {
28
        foreach ($this->repos as $repo) {
29
            if ($repo->hasSetting($name)) {
30
                return $repo->getSetting($name);
31
            }
32
        }
33
34
        throw new UnknownSettingException("Unknown setting '$name'");
35
    }
36
37
    public function hasSetting(string $name): bool
38
    {
39
        foreach ($this->repos as $repo) {
40
            if ($repo->hasSetting($name)) {
41
                return true;
42
            }
43
        }
44
45
        return false;
46
    }
47
}
48