GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( e22738...bc2961 )
by
unknown
01:53
created

Config   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 131
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 43
dl 0
loc 131
rs 10
c 0
b 0
f 0
wmc 17

5 Methods

Rating   Name   Duplication   Size   Complexity  
A addItem() 0 3 1
A __construct() 0 21 6
B loadFile() 0 38 6
A setItem() 0 3 1
A getItem() 0 11 3
1
<?php
2
/**
3
 * This file is part of the O2System PHP Framework package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author         Steeve Andrian Salim
9
 * @copyright      Copyright (c) Steeve Andrian Salim
10
 */
11
12
// ------------------------------------------------------------------------
13
14
namespace O2System\Reactor\Services;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Kernel\Containers\Environment;
19
use O2System\Spl\Datastructures\SplArrayObject;
20
21
/**
22
 * Class Config
23
 *
24
 * @package O2System\Reactor\Services
25
 */
26
class Config extends Environment
27
{
28
    /**
29
     * Config::__construct
30
     */
31
    public function __construct()
32
    {
33
        if (is_file(
34
            $filePath = PATH_APP . 'Config' . DIRECTORY_SEPARATOR . ucfirst(
35
                    strtolower(ENVIRONMENT)
0 ignored issues
show
Bug introduced by
The constant O2System\Reactor\Services\ENVIRONMENT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
36
                ) . DIRECTORY_SEPARATOR . 'Config.php'
37
        )) {
38
            include($filePath);
39
        } elseif (is_file($filePath = PATH_APP . 'Config' . DIRECTORY_SEPARATOR . 'Config.php')) {
40
            include($filePath);
41
        }
42
43
        if (isset($config) AND is_array($config)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $config seems to never exist and therefore isset should always be false.
Loading history...
44
            // Set default timezone
45
            if (isset($config['datetime']['timezone'])) {
46
                date_default_timezone_set($config['datetime']['timezone']);
47
            }
48
49
            $this->merge($config);
50
51
            unset($config);
52
        }
53
    }
54
55
    // ------------------------------------------------------------------------
56
57
    /**
58
     * Config::loadFile
59
     *
60
     * @param string $offset
61
     * @param bool   $return
62
     *
63
     * @return mixed
64
     */
65
    public function loadFile($offset, $return = false)
66
    {
67
        $basename = pathinfo($offset, PATHINFO_BASENAME);
68
        $filename = studlycase($basename);
69
70
        $configFile = str_replace($basename, $filename, $offset);
71
        $offset = camelcase($basename);
72
73
        $configDirs = [
74
            PATH_REACTOR . 'Config' . DIRECTORY_SEPARATOR,
75
            PATH_APP . 'Config' . DIRECTORY_SEPARATOR,
76
        ];
77
78
        foreach ($configDirs as $configDir) {
79
            if (is_file(
80
                $filePath = $configDir . ucfirst(
81
                        strtolower(ENVIRONMENT)
0 ignored issues
show
Bug introduced by
The constant O2System\Reactor\Services\ENVIRONMENT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
82
                    ) . DIRECTORY_SEPARATOR . $configFile . '.php'
83
            )) {
84
                include($filePath);
85
            } elseif (is_file($filePath = $configDir . DIRECTORY_SEPARATOR . $configFile . '.php')) {
86
                include($filePath);
87
            }
88
        }
89
90
        if (isset($$offset)) {
91
            $this->addItem($offset, $$offset);
92
93
            unset($$offset);
94
95
            if ($return) {
96
                return $this->getItem($offset);
97
            }
98
99
            return true;
100
        }
101
102
        return false;
103
    }
104
105
    // ------------------------------------------------------------------------
106
107
    /**
108
     * Config::addItem
109
     *
110
     * Adds config item.
111
     *
112
     * @param string $offset
113
     * @param mixed  $value
114
     */
115
    public function addItem($offset, $value)
116
    {
117
        $this->offsetSet($offset, $value);
118
    }
119
120
    // ------------------------------------------------------------------------
121
122
    /**
123
     * Config::getItem
124
     *
125
     * Gets config item.
126
     *
127
     * @param string $offset
128
     *
129
     * @return mixed|\O2System\Spl\Datastructures\SplArrayObject
130
     */
131
    public function &getItem($offset)
132
    {
133
        $item = parent::offsetGet($offset);
134
135
        if (is_array($item)) {
136
            if (is_string(key($item))) {
137
                $item = new SplArrayObject($item);
138
            }
139
        }
140
141
        return $item;
142
    }
143
144
    // ------------------------------------------------------------------------
145
146
    /**
147
     * Config::setItem
148
     *
149
     * Sets config item.
150
     *
151
     * @param string $offset
152
     * @param mixed  $value
153
     */
154
    public function setItem($offset, $value)
155
    {
156
        $this->offsetSet($offset, $value);
157
    }
158
}