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 ( 776629...deac27 )
by
unknown
03:03
created

Framework   F

Complexity

Total Complexity 74

Size/Duplication

Total Lines 427
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 211
dl 0
loc 427
rs 2.48
c 0
b 0
f 0
wmc 74

4 Methods

Rating   Name   Duplication   Size   Complexity  
F httpHandler() 0 243 49
C cliHandler() 0 54 11
A __reconstruct() 0 28 6
B __construct() 0 51 8

How to fix   Complexity   

Complex Class

Complex classes like Framework often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Framework, and based on these observations, apply Extract Interface, too.

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_FRAMEWORK')) {
65
    define('PATH_FRAMEWORK', __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/Framework.php';
147
148
/**
149
 * Class Framework
150
 *
151
 * @package O2System
152
 */
153
class Framework extends Kernel
154
{
155
    /**
156
     * Framework Container Models
157
     *
158
     * @var Framework\Containers\Models
159
     */
160
    public $models;
161
162
    /**
163
     * Framework Container Modules
164
     *
165
     * @var Framework\Containers\Modules
166
     */
167
    public $modules;
168
169
    // ------------------------------------------------------------------------
170
171
    /**
172
     * Framework::__construct
173
     *
174
     * @return Framework
175
     */
176
    protected function __construct()
177
    {
178
        parent::__construct();
179
180
        if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
181
            profiler()->watch('Starting O2System Framework');
182
        }
183
184
        // Add App Views Folder
185
        output()->addFilePath(PATH_APP);
186
187
        $this->services->load(Framework\Services\Hooks::class);
188
189
        if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
190
            profiler()->watch('Starting Framework Services');
191
        }
192
193
        $services = [
194
            'Containers\Globals' => 'globals',
195
            'Containers\Environment' => 'environment',
196
            'Services\Loader' => 'loader',
197
            'Services\Config' => 'config'
198
        ];
199
200
        foreach ($services as $className => $classOffset) {
201
            $this->services->load($className, $classOffset);
202
        }
203
204
        // Instantiate Models Container
205
        if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
206
            profiler()->watch('Starting Models Container');
207
        }
208
209
        $this->models = new Framework\Containers\Models();
210
211
        // Instantiate Cache Service
212
        if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
213
            profiler()->watch('Starting Cache Service');
214
        }
215
        $this->services->add(new Framework\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\Framework\Services\Config; however, parameter $config of O2System\Framework\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

215
        $this->services->add(new Framework\Services\Cache(/** @scrutinizer ignore-type */ config('cache', true)), 'cache');
Loading history...
216
217
        // Instantiate Modules Container
218
        if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
219
            profiler()->watch('Starting Modules Container');
220
        }
221
        $this->modules = new Framework\Containers\Modules();
222
223
        if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
224
            profiler()->watch('Starting O2System Framework Hooks Pre System');
225
        }
226
        hooks()->callEvent(Framework\Services\Hooks::PRE_SYSTEM);
227
    }
228
229
    // ------------------------------------------------------------------------
230
231
    /**
232
     * Framework::__reconstruct
233
     */
234
    protected function __reconstruct()
235
    {
236
        // Modules default app
237
        if (null !== ($defaultApp = config('app'))) {
0 ignored issues
show
introduced by
The condition null !== $defaultApp = config('app') is always true.
Loading history...
238
            if (false !== ($defaultModule = modules()->getApp($defaultApp))) {
0 ignored issues
show
Bug introduced by
It seems like $defaultApp can also be of type O2System\Framework\Services\Config; however, parameter $segment of O2System\Framework\Containers\Modules::getApp() does only seem to accept string, 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

238
            if (false !== ($defaultModule = modules()->getApp(/** @scrutinizer ignore-type */ $defaultApp))) {
Loading history...
239
                // Register Domain App Module Namespace
240
                loader()->addNamespace($defaultModule->getNamespace(), $defaultModule->getRealPath());
241
242
                // Push Domain App Module
243
                modules()->push($defaultModule);
244
            } elseif (false !== ($defaultModule = modules()->getModule($defaultApp))) {
0 ignored issues
show
Bug introduced by
It seems like $defaultApp can also be of type O2System\Framework\Services\Config; however, parameter $segments of O2System\Framework\Containers\Modules::getModule() does only seem to accept array|string, 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

244
            } elseif (false !== ($defaultModule = modules()->getModule(/** @scrutinizer ignore-type */ $defaultApp))) {
Loading history...
245
                // Register Path Module Namespace
246
                loader()->addNamespace($defaultModule->getNamespace(), $defaultModule->getRealPath());
247
248
                // Push Path Module
249
                modules()->push($defaultModule);
250
            }
251
        }
252
253
        if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
254
            profiler()->watch('Calling Hooks Service: Post System');
255
        }
256
        hooks()->callEvent(Framework\Services\Hooks::POST_SYSTEM);
257
258
        if (is_cli()) {
259
            $this->cliHandler();
260
        } else {
261
            $this->httpHandler();
262
        }
263
    }
