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 | * PHPCS cross-version compatibility helper. |
||
4 | * |
||
5 | * @category PHP |
||
6 | * @package PHPCompatibility |
||
7 | * @author Juliette Reinders Folmer <[email protected]> |
||
8 | */ |
||
9 | |||
10 | |||
11 | /* |
||
12 | * Alias a number of PHPCS 3.x classes to their PHPCS 2.x equivalents. |
||
13 | * |
||
14 | * This file is auto-loaded by PHPCS 3.x before any sniffs are loaded |
||
15 | * through the PHPCS 3.x `<autoload>` ruleset directive. |
||
16 | * |
||
17 | * {@internal The PHPCS file have been reorganized in PHPCS 3.x, quite |
||
18 | * a few "old" classes have been split and spread out over several "new" |
||
19 | * classes. In other words, this will only work for a limited number |
||
20 | * of classes.}} |
||
21 | */ |
||
22 | if (defined('PHPCOMPATIBILITY_PHPCS_ALIASES_SET') === false) { |
||
23 | class_alias('PHP_CodeSniffer\Sniffs\Sniff', '\PHP_CodeSniffer_Sniff'); |
||
24 | class_alias('PHP_CodeSniffer\Files\File', '\PHP_CodeSniffer_File'); |
||
25 | class_alias('PHP_CodeSniffer\Util\Tokens', '\PHP_CodeSniffer_Tokens'); |
||
26 | class_alias('PHP_CodeSniffer\Exceptions\RuntimeException', '\PHP_CodeSniffer_Exception'); |
||
27 | |||
28 | define('PHPCOMPATIBILITY_PHPCS_ALIASES_SET', true); |
||
29 | } |
||
30 | |||
31 | |||
32 | /* |
||
33 | * Register an autoloader. |
||
34 | * |
||
35 | * This autoloader is not needed for running the sniffs, however, it *is* needed |
||
36 | * for running the unit tests. |
||
37 | */ |
||
38 | if (defined('PHP_CODESNIFFER_IN_TESTS')) { |
||
39 | spl_autoload_register(function ($class) { |
||
40 | // Only try & load our own classes. |
||
41 | if (strpos($class, 'PHPCompatibility') !== 0) { |
||
42 | return; |
||
43 | } |
||
44 | |||
45 | $file = realpath(__DIR__) . DIRECTORY_SEPARATOR . strtr($class, '\\', DIRECTORY_SEPARATOR) . '.php'; |
||
46 | |||
47 | if (file_exists($file)) { |
||
48 | include_once($file); |
||
49 | } |
||
50 | }); |
||
51 | } |
||
52 |
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.