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

ArraySettings   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 24
rs 10
c 0
b 0
f 0
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
    /**
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