These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
1 ignored issue
–
show
|
|||
2 | /** |
||
3 | * Hummingbird Anime Client |
||
4 | * |
||
5 | * An API client for Hummingbird to manage anime and manga watch lists |
||
6 | * |
||
7 | * @package HummingbirdAnimeClient |
||
8 | * @author Timothy J. Warren |
||
9 | * @copyright Copyright (c) 2015 |
||
10 | * @link https://github.com/timw4mail/HummingBirdAnimeClient |
||
11 | * @license MIT |
||
12 | */ |
||
13 | use Whoops\Handler\PrettyPageHandler; |
||
14 | use Whoops\Handler\JsonResponseHandler; |
||
15 | |||
16 | // Work around the silly timezone error |
||
17 | $timezone = ini_get('date.timezone'); |
||
18 | if ($timezone === '' || $timezone === FALSE) |
||
19 | { |
||
20 | ini_set('date.timezone', 'GMT'); |
||
21 | } |
||
22 | |||
23 | // Define base directories |
||
24 | define('ROOT_DIR', __DIR__); |
||
25 | define('APP_DIR', ROOT_DIR . DIRECTORY_SEPARATOR . 'app'); |
||
26 | define('SRC_DIR', ROOT_DIR . DIRECTORY_SEPARATOR . 'src'); |
||
27 | define('CONF_DIR', APP_DIR . DIRECTORY_SEPARATOR . 'config'); |
||
28 | define('BASE_DIR', SRC_DIR . DIRECTORY_SEPARATOR . 'Base'); |
||
29 | |||
30 | /** |
||
31 | * Joins paths together. Variadic to take an |
||
32 | * arbitrary number of arguments |
||
33 | * |
||
34 | * @return string |
||
35 | */ |
||
36 | function _dir() |
||
37 | { |
||
38 | return implode(DIRECTORY_SEPARATOR, func_get_args()); |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * Set up autoloaders |
||
43 | * |
||
44 | * @codeCoverageIgnore |
||
45 | * @return void |
||
46 | */ |
||
47 | spl_autoload_register(function($class) { |
||
48 | $class_parts = explode('\\', $class); |
||
49 | $ns_path = SRC_DIR . '/' . implode('/', $class_parts) . ".php"; |
||
50 | |||
51 | if (file_exists($ns_path)) |
||
52 | { |
||
53 | require_once($ns_path); |
||
54 | return; |
||
55 | } |
||
56 | }); |
||
57 | |||
58 | require _dir(ROOT_DIR, '/vendor/autoload.php'); |
||
59 | |||
60 | // ------------------------------------------------------------------------- |
||
61 | // Setup error handling |
||
62 | // ------------------------------------------------------------------------- |
||
63 | $whoops = new \Whoops\Run(); |
||
64 | |||
65 | // Set up default handler for general errors |
||
66 | $defaultHandler = new PrettyPageHandler(); |
||
67 | $whoops->pushHandler($defaultHandler); |
||
1 ignored issue
–
show
$defaultHandler is of type object<Whoops\Handler\PrettyPageHandler> , but the function expects a callable .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
68 | |||
69 | // Set up json handler for ajax errors |
||
70 | $jsonHandler = new JsonResponseHandler(); |
||
71 | $jsonHandler->onlyForAjaxRequests(TRUE); |
||
72 | $whoops->pushHandler($jsonHandler); |
||
1 ignored issue
–
show
$jsonHandler is of type object<Whoops\Handler\JsonResponseHandler> , but the function expects a callable .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
73 | |||
74 | // Register as the error handler |
||
75 | $whoops->register(); |
||
76 | |||
77 | // ----------------------------------------------------------------------------- |
||
78 | // Dependency Injection setup |
||
79 | // ----------------------------------------------------------------------------- |
||
80 | require _dir(CONF_DIR, 'base_config.php'); // $base_config |
||
81 | require _dir(CONF_DIR, 'config.php'); // $config |
||
82 | $config_array = array_merge($base_config, $config); |
||
83 | $di = require _dir(APP_DIR, 'bootstrap.php'); |
||
84 | $container = $di($config_array); |
||
85 | $container->set('error-handler', $defaultHandler); |
||
86 | |||
87 | // ----------------------------------------------------------------------------- |
||
88 | // Dispatch to the current route |
||
89 | // ----------------------------------------------------------------------------- |
||
90 | $container->get('dispatcher')->__invoke(); |
||
91 | |||
92 | // End of index.php |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.