Config   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 92.59%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 51
ccs 25
cts 27
cp 0.9259
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 4 1
A loadToStore() 0 6 1
A loaded() 0 6 1
A load() 0 8 2
A loadFromStore() 0 17 4
1
<?php
2
3
namespace PHPieces\ANZGateway;
4
5
class Config
6
{
7
    private static $baseDir = __DIR__."/../config/";
8
    private static $store = [];
9
10 27
    public static function load($path)
11
    {
12 27
        if (!self::loaded($path)) {
13 3
            self::loadToStore($path);
14
        }
15
16 27
        return self::loadFromStore($path);
17
    }
18
19 24
    public static function set($key, $val)
20
    {
21 24
        self::$store[$key] = $val;
22 24
    }
23
24 3
    private static function loadToStore($path)
25
    {
26 3
        $vars = explode(".", $path);
27 3
        $file = array_shift($vars);
28 3
        self::$store[$file] = include(self::$baseDir."{$file}.php");
29 3
    }
30
31 27
    private static function loadFromStore($path)
32
    {
33 27
        $vars = explode(".", $path);
34 27
        $file = array_shift($vars);
35 27
        $config = self::$store[$file];
36
37 27
        foreach ($vars as $var) {
38 24
            if (!is_array($config)) {
39
                return null;
40
            }
41 24
            if (!array_key_exists($var, $config)) {
42
                return null;
43
            }
44 24
            $config = $config[$var];
45
        }
46 27
        return $config;
47
    }
48
49 27
    private static function loaded($path)
50
    {
51 27
        $vars = explode(".", $path);
52 27
        $file = array_shift($vars);
53 27
        return isset(self::$store[$file]);
54
    }
55
}
56