Config   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 9
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 65
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A init() 0 9 2
A getConfigField() 0 14 3
A setConfigField() 0 8 2
A getConfigArray() 0 4 1
1
<?php
2
3
namespace FinanCalc\Utils {
4
5
    use Exception;
6
    use FinanCalc\Constants\Defaults;
7
    use FinanCalc\Constants\ErrorMessages;
8
9
    /**
10
     * Class Config
11
     * @package FinanCalc\Utils
12
     */
13
    class Config
14
    {
15
        protected static $configArray = array();
16
17
        /**
18
         * PRIVATE constructor
19
         */
20
        private function __construct()
21
        {
22
        }
23
24
        /**
25
         * @param null $defaultValues
26
         */
27
        public static function init($defaultValues = null)
28
        {
29
            if ($defaultValues == null) {
30
                $defaultValues = Defaults::$configDefault;
31
            } else {
32
                $defaultValues = array_merge(Defaults::$configDefault, $defaultValues);
33
            }
34
            static::$configArray = $defaultValues;
35
        }
36
37
        /**
38
         * @param string $key
39
         * @return mixed
40
         * @throws Exception
41
         */
42
        public static function getConfigField($key)
43
        {
44
            if (empty(static::$configArray)) {
45
                Config::init();
46
            }
47
48
            $configField = static::$configArray[$key];
49
50
            if ($configField === null) {
51
                throw new Exception(ErrorMessages::getConfigFieldNotFoundMessage($key));
52
            }
53
54
            return $configField;
55
        }
56
57
        /**
58
         * @param $key
59
         * @param $value
60
         */
61
        public static function setConfigField($key, $value)
62
        {
63
            if (empty(static::$configArray)) {
64
                Config::init();
65
            }
66
67
            static::$configArray[$key] = $value;
68
        }
69
70
        /**
71
         * @return array
72
         */
73
        public static function getConfigArray()
74
        {
75
            return static::$configArray;
76
        }
77
    }
78
}
79