264
265
    // ------------------------------------------------------------------------
266
267
    /**
268
     * Framework::cliHandler
269
     *
270
     * @return void
271
     */
272
    private function cliHandler()
273
    {
274
        // Instantiate CLI Router Service
275
        $this->services->load(Framework\Cli\Router::class);
0 ignored issues
show
Bug introduced by
The type O2System\Framework\Cli\Router was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
276
277
        if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
278
            profiler()->watch('Parse Router Request');
279
        }
280
        router()->parseRequest();
281
282
        if ($commander = router()->getCommander()) {
0 ignored issues
show
Bug introduced by
The method getCommander() does not exist on O2System\Framework\Http\Router. ( Ignorable by Annotation )

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

282
        if ($commander = router()->/** @scrutinizer ignore-call */ getCommander()) {

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...
283
            if ($commander instanceof Kernel\Cli\Router\Datastructures\Commander) {
284
                // Autoload Language
285
                language()->loadFile($commander->getParameter());
286
                language()->loadFile($commander->getRequestMethod());
287
                language()->loadFile($commander->getParameter() . '/' . $commander->getRequestMethod());
288
289
                // Autoload Model
290
                foreach ($this->modules as $module) {
291
                    if (in_array($module->getType(), ['KERNEL', 'FRAMEWORK'])) {
292
                        continue;
293
                    }
294
                    $module->loadModel();
295
                }
296
297
                // Autoload Model
298
                $modelClassName = str_replace('Commanders', 'Models', $commander->getName());
299
300
                if (class_exists($modelClassName)) {
301
                    models()->load($modelClassName, 'commander');
0 ignored issues
show
Bug introduced by
The method load() does not exist on O2System\Framework\Models\NoSql\Model. ( Ignorable by Annotation )

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

301
                    models()->/** @scrutinizer ignore-call */ load($modelClassName, 'commander');

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...
Bug introduced by
The method load() does not exist on O2System\Framework\Models\Sql\Model. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

301
                    models()->/** @scrutinizer ignore-call */ load($modelClassName, 'commander');
Loading history...
302
                }
303
304
                // Initialize Controller
305
                if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
306
                    profiler()->watch('Calling Hooks Service: Pre Commander');
307
                }
308
                hooks()->callEvent(Framework\Services\Hooks::PRE_COMMANDER);
309
310
                if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
311
                    profiler()->watch('Instantiating Requested Commander: ' . $commander->getClass());
312
                }
313
                $requestCommander = $commander->getInstance();
314
315
                if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
316
                    profiler()->watch('Calling Hooks Service: Post Commander');
317
                }
318
                hooks()->callEvent(Framework\Services\Hooks::POST_COMMANDER);
319
320
                if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
321
                    profiler()->watch('Execute Requested Commander: ' . $commander->getClass());
322
                }
323
                $requestCommander->execute();
324
325
                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...
326
            }
327
        }
328
    }
329
330
    // ------------------------------------------------------------------------
331
332
    /**
333
     * Framework::httpHandler
334
     *
335
     * @return void
336
     */
337
    private function httpHandler()
