ArraySettings   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 23
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hasSetting() 0 3 1
A __construct() 0 3 1
A getSetting() 0 7 2
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