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 ( 28d14f...c253f8 )
by
unknown
03:01
created

Reactor   A

Complexity

Total Complexity 27

Size/Duplication

Total Lines 194
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 73
dl 0
loc 194
rs 10
c 0
b 0
f 0
wmc 27

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __reconstruct() 0 6 2
B cliHandler() 0 31 7
B __construct() 0 41 8
C httpHandler() 0 58 10
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;
15
16
// ------------------------------------------------------------------------
17
18
/*
19
 * ---------------------------------------------------------------
20
 * ERROR REPORTING
21
 * ---------------------------------------------------------------
22
 *
23
 * Different environments will require different levels of error reporting.
24
 * By default development will show errors but testing and live will hide them.
25
 */
26
switch (strtoupper(ENVIRONMENT)) {
0 ignored issues
show
Bug introduced by
The constant O2System\ENVIRONMENT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
27
    case 'DEVELOPMENT':
28
        error_reporting(-1);
29
        ini_set('display_errors', 1);
30
        break;
31
    case 'TESTING':
32
    case 'PRODUCTION':
33
        ini_set('display_errors', 0);
34
        error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
35
        break;
36
    default:
37
        header('HTTP/1.1 503 Service Unavailable.', true, 503);
38
        echo 'The application environment is not set correctly.';
39
        exit(1); // EXIT_ERROR
40
}
41
42
/*
43
 *---------------------------------------------------------------
44
 * VENDOR PATH
45
 *---------------------------------------------------------------
46
 *
47
 * RealPath to vendor folder.
48
 *
49
 * WITH TRAILING SLASH!
50
 */
51
if ( ! defined('PATH_VENDOR')) {
52
    define('PATH_VENDOR', PATH_ROOT . 'vendor' . DIRECTORY_SEPARATOR);
0 ignored issues
show
Bug introduced by
The constant O2System\PATH_ROOT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
53
}
54
55
/*
56
 *---------------------------------------------------------------
57
 * FRAMEWORK PATH
58
 *---------------------------------------------------------------
59
 *
60
 * RealPath to framework folder.
61
 *
62
 * WITH TRAILING SLASH!
63
 */
64
if ( ! defined('PATH_REACTOR')) {
65
    define('PATH_REACTOR', __DIR__ . DIRECTORY_SEPARATOR);
66
}
67
68
/*
69
 *---------------------------------------------------------------
70
 * APP PATH
71
 *---------------------------------------------------------------
72
 *
73
 * RealPath to application folder.
74
 *
75
 * WITH TRAILING SLASH!
76
 */
77
if ( ! defined('PATH_APP')) {
78
    define('PATH_APP', PATH_ROOT . DIR_APP . DIRECTORY_SEPARATOR);
0 ignored issues
show
Bug introduced by
The constant O2System\DIR_APP was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
79
}
80
81
/*
82
 *---------------------------------------------------------------
83
 * PUBLIC PATH
84
 *---------------------------------------------------------------
85
 *
86
 * RealPath to public folder.
87
 *
88
 * WITH TRAILING SLASH!
89
 */
90
if ( ! defined('PATH_PUBLIC')) {
91
    define('PATH_PUBLIC', PATH_ROOT . DIR_PUBLIC . DIRECTORY_SEPARATOR);
0 ignored issues
show
Bug introduced by
The constant O2System\DIR_PUBLIC was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
92
}
93
94
/*
95
 *---------------------------------------------------------------
96
 * CACHE PATH
97
 *---------------------------------------------------------------
98
 *
99
 * RealPath to writable caching folder.
100
 *
101
 * WITH TRAILING SLASH!
102
 */
103
if ( ! defined('PATH_CACHE')) {
104
    define('PATH_CACHE', PATH_ROOT . DIR_CACHE . DIRECTORY_SEPARATOR);
0 ignored issues
show
Bug introduced by
The constant O2System\DIR_CACHE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
105
}
106
107
/*
108
 *---------------------------------------------------------------
109
 * STORAGE PATH
110
 *---------------------------------------------------------------
111
 *
112
 * RealPath to writable storage folder.
113
 *
114
 * WITH TRAILING SLASH!
115
 */
116
if ( ! defined('PATH_STORAGE')) {
117
    define('PATH_STORAGE', PATH_ROOT . DIR_STORAGE . DIRECTORY_SEPARATOR);
0 ignored issues
show
Bug introduced by
The constant O2System\DIR_STORAGE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
118
}
119
120
/*
121
 *---------------------------------------------------------------
122
 * RESOURCES PATH
123
 *---------------------------------------------------------------
124
 *
125
 * RealPath to writable resources folder.
126
 *
127
 * WITH TRAILING SLASH!
128
 */
129
if ( ! defined('PATH_RESOURCES')) {
130
    define('PATH_RESOURCES', PATH_ROOT . DIR_RESOURCES . DIRECTORY_SEPARATOR);
0 ignored issues
show
Bug introduced by
The constant O2System\DIR_RESOURCES was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
131
}
132
133
134
/*
135
 *---------------------------------------------------------------
136
 * FRAMEWORK CONSTANTS
137
 *---------------------------------------------------------------
138
 */
139
require __DIR__ . '/Config/Constants.php';
140
141
/*
142
 *---------------------------------------------------------------
143
 * FRAMEWORK HELPERS
144
 *---------------------------------------------------------------
145
 */
146
require __DIR__ . '/Helpers/Reactor.php';
147
148
/**
149
 * Class Reactor
150
 *
151
 * @package O2System
152
 */
153
class Reactor extends Kernel
154
{
155
    /**
156
     * Reactor::$config
157
     *
158
     * Reactor Container Config
159
     *
160
     * @var Reactor\Containers\Config
161
     */
162
    public $config;
163
164
    // ------------------------------------------------------------------------
165
    
166
    /**
167
     * Reactor::$models
168
     * 
169
     * Reactor Container Models
170
     *
171
     * @var Reactor\Containers\Models
172
     */
173
    public $models;
174
    
175
    // ------------------------------------------------------------------------
176
177
    /**
178
     * Reactor::__construct
179
     *
180
     * @return Reactor
181
     */
182
    protected function __construct()
183
    {
184
        parent::__construct();
185
186
        if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
187
            profiler()->watch('Starting O2System Reactor');
188
        }
189
190
        // Instantiate Config Container
191
        if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
192
            profiler()->watch('Starting Config Container');
193
        }
194
195
        $this->config = new Reactor\Containers\Config();
196
197
        if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
198
            profiler()->watch('Starting Reactor Services');
199
        }
200
201
        $services = [
202
            'Services\Loader' => 'loader',
203
        ];
204
        
205
        foreach ($services as $className => $classOffset) {
206
            $this->services->load($className, $classOffset);
207
        }
208
209
        // Instantiate Models Container
210
        if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
211
            profiler()->watch('Starting Models Container');
212
        }
213
214
        $this->models = new Reactor\Containers\Models();
215
216
        if (config()->loadFile('cache') === true) {
0 ignored issues
show
Bug introduced by
The method loadFile() does not exist on O2System\Kernel\Datastructures\Config. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

216
        if (config()->/** @scrutinizer ignore-call */ loadFile('cache') === true) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
217
            // Instantiate Cache Service
218
            if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
219
                profiler()->watch('Starting Cache Service');
220
            }
221
            
222
            $this->services->add(new Reactor\Services\Cache(config('cache', true)), 'cache');
0 ignored issues
show
Bug introduced by
It seems like config('cache', true) can also be of type O2System\Reactor\Containers\Config; however, parameter $config of O2System\Reactor\Services\Cache::__construct() does only seem to accept O2System\Cache\Datastructures\Config, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

222
            $this->services->add(new Reactor\Services\Cache(/** @scrutinizer ignore-type */ config('cache', true)), 'cache');
Loading history...
223
        }
224
    }
225
226
    // ------------------------------------------------------------------------
227
228
    /**
229
     * Reactor::__reconstruct
230
     */
231
    protected function __reconstruct()
232
    {
233
        if (is_cli()) {
234
            $this->cliHandler();
235
        } else {
236
            $this->httpHandler();
237
        }
238
    }
239
240
    // ------------------------------------------------------------------------
241
242
    /**
243
     * Reactor::cliHandler
244
     *
245
     * @return void
246
     */
247
    private function cliHandler()
248
    {
249
        // Instantiate CLI Router Service
250
        $this->services->load(Kernel\Cli\Router::class);
251
252
        if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
253
            profiler()->watch('Parse Router Request');
254
        }
255
        router()->parseRequest();
256
257
        if ($commander = router()->getCommander()) {
258
            if ($commander instanceof Kernel\Cli\Router\Datastructures\Commander) {
259
                
260
                // Autoload Model
261
                $modelClassName = str_replace('Commanders', 'Models', $commander->getName());
262
263
                if (class_exists($modelClassName)) {
264
                    models()->load($modelClassName, 'commander');
265
                }
266
267
                if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
268
                    profiler()->watch('Instantiating Requested Commander: ' . $commander->getClass());
269
                }
270
                $requestCommander = $commander->getInstance();
271
272
                if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
273
                    profiler()->watch('Execute Requested Commander: ' . $commander->getClass());
274
                }
275
                $requestCommander->execute();
276
277
                exit(EXIT_SUCCESS);
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
278
            }
279
        }
280
    }
281
282
    // ------------------------------------------------------------------------
283
284
    /**
285
     * Reactor::httpHandler
286
     *
287
     * @return void
288
     */
289
    private function httpHandler()
290
    {
291
        // Instantiate Http Router Service
292
        $this->services->load(Reactor\Http\Router::class);
293
294
        if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
295
            profiler()->watch('Parse Router Request');
296
        }
297
        router()->parseRequest();
298
        
299
        // Instantiate Http Middleware Service
300
        $this->services->load('Http\Middleware', 'middleware');
301
302
        if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
303
            profiler()->watch('Running Middleware Service: Pre Controller');
304
        }
305
        middleware()->run();
306
        
307
        if($this->services->has('controller')) {
308
            $controller = $this->services->get('controller');
309
            
310
            // Autoload Model
311
            $modelClassName = str_replace('Controllers', 'Models', $controller->getName());
312
313
            if (class_exists($modelClassName)) {
314
                $this->models->register($modelClassName, 'controller');
315
            }
316
317
            if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
318
                profiler()->watch('Instantiating Requested Controller: ' . $controller->getClass());
319
            }
320
            $requestController = $controller->getInstance();
321
322
            if (method_exists($requestController, '__reconstruct')) {
323
                $requestController->__reconstruct();
324
            } elseif (method_exists($requestController, 'initialize')) {
325
                $requestController->initialize();
326
            }
327
328
            $this->services->add($requestController, 'controller');
329
330
            if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
331
                profiler()->watch('Calling Middleware Service: Post Controller');
332
            }
333
            middleware()->run();
334
335
            $requestMethod = $controller->getRequestMethod();
336
            $requestMethodArgs = $controller->getRequestMethodArgs();
337
338
            // Call the requested controller method
339
            if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
340
                profiler()->watch('Execute Requested Controller Method');
341
            }
342
343
            $requestController->__call($requestMethod, $requestMethodArgs);
344
        } else {
345
            // Show Error (404) Page Not Found
346
            output()->sendError(404);
347
        }
348
    }
349
}
350