ArraySettings::getSetting()   A
last analyzed

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
    /** @var array<string, mixed> */
12
    private $settings;
13
14
    /** @param array<string, mixed> $settings */
15
    public function __construct(array $settings)
16
    {
17
        $this->settings = array_change_key_case($settings, CASE_UPPER);
18
    }
19
20
    public function getSetting(string $name)
21
    {
22
        if (!$this->hasSetting($name)) {
23
            throw new UnknownSettingException("Unknown setting '$name'");
24
        }
25
26
        return $this->settings[strtoupper($name)];
27
    }
28
29
    public function hasSetting(string $name): bool
30
    {
31
        return isset($this->settings[strtoupper($name)]);
32
    }
33
}
34