ConfigurationReader   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 2
dl 0
loc 52
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
D configure() 0 36 10
1
<?php
2
3
namespace Magium\Util\Configuration;
4
5
class ConfigurationReader extends AbstractConfigurationReader
6
{
7
8
    protected $baseDir;
9
10
    protected $config = null;
11
12
    public function __construct(
13
        $baseDir = null
14
    )
15
    {
16
        $this->baseDir = $baseDir;
17
    }
18
19
    public function configure(ConfigurableObjectInterface $config)
20
    {
21
        if ($this->config === null) {
22
            $file = 'magium.json';
23
            $dir = $this->baseDir;
24
            if ($dir === null) {
25
                $dir = __DIR__;
26
            }
27
            $count = 0;
28
            while ($count++ < 10) {
29
                $filePath = $dir . '/' . $file;
30
                if (file_exists($filePath)) {
31
                    $this->config = json_decode(file_get_contents($filePath), true);
32
                    break;
33
                }
34
                $dir = realpath($dir . '/..');
35
            }
36
        }
37
38
        if ($this->config === null) {
39
            $this->config = false;
40
        }
41
42
        if ($this->config) {
43
            $classes = $this->introspectClass($config);
44
            foreach ($classes as $class) {
45
                $className = strtolower($class);
46
                if (isset($this->config['magium'][$className])) {
47
                    foreach ($this->config['magium'][$className] as $property => $value) {
48
                        $config->set($property, $value);
49
                    }
50
                }
51
            }
52
        }
53
54
    }
55
56
}
57