ConfigMerge   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 4 1
A getWithMerge() 0 13 3
1
<?php
2
namespace Consolidation\Config\Util;
3
4
/**
5
 * Works like 'getWithFallback', but merges results from all applicable
6
 * groups. Settings from most specific group take precedence.
7
 */
8
class ConfigMerge extends ConfigGroup
9
{
10
    /**
11
     * @inheritdoc
12
     */
13
    public function get($key)
14
    {
15
        return $this->getWithMerge($key, $this->group, $this->prefix, $this->postfix);
16
    }
17
18
    /**
19
     * Merge available configuration from each configuration group.
20
     */
21
    public function getWithMerge($key, $group, $prefix = '', $postfix = '.')
22
    {
23
        $configKey = "{$prefix}{$group}${postfix}{$key}";
24
        $result = $this->config->get($configKey, []);
25
        if (!is_array($result)) {
26
            throw new \UnexpectedValueException($configKey . ' must be a list of settings to apply.');
27
        }
28
        $moreGeneralGroupname = $this->moreGeneralGroupName($group);
29
        if ($moreGeneralGroupname) {
30
            $result += $this->getWithMerge($key, $moreGeneralGroupname, $prefix, $postfix);
31
        }
32
        return $result;
33
    }
34
}
35