Completed
Pull Request — master (#540)
by Wim
03:14 queued 01:34
created

DeprecatedMagicAutoloadSniff::process()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 22
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 22
rs 8.6737
cc 5
eloc 11
nc 5
nop 2
1
<?php
2
/**
3
 * \PHPCompatibility\Sniffs\PHP\DeprecatedMagicAutoloadSniff.
4
 *
5
 * PHP version 7.2
6
 *
7
 * @category  PHP
8
 * @package   PHPCompatibility
9
 * @author    Wim Godden <[email protected]>
10
 */
11
12
namespace PHPCompatibility\Sniffs\PHP;
13
14
use PHPCompatibility\Sniff;
15
16
/**
17
 * \PHPCompatibility\Sniffs\PHP\DeprecatedMagicAutoloadSniff.
18
 *
19
 * @category  PHP
20
 * @package   PHPCompatibility
21
 * @author    Wim Godden <[email protected]>
22
 */
23
class DeprecatedMagicAutoloadSniff extends Sniff
24
{
25
26
    /**
27
     * Returns an array of tokens this test wants to listen for.
28
     *
29
     * @return array
30
     */
31
    public function register()
32
    {
33
        return array(T_FUNCTION);
34
    }//end register()
35
36
    /**
37
     * Processes this test, when one of its tokens is encountered.
38
     *
39
     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
40
     * @param int                   $stackPtr  The position of the current token in the
41
     *                                         stack passed in $tokens.
42
     *
43
     * @return void
44
     */
45
    public function process(\PHP_CodeSniffer_File $phpcsFile, $stackPtr)
46
    {
47
        if ($this->supportsAbove('7.2') === false) {
48
            return;
49
        }
50
51
        $funcName = $phpcsFile->getDeclarationName($stackPtr);
52
        
53
        if (strtolower($funcName) !== '__autoload') {
54
            return;
55
        }
56
57
        if ($this->determineNamespace($phpcsFile, $stackPtr) != '') {
58
            return;
59
        }
60
61
        if ($this->validDirectScope($phpcsFile, $stackPtr, array('T_CLASS', 'T_ANON_CLASS', 'T_INTERFACE', 'T_TRAIT')) === true) {
62
            return;
63
        }
64
        
65
        $phpcsFile->addWarning('Use of __autoload() function is deprecated since PHP 7.2', $stackPtr, 'Found');
66
    }//end process()
67
68
}//end class
69