Passed
Pull Request — master (#14)
by
unknown
08:37
created

ConfigDirectory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
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;
0 ignored issues
show
Coding Style introduced by
Private member variable "path" must contain a leading underscore
Loading history...
Coding Style introduced by
Expected 1 blank line before member var; 0 found
Loading history...
12
13
    /** @var LoaderInterface */
14
    private $loader;
0 ignored issues
show
Coding Style introduced by
Private member variable "loader" must contain a leading underscore
Loading history...
15
16
    /** @var array */
17
    private $config = [];
0 ignored issues
show
Coding Style introduced by
Private member variable "config" must contain a leading underscore
Loading history...
18
19
    public function __construct($path, LoaderInterface $loader)
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
20
    {
21
        $this->path = $path;
22
        $this->loader = $loader;
23
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
24
25
    public function get(string $dotPath, $default = null)
26
    {
27
        list($name) = explode('.', $dotPath, 2);
28
29
        if (!isset($this->config[$name])) {
0 ignored issues
show
Coding Style introduced by
There must be a single space after a NOT operator; 0 found
Loading history...
30
            $this->config[$name] = $this->loader->load("{$this->path}/$name");
31
        }
32
33
        return array_path($this->config, $dotPath, $default);
34
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
35
36
    public function set(string $dotPath, $value, $hard = false)
37
    {
38
        $this->config = array_path_set($this->config, $dotPath, $value);
39
40
        if ($hard === true) {
41
            list($name) = explode('.', $dotPath, 2);
42
            $this->loader->unload("{$this->path}/$name", $this->config);
43
        }
44
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
45
}
46