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

ConfigDirectory::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 10
ccs 6
cts 6
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
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