ConfigDirectory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Northwoods\Config;
5
6
use Northwoods\Config\Loader\LoaderInterface;
7
8
class ConfigDirectory implements ConfigInterface
9
{
10
    /** @var string */
11
    private $path;
12
13
    /** @var LoaderInterface */
14
    private $loader;
15
16
    /** @var array */
17
    private $config = [];
18
19 3
    public function __construct($path, LoaderInterface $loader)
20
    {
21 3
        $this->path = $path;
22 3
        $this->loader = $loader;
23 3
    }
24
25 3
    public function get(string $dotPath, $default = null)
26
    {
27 3
        list($name) = explode('.', $dotPath, 2);
28
29 3
        if (!isset($this->config[$name])) {
30 3
            $this->config[$name] = $this->loader->load("{$this->path}/$name");
31
        }
32
33 3
        return array_path($this->config, $dotPath, $default);
34
    }
35
36 3
    public function set(string $dotPath, $value)
37
    {
38 3
        $this->config = array_path_set($this->config, $dotPath, $value);
39 3
    }
40
}
41