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

MergedConfigCollection   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 32
ccs 10
cts 10
cp 1
rs 10
c 1
b 0
f 1
wmc 6
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
B get() 0 23 6
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