Config::load()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.3332

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 5
c 1
b 0
f 1
nc 4
nop 1
dl 0
loc 9
ccs 4
cts 6
cp 0.6667
crap 3.3332
rs 9.6666
1
<?php
2
namespace JayaCode\Framework\Core\Helper\Config;
3
4
/**
5
 * Class Config
6
 * @package JayaCode\Framework\Core\Config
7
 */
8
class Config
9
{
10
    /**
11
     * @var string
12
     */
13
    public static $configDir = null;
14
    /**
15
     * @var array
16
     */
17
    protected static $dataConfig = array();
18
19
    /**
20
     * @param $name
21
     * @param $default
22
     * @return mixed
23
     */
24 9
    public static function get($name, $default = null)
25
    {
26 9
        $configName = explode(".", $name);
27 9
        $configName = $configName[0];
28
29 9
        if (!isset(static::$dataConfig[$configName])) {
30 9
            static::$dataConfig[$configName] = static::load($configName.".php");
31 9
        }
32
33 9
        if ($configName == $name && !is_array(static::$dataConfig[$configName])) {
34
            return static::$dataConfig[$configName];
35
        }
36
37 9
        return arr_get(static::$dataConfig, $name, $default);
38
    }
39
40
    /**
41
     * @param $filename
42
     * @return array|mixed
43
     */
44 9
    public static function load($filename)
45
    {
46 9
        if (is_null(static::$configDir)) {
47
            static::initConfigDir();
48
        }
49
50 9
        $locFile = static::$configDir."/".$filename;
51 9
        return file_exists($locFile)?include($locFile):array();
52
    }
53
54
    /**
55
     * Init $configDir
56
     */
57
    protected static function initConfigDir()
58
    {
59
        static::$configDir = defined("__CONFIG_DIR__")?__CONFIG_DIR__:__DIR__."/config";
60
    }
61
}
62