Completed
Push — master ( ad5456...f93915 )
by Amine
10s
created

Config   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B get() 0 13 5
1
<?php namespace Tarsana\Command\Config;
2
3
use Tarsana\Command\Interfaces\Config\ConfigInterface;
4
5
/**
6
 * Stores and gets configuration.
7
 */
8
class Config implements ConfigInterface {
9
    /**
10
     * The raw configuration data.
11
     *
12
     * @var array
13
     */
14
    protected $data;
15
16
    public function __construct(array $data) {
17
        $this->data = $data;
18
    }
19
20
    /**
21
     * Gets a configuration value by path.
22
     */
23
    public function get(string $path = null)
24
    {
25
        if (null === $path)
26
            return $this->data;
27
        $keys = explode('.', $path);
28
        $value = $this->data;
29
        foreach ($keys as $key) {
30
            if (!is_array($value) || !array_key_exists($key, $value))
31
                throw new \Exception("Unable to find a configuration value with path '{$path}'");
32
            $value = $value[$key];
33
        }
34
        return $value;
35
    }
36
}
37