Completed
Push — feature/controller ( c4fe94...cdd7be )
by René
03:29
created

Configuration::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
crap 6
1
<?php
2
declare(strict_types = 1);
3
4
namespace Zortje\MVC\Configuration;
5
6
use Zortje\MVC\Configuration\Exception\ConfigurationNonexistentException;
7
8
/**
9
 * Class Configuration
10
 *
11
 * @package Zortje\MVC\Configuration
12
 */
13
class Configuration
14
{
15
16
    /**
17
     * @var array Internal configurations
18
     */
19
    protected $configurations = [];
20
21
    /**
22
     * Configuration constructor.
23
     *
24
     * @param array $config
25
     */
26
    public function __construct(array $config)
27
    {
28
        foreach ($config as $key => $value) {
29
            $this->set($key, $value);
30
        }
31
    }
32
33
    /**
34
     * Set configuration
35
     *
36
     * @param string $key   Configuration name
37
     * @param mixed  $value Configuration value
38
     */
39
    public function set(string $key, $value)
40
    {
41
        $this->configurations[$key] = $value;
42
    }
43
44
    /**
45
     * Get configuration
46
     *
47
     * @param string $key Configuration name
48
     *
49
     * @return mixed Configuration value
50
     *
51
     * @throws ConfigurationNonexistentException If configuration has not been set
52
     */
53
    public function get(string $key)
54
    {
55
        if (isset($this->configurations[$key]) === false) {
56
            throw new ConfigurationNonexistentException([$key]);
57
        }
58
59
        return $this->configurations[$key];
60
    }
61
}
62