Completed
Push — master ( bf1c9e...8c1053 )
by Woody
13s
created

ConfigDirectory   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 39
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A get() 0 10 2
A set() 0 4 1
1
<?php
2
3
namespace Northwoods\Config;
4
5
use Northwoods\Config\Loader\LoaderInterface;
6
7
class ConfigDirectory implements ConfigInterface
8
{
9
    /**
10
     * @var string
11
     */
12
    private $path;
13
14
    /**
15
     * @var LoaderInterface
16
     */
17
    private $loader;
18
19
    /**
20
     * @var array
21
     */
22
    private $config = [];
23
24 3
    public function __construct($path, LoaderInterface $loader)
25
    {
26 3
        $this->path = $path;
27 3
        $this->loader = $loader;
28 3
    }
29
30 3
    public function get($dotPath, $default = null)
31
    {
32 3
        list($name) = explode('.', $dotPath, 2);
33
34 3
        if (!isset($this->config[$name])) {
35 3
            $this->config[$name] = $this->loader->load("{$this->path}/$name");
36 3
        }
37
38 3
        return array_path($this->config, $dotPath, $default);
39
    }
40
41 3
    public function set($dotPath, $value)
42
    {
43 3
        $this->config = array_path_set($this->config, $dotPath, $value);
44 3
    }
45
}
46