These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
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 - 2016 |
||
10 | * @link https://github.com/timw4mail/HummingBirdAnimeClient |
||
11 | * @license MIT |
||
12 | */ |
||
13 | use Aviat\AnimeClient\AnimeClient; |
||
14 | use Whoops\Handler\PrettyPageHandler; |
||
15 | use Whoops\Handler\JsonResponseHandler; |
||
16 | |||
17 | // Work around the silly timezone error |
||
18 | $timezone = ini_get('date.timezone'); |
||
19 | if ($timezone === '' || $timezone === FALSE) |
||
20 | { |
||
21 | ini_set('date.timezone', 'GMT'); |
||
22 | } |
||
23 | |||
24 | /** |
||
25 | * Joins paths together. Variadic to take an |
||
26 | * arbitrary number of arguments |
||
27 | * |
||
28 | * @return string |
||
29 | */ |
||
30 | function _dir() |
||
31 | { |
||
32 | return implode(DIRECTORY_SEPARATOR, func_get_args()); |
||
33 | } |
||
34 | |||
35 | // Define base directories |
||
36 | $APP_DIR = _dir(__DIR__, 'app'); |
||
37 | $SRC_DIR = _dir(__DIR__, 'src'); |
||
38 | $CONF_DIR = _dir($APP_DIR, 'config'); |
||
39 | |||
40 | /** |
||
41 | * Set up autoloaders |
||
42 | * |
||
43 | * @codeCoverageIgnore |
||
44 | * @return void |
||
45 | */ |
||
46 | spl_autoload_register(function($class) use ($SRC_DIR) { |
||
47 | $class_parts = explode('\\', $class); |
||
48 | $ns_path = $SRC_DIR . '/' . implode('/', $class_parts) . ".php"; |
||
49 | |||
50 | if (file_exists($ns_path)) |
||
51 | { |
||
52 | require_once($ns_path); |
||
53 | return; |
||
54 | } |
||
55 | }); |
||
56 | |||
57 | // Set up autoloader for third-party dependencies |
||
58 | require _dir(__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); |
||
68 | |||
69 | // Set up json handler for ajax errors |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
37% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
70 | //$jsonHandler = new JsonResponseHandler(); |
||
71 | //$whoops->pushHandler($jsonHandler); |
||
72 | |||
73 | // Register as the error handler |
||
74 | $whoops->register(); |
||
75 | |||
76 | // ----------------------------------------------------------------------------- |
||
77 | // Dependency Injection setup |
||
78 | // ----------------------------------------------------------------------------- |
||
79 | require _dir($CONF_DIR, 'base_config.php'); // $base_config |
||
80 | $di = require _dir($APP_DIR, 'bootstrap.php'); |
||
81 | |||
82 | $config = AnimeClient::load_toml($CONF_DIR); |
||
83 | $config_array = array_merge($base_config, $config); |
||
84 | |||
85 | $container = $di($config_array); |
||
86 | |||
87 | // Unset 'constants' |
||
88 | unset($APP_DIR); |
||
89 | unset($SRC_DIR); |
||
90 | unset($CONF_DIR); |
||
91 | |||
92 | // ----------------------------------------------------------------------------- |
||
93 | // Dispatch to the current route |
||
94 | // ----------------------------------------------------------------------------- |
||
95 | $container->get('dispatcher')->__invoke(); |
||
96 | |||
97 | // 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.