Passed
Push — master ( 83b89e...48455b )
by Hannes
02:13
created

ArraySettings::getSetting()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
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 ArraySettings implements SettingsInterface
10
{
11
    /**
12
     * @var array
13
     */
14
    private $settings;
15
16
    public function __construct(array $settings)
17
    {
18
        $this->settings = array_change_key_case($settings, CASE_UPPER);
19
    }
20
21
    public function getSetting(string $name)
22
    {
23
        if (!$this->hasSetting($name)) {
24
            throw new UnknownSettingException("Unknown setting '$name'");
25
        }
26
27
        return $this->settings[strtoupper($name)];
28
    }
29
30
    public function hasSetting(string $name): bool
31
    {
32
        return isset($this->settings[strtoupper($name)]);
33
    }
34
}
35