ConfigDirectory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

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
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