Config   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 55
ccs 0
cts 29
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A all() 0 5 1
A get() 0 19 4
A has() 0 16 3
1
<?php
2
namespace Staticus\Config;
3
4
class Config implements ConfigInterface
5
{
6
    protected $config = [];
7
    public function __construct($config)
8
    {
9
        $this->config = $config;
10
    }
11
12
    public function all()
13
    {
14
15
        return $this->config;
16
    }
17
18
    public function get($route, $default = null)
19
    {
20
        $config = $this->config;
21
        $routes = explode('.', $route);
22
        $endPath = '';
23
        foreach ($routes as $item) {
24
            $endPath .= $item . '.';
25
            if (!array_key_exists($item, $config)) {
26
                if (null !== $default) {
27
28
                    return $default;
29
                }
30
                throw new \RuntimeException('Unknown config route and no default values: ' . $endPath);
31
            }
32
            $config = $config[$item];
33
        }
34
35
        return $config;
36
    }
37
38
    /**
39
     * @param $route
40
     * @return bool
41
     */
42
    public function has($route)
43
    {
44
        $config = $this->config;
45
        $routes = explode('.', $route);
46
        $endPath = '';
47
        foreach ($routes as $item) {
48
            $endPath .= $item . '.';
49
            if (!array_key_exists($item, $config)) {
50
51
                return false;
52
            }
53
            $config = $config[$item];
54
        }
55
56
        return true;
57
    }
58
}