Config   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 77
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B _configFile() 0 24 4
A get() 0 4 1
A error() 0 4 1
1
<?php
2
3
/**
4
 * Holds the configuration details
5
 *
6
 * PHP Version 5
7
 *
8
 * @category  Core
9
 * @package   Init
10
 * @author    Hans-Joachim Piepereit <[email protected]>
11
 * @copyright 2013 cSphere Team
12
 * @license   http://opensource.org/licenses/bsd-license Simplified BSD License
13
 * @link      http://www.csphere.eu
14
 **/
15
16
namespace csphere\core\init;
17
18
/**
19
 * Holds the configuration details
20
 *
21
 * @category  Core
22
 * @package   Init
23
 * @author    Hans-Joachim Piepereit <[email protected]>
24
 * @copyright 2013 cSphere Team
25
 * @license   http://opensource.org/licenses/bsd-license Simplified BSD License
26
 * @link      http://www.csphere.eu
27
 **/
28
29
class Config
30
{
31
    /**
32
     * Array with config settings
33
     **/
34
    private $_config = [];
35
36
    /**
37
     * Error details as an array
38
     **/
39
    private $_error = [];
40
41
    /**
42
     * Prepare configuration
43
     *
44
     * @return \csphere\core\init\Config
45
     **/
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
46
47
    public function __construct()
48
    {
49
        // Try to load config file
50
        $this->_configFile();
51
    }
52
53
    /**
54
     * Loads the configuration file
55
     *
56
     * @return void
57
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
58
59
    private function _configFile()
60
    {
61
        $config = [];
62
63
        // Try to load the config file
64
        $file = \csphere\core\init\path() . 'csphere/config/config.php';
65
66
        if (file_exists($file)) {
67
68
            include $file;
69
70
        } else {
71
72
            $this->_error = ['error' => 'config_missing', 'file' => $file];
73
        }
74
75
        // Check for config array to be correct
76
        if (!isset($config) || !is_array($config)) {
77
78
            $this->_error = ['error' => 'config_corrupt', 'file' => $file];
79
        }
80
81
        $this->_config = $config;
0 ignored issues
show
Documentation Bug introduced by
It seems like $config can be null. However, the property $_config is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
82
    }
83
84
    /**
85
     * Pass configuration details
86
     *
87
     * @return array
88
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
89
90
    public function get()
91
    {
92
        return $this->_config;
93
    }
94
95
    /**
96
     * Pass error details
97
     *
98
     * @return array
99
     **/
0 ignored issues
show
Coding Style introduced by
There must be no blank lines after the function comment
Loading history...
100
101
    public function error()
102
    {
103
        return $this->_error;
104
    }
105
}
106