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

Configuration   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 49
ccs 0
cts 11
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A set() 0 4 1
A get() 0 8 2
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