Completed
Push — feature/changelog-readme-updat... ( 019eb0 )
by Juliette
02:36
created

PHPCSAliases.php (1 issue)

Upgrade to new PHP Analysis Engine

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
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 40 and the first side effect is on line 28.

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.

Loading history...
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
 * {@internal The `class_exists` wrappers are needed to play nice with other
23
 * external PHPCS standards creating cross-version compatibility in the same
24
 * manner.}}
25
 */
26
if (defined('PHPCOMPATIBILITY_PHPCS_ALIASES_SET') === false) {
27
    if (interface_exists('\PHP_CodeSniffer_Sniff') === false) {
28
        class_alias('PHP_CodeSniffer\Sniffs\Sniff', '\PHP_CodeSniffer_Sniff');
29
    }
30
    if (class_exists('\PHP_CodeSniffer_File') === false) {
31
        class_alias('PHP_CodeSniffer\Files\File', '\PHP_CodeSniffer_File');
32
    }
33
    if (class_exists('\PHP_CodeSniffer_Tokens') === false) {
34
        class_alias('PHP_CodeSniffer\Util\Tokens', '\PHP_CodeSniffer_Tokens');
35
    }
36
    if (class_exists('\PHP_CodeSniffer_Exception') === false) {
37
        class_alias('PHP_CodeSniffer\Exceptions\RuntimeException', '\PHP_CodeSniffer_Exception');
38
    }
39
40
    define('PHPCOMPATIBILITY_PHPCS_ALIASES_SET', true);
41
}
42
43
44
/*
45
 * Register an autoloader.
46
 *
47
 * {@internal This autoloader is not needed for running the sniffs, however, it *is*
48
 * needed for running the unit tests as the PHPCS native autoloader runs into trouble there.
49
 * This issue will be fixed in PHPCS 3.1, so the below code can be removed once the
50
 * minimum PHPCS 3.x requirement for PHPCompatibility has gone up to 3.1.
51
 * Upstream issue: {@link https://github.com/squizlabs/PHP_CodeSniffer/issues/1564} }}
52
 */
53
if (defined('PHP_CODESNIFFER_IN_TESTS')) {
54
    spl_autoload_register(function ($class) {
55
        // Only try & load our own classes.
56
        if (stripos($class, 'PHPCompatibility') !== 0) {
57
            return;
58
        }
59
60
        $file = realpath(__DIR__) . DIRECTORY_SEPARATOR . strtr($class, '\\', DIRECTORY_SEPARATOR) . '.php';
61
62
        if (file_exists($file)) {
63
            include_once($file);
64
        }
65
    });
66
}
67