338
    {
339
        // Instantiate Http Router Service
340
        $this->services->load(Framework\Http\Router::class);
341
342
        if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
343
            profiler()->watch('Parse Router Request');
344
        }
345
        router()->parseRequest();
346
347
        if (config()->loadFile('session') === 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

347
        if (config()->/** @scrutinizer ignore-call */ loadFile('session') === 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...
348
349
            // Instantiate Session Service
350
            $session = new Session(config('session', true));
0 ignored issues
show
Bug introduced by
It seems like config('session', true) can also be of type O2System\Framework\Services\Config; however, parameter $config of O2System\Session::__construct() does only seem to accept O2System\Kernel\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

350
            $session = new Session(/** @scrutinizer ignore-type */ config('session', true));
Loading history...
351
            $session->setLogger($this->services->get('logger'));
352
353
            if ( ! $session->isStarted()) {
354
                $session->start();
355
            }
356
357
            $this->services->add($session, 'session');
358
359
            if ($session->has('language') and $this->services->has('language')) {
360
                language()->setDefault($session->get('language'));
361
            } else {
362
                $session->set('language', language()->getDefault());
363
            }
364
365
            if (config('security')->protection[ 'csrf' ] === true) {
0 ignored issues
show
Bug Best Practice introduced by
The property protection does not exist on O2System\Framework\Services\Config. Since you implemented __get, consider adding a @property annotation.
Loading history...
366
                $csrfProtection = new Security\Protections\Csrf();
367
                $this->services->add($csrfProtection, 'csrfProtection');
368
            }
369
370
            if (config('security')->protection[ 'xss' ] === true) {
371
                $csrfProtection = new Security\Protections\Xss();
0 ignored issues
show
Unused Code introduced by
The assignment to $csrfProtection is dead and can be removed.
Loading history...
372
                $this->services->add($xssProtection, 'xssProtection');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $xssProtection seems to be never defined.
Loading history...
373
            }
374
        }
375
376
        if (config()->loadFile('view') === true) {
377
            // Instantiate Http UserAgent Service
378
            $this->services->load(Framework\Http\UserAgent::class);
379
380
            // Instantiate Http View Service
381
            $this->services->load(Framework\Http\Parser::class);
382
383
            // Instantiate Http View Service
384
            $this->services->load(Framework\Http\View::class);
385
386
            // Instantiate Http Presenter Service
387
            $this->services->load(Framework\Http\Presenter::class);
388
            presenter()->initialize();
389
        }
390
391
        // Instantiate Http Middleware Service
392
        $this->services->load(Framework\Http\Middleware::class);
393
394
        if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
395
            profiler()->watch('Running Middleware Service: Pre Controller');
396
        }
397
        middleware()->run();
