Config   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 39
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 4
A get() 0 20 5
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