Config::get()   A
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
nc 6
nop 2
dl 0
loc 20
ccs 0
cts 11
cp 0
crap 30
rs 9.2888
c 0
b 0
f 0
1
<?php
2
3
namespace CodexShaper\WP\Support\Facades;
4
5
class Config
6
{
7
    protected $config = [];
8
9
    public function __construct($options = [])
10
    {
11
        $dir = __DIR__ . '/../../../../../../';
12
13
        if (! empty($options) && isset($options['paths']['root'])) {
14
            $dir = rtrim($options['paths']['root'], "/") . '/';
15
        }
16
        
17
        foreach (glob($dir . 'config/*.php') as $file) {
18
            $index = pathinfo($file)['filename'];
19
            $this->config[$index] = require_once $file;
20
        }
21
    }
22
23
    public function get($config, $default = null)
24
    {
25
        $keys = explode('.', $config);
26
        $filename = array_shift($keys);
27
        $data = $this->config[$filename];
28
29
        foreach ($keys as $key) {
30
            if (is_array($data) && array_key_exists($key, $data)) {
31
                $data = $data[$key];
32
            } else {
33
                $data = null;
34
            }
35
        }
36
37
        if (!$data) {
38
            $data = $default;
39
        }
40
41
        return $data;
42
    }
43
}
44