398
399
        if (false !== ($controller = $this->services->get('controller'))) {
400
            if ($controller instanceof Kernel\Http\Router\Datastructures\Controller) {
401
                $controllerParameter = dash($controller->getParameter());
402
                $controllerRequestMethod = dash($controller->getRequestMethod());
403
404
                // Autoload Language
405
                if ($this->services->has('language')) {
406
                    language()->loadFile($controller->getParameter());
407
                    language()->loadFile($controller->getRequestMethod());
408
                    language()->loadFile($controller->getParameter() . '/' . $controller->getRequestMethod());
409
                }
410
411
                // Autoload Model
412
                foreach ($this->modules as $module) {
413
                    if (in_array($module->getType(), ['KERNEL', 'FRAMEWORK'])) {
414
                        continue;
415
                    }
416
                    $module->loadModel();
417
                }
418
419
                // Autoload Model
420
                $modelClassName = str_replace(['Controllers', 'Presenters'], 'Models', $controller->getName());
421
422
                if (class_exists($modelClassName)) {
423
                    $this->models->register('controller', new $modelClassName());
0 ignored issues
show
Bug introduced by
new $modelClassName() of type object is incompatible with the type null|string expected by parameter $offset of O2System\Framework\Containers\Models::register(). ( Ignorable by Annotation )

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

423
                    $this->models->register('controller', /** @scrutinizer ignore-type */ new $modelClassName());
Loading history...
Bug introduced by
'controller' of type string is incompatible with the type O2System\Spl\Containers\...ures\SplServiceRegistry expected by parameter $service of O2System\Framework\Containers\Models::register(). ( Ignorable by Annotation )

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

423
                    $this->models->register(/** @scrutinizer ignore-type */ 'controller', new $modelClassName());
Loading history...
424
                }
425
426
                // Autoload Assets
427
                if (config()->loadFile('view') === true) {
428
                    $controllerAssets = [];
429
                    $controllerAssetsDirs = [];
430
431
                    // Autoload Assets
432
                    foreach ($this->modules as $module) {
433
                        if (in_array($module->getType(), ['KERNEL', 'FRAMEWORK'])) {
434
                            continue;
435
                        }
436
437
                        $controllerAssets[] = $module->getParameter();
438
                        $controllerAssetsDirs[] = $module->getParameter();
439
                    }
440
441
                    $controllerAssets = array_reverse($controllerAssets);
442
                    $controllerAssetsDirs = array_reverse($controllerAssetsDirs);
443
444
                    $controllerAssets[] = $controllerParameter;
445
                    $controllerAssetsDirs[] = $controllerParameter;
446
447
                    $controllerAssets[] = $controllerRequestMethod;
448
449
                    foreach ($controllerAssetsDirs as $controllerAssetsDir) {
450
                        $controllerAssets[] = $controllerAssetsDir . '/' . $controllerParameter;
451
                        $controllerAssets[] = $controllerAssetsDir . '/' . $controllerRequestMethod;
452
                        $controllerAssets[] = $controllerAssetsDir . '/' . $controllerParameter . '/' . $controllerRequestMethod;
453
                    }
454
455
                    // Autoload Presenter
456
                    $presenterClassName = str_replace('Controllers', 'Presenters', $controller->getName());
457
458
                    if (class_exists($presenterClassName)) {
459
                        $presenterClassObject = new $presenterClassName();
460
                        if ($presenterClassObject instanceof Framework\Http\Presenter) {
461
                            $this->services->add($presenterClassObject, 'presenter');
462
                        }
463
                    }
464
465
                    // Re-Initialize Presenter
466
                    presenter()->initialize()->assets->loadFiles(
0 ignored issues
show
Bug Best Practice introduced by
The property assets does not exist on O2System\Framework\Http\Presenter. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug introduced by
The method loadFiles() does not exist on null. ( Ignorable by Annotation )

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

466
                    presenter()->initialize()->assets->/** @scrutinizer ignore-call */ 
467
                                                       loadFiles(

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...
467
                        [
468
                            'css' => $controllerAssets,
469
                            'js'  => $controllerAssets,
470
                        ]
471
                    );
472
                }
473
474
                // Initialize Controller
475
                if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
476
                    profiler()->watch('Calling Hooks Service: Pre Controller');
477
                }
478
479
                hooks()->callEvent(Framework\Services\Hooks::PRE_CONTROLLER);
480
481
                if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
482
                    profiler()->watch('Instantiating Requested Controller: ' . $controller->getClass());
483
                }
484
                $requestController = $controller->getInstance();
485
486
                if (method_exists($requestController, '__reconstruct')) {
487
                    $requestController->__reconstruct();
488
                } elseif (method_exists($requestController, 'initialize')) {
489
                    $requestController->initialize();
490
                }
491
492
                $this->services->add($requestController, 'controller');
493
494
                if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
495
                    profiler()->watch('Calling Middleware Service: Post Controller');
496
                }
497
                hooks()->callEvent(Framework\Services\Hooks::POST_CONTROLLER);
498
499
                $requestMethod = $controller->getRequestMethod();
500
                $requestMethodArgs = $controller->getRequestMethodArgs();
501
502
                // Call the requested controller method
503
                if (profiler() !== false) {
0 ignored issues
show
introduced by
The condition profiler() !== false is always true.
Loading history...
504
                    profiler()->watch('Execute Requested Controller Method');
505
                }
506
                ob_start();
