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 | /** |
||
4 | * @author Sullivan Senechal <[email protected]> |
||
5 | * |
||
6 | * @link https://github.com/composer/composer/issues/1493#issuecomment-12492276 |
||
7 | */ |
||
8 | class CustomLoader |
||
9 | { |
||
10 | /** |
||
11 | * @var \Composer\Autoload\ClassLoader |
||
12 | */ |
||
13 | private $loader; |
||
14 | |||
15 | /** |
||
16 | * @param \Composer\Autoload\ClassLoader $loader |
||
17 | */ |
||
18 | public function __construct($loader) |
||
19 | { |
||
20 | $this->loader = $loader; |
||
21 | } |
||
22 | |||
23 | /** |
||
24 | * @param string $class The class name |
||
25 | * |
||
26 | * @return bool|null |
||
27 | */ |
||
28 | public function loadClass($class) |
||
29 | { |
||
30 | $result = $this->loader->loadClass($class); |
||
31 | |||
32 | if ($result && method_exists($class, '__static')) { |
||
33 | call_user_func(array($class, '__static')); |
||
34 | } |
||
35 | |||
36 | return $result; |
||
37 | } |
||
38 | } |
||
39 | |||
40 | if (file_exists(__DIR__.'/../../autoload.php')) { |
||
41 | $loader = require __DIR__.'/../../autoload.php'; |
||
42 | } else { |
||
43 | $loader = require __DIR__.'/vendor/autoload.php'; |
||
44 | } |
||
45 | $loader->unregister(); |
||
46 | spl_autoload_register(array(new CustomLoader($loader), 'loadClass')); |
||
47 |
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.