Completed
Push — feature/controller ( 90cc1a...dc82aa )
by René
04:15
created

Configuration   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 6
c 3
b 0
f 0
lcom 1
cbo 1
dl 0
loc 61
ccs 0
cts 13
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A set() 0 4 1
A exists() 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
     * Check if configuration exists
46
     *
47
     * @param string $key Configuration name
48
     *
49
     * @return bool TRUE if configuration exists, otherwise FALSE
50
     */
51
    public function exists(string $key)
52
    {
53
        return isset($this->configurations[$key]);
54
    }
55
56
    /**
57
     * Get configuration
58
     *
59
     * @param string $key Configuration name
60
     *
61
     * @return mixed Configuration value
62
     *
63
     * @throws ConfigurationNonexistentException If configuration has not been set
64
     */
65
    public function get(string $key)
66
    {
67
        if (isset($this->configurations[$key]) === false) {
68
            throw new ConfigurationNonexistentException([$key]);
69
        }
70
71
        return $this->configurations[$key];
72
    }
73
}
74