507
                $requestControllerOutput = $requestController->__call($requestMethod, $requestMethodArgs);
508
509
                if (empty($requestControllerOutput)) {
510
                    $requestControllerOutput = ob_get_contents();
511
                    ob_end_clean();
512
                } elseif (is_bool($requestControllerOutput)) {
513
                    if ($requestController instanceof Framework\Http\Controllers\Restful) {
514
                        $requestController->sendError($requestControllerOutput);
515
                    } else {
516
                        if ($requestControllerOutput === true) {
517
                            output()->sendError(200);
518
                            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...
519
                        } elseif ($requestControllerOutput === false) {
0 ignored issues
show
introduced by
The condition $requestControllerOutput === false is always true.
Loading history...
520
                            output()->sendError(204);
521
                            exit(EXIT_ERROR);
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...
522
                        }
523
                    }
524
                } elseif (is_array($requestControllerOutput) or is_object($requestControllerOutput)) {
525
                    if ($requestController instanceof Framework\Http\Controllers\Restful) {
526
                        $requestController->sendPayload($requestControllerOutput);
527
                    } else {
528
                        output()->send($requestControllerOutput);
0 ignored issues
show
Bug introduced by
The method send() does not exist on O2System\Kernel\Cli\Output. ( Ignorable by Annotation )

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

528
                        output()->/** @scrutinizer ignore-call */ send($requestControllerOutput);

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...
529
                    }
530
                } elseif (is_numeric($requestControllerOutput)) {
531
                    output()->sendError($requestControllerOutput);
532
                }
533
534
                if (empty($requestControllerOutput) or $requestControllerOutput === '') {
535
                    if ($requestController instanceof Framework\Http\Controllers\Restful) {
536
                        $requestController->sendError(204);
537
                    } elseif (config()->loadFile('view') === true) {
538
                        $filenames = [
539
                            $controllerRequestMethod,
540
                            $controllerParameter . DIRECTORY_SEPARATOR . $controllerRequestMethod,
541
                        ];
542
543
                        if ($controllerRequestMethod === 'index') {
544
                            array_unshift($filenames, $controllerParameter);
545
                        }
546
547
                        foreach ($filenames as $filename) {
548
                            if (view()->getFilePath($filename)) {
549
                                view()->load($filename);
550
                            }
551
                        }
552
553
                        if (presenter()->partials->offsetExists('content')) {
0 ignored issues
show
Bug introduced by
The method offsetExists() does not exist on null. ( Ignorable by Annotation )

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

553
                        if (presenter()->partials->/** @scrutinizer ignore-call */ offsetExists('content')) {

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...
Bug Best Practice introduced by
The property partials does not exist on O2System\Framework\Http\Presenter. Since you implemented __get, consider adding a @property annotation.
Loading history...
554
                            view()->render();
555
                            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...
556
                        }
557
                    }
558
559
                    // Send default error 204 - No Content
560
                    output()->sendError(204);
561
                } elseif (is_string($requestControllerOutput)) {
562
                    if (is_json($requestControllerOutput)) {
563
                        output()->setContentType('application/json');
0 ignored issues
show
Bug introduced by
The method setContentType() does not exist on O2System\Kernel\Cli\Output. ( Ignorable by Annotation )

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

563
                        output()->/** @scrutinizer ignore-call */ setContentType('application/json');

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...
564
                        output()->send($requestControllerOutput);
565
                    } elseif (is_serialized($requestControllerOutput)) {
566
                        output()->send($requestControllerOutput);
567
                    } elseif (config('presenter', true)->enabled === true) {
0 ignored issues
show
Bug Best Practice introduced by
The property enabled does not exist on O2System\Framework\Services\Config. Since you implemented __get, consider adding a @property annotation.
Loading history...
568
                        presenter()->partials->offsetSet('content', $requestControllerOutput);
569
                        view()->render();
570
                    } else {
571
                        output()->send($requestControllerOutput);
572
                    }
573
                    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...
574
                }
575
            }
576
        }
577
578
        // Show Error (404) Page Not Found
579
        output()->sendError(404);
580
    }
581
}
582