Config   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 66.67%

Importance

Changes 4
Bugs 0 Features 2
Metric Value
c 4
b 0
f 2
dl 0
loc 54
ccs 12
cts 18
cp 0.6667
rs 10
wmc 9
lcom 1
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 15 4
A load() 0 9 3
A initConfigDir() 0 4 2
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