Completed
Push — magic-autoload-deprecations ( 6419e3 )
by Wim
01:42
created

DeprecatedMagicAutoloadSniff::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
nc 3
nop 2
dl 0
loc 14
rs 9.4285
c 1
b 0
f 0
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
        $this->addMessage($phpcsFile, 'Use of __autoload() function is deprecated since PHP 7.2', $stackPtr, false);
58
    }//end process()
59
60
}//end class
61