Completed
Pull Request — master (#12)
by
unknown
04:11
created

MergedConfigCollection::get()   B

Complexity

Conditions 6
Paths 8

Size

Total Lines 23
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 6
eloc 11
nc 8
nop 2
dl 0
loc 23
ccs 10
cts 10
cp 1
crap 6
rs 8.5906
c 1
b 0
f 1
1
<?php
2
3
namespace Northwoods\Config;
4
5
class MergedConfigCollection extends ConfigCollection
6
{
7
    /**
8
     * @param string $dotPath
9
     * @param string $default
10
     *
11
     * @return mixed|null
12
     */
13 1
    public function get($dotPath, $default = null)
14
    {
15 1
        $found = null;
16
17 1
        foreach (array_reverse($this->configs) as $config) {
18
19
            /** @var ConfigInterface $config */
20
21 1
            $value = $config->get($dotPath, null);
22
23 1
            if ($value === null) {
24 1
                continue;
25
            }
26
27 1
            if (is_array($found) && is_array($value)) {
28 1
                $found = array_replace_recursive($found, $value);
29
            } else {
30 1
                $found = $value;
31
            }
32
        }
33
34 1
        return $found !== null ? $found : $default;
35
    }
36
}
37