Manager::getBxConfig()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
namespace PrettyBx\Support\Config;
4
5
use PrettyBx\Support\Contracts\ConfigurationContract;
6
use Bitrix\Main\Config\Configuration;
0 ignored issues
show
Bug introduced by
The type Bitrix\Main\Config\Configuration was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
8
class Manager implements ConfigurationContract
9
{
10
    /**
11
     * @var Configuration $bxConfig
12
     */
13
    protected $bxConfig;
14
15
    /**
16
     * @inheritDoc
17
     */
18
    public function get(string $key)
19
    {
20
        $value = $this->getBxConfig()->get($key);
21
22
        if (! empty($value)) {
23
            return $value;
24
        }
25
26
        $keyPath = explode('.', $key);
27
28
        $root = $this->getBxConfig()->get(array_shift($keyPath));
29
30
        if (empty($root) || ! is_array($root)) {
31
            return '';
32
        }
33
34
        $current = $root;
35
        foreach ($keyPath as $key => $val) {
36
            if (empty($current[$val])) {
37
                return '';
38
            }
39
40
            $current = $current[$val];
41
        }
42
43
        return $current;
44
    }
45
46
    /**
47
     * getBxConfig.
48
     *
49
     * @access	protected
50
     * @return	Configuration
51
     */
52
    protected function getBxConfig()
53
    {
54
        if (empty($this->bxConfig)) {
55
            $this->bxConfig = Configuration::getInstance();
56
        }
57
58
        return $this->bxConfig;
59
    }
60
}
61