Completed
Pull Request — master (#8)
by Woody
01:56
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 ConfigFactory
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;
0 ignored issues
show
Documentation Bug introduced by
It seems like $loader of type object<Northwoods\Config\Loader\LoaderInterface> is incompatible with the declared type object<Northwoods\Config\ConfigFactory> of property $loader.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
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");
0 ignored issues
show
Bug introduced by
The method load() does not seem to exist on object<Northwoods\Config\ConfigFactory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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