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

DeprecatedMagicAutoloadSniff::process()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 23
rs 8.5906
cc 5
eloc 12
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
     * @var array
27
     */
28
    private $excludeScopes = array(
29
        'T_CLASS'      => true,
30
        'T_ANON_CLASS' => true,
31
        'T_INTERFACE'  => true,
32
        'T_TRAIT'      => true,
33
        'T_NAMESPACE'  => true, // = Only scoped namespaces, non-scoped still needs to be checked in another way.
34
    );
35
    
36
    /**
37
     * Returns an array of tokens this test wants to listen for.
38
     *
39
     * @return array
40
     */
41
    public function register()
42
    {
43
        return array(T_FUNCTION);
44
    }//end register()
45
46
    /**
47
     * Processes this test, when one of its tokens is encountered.
48
     *
49
     * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
50
     * @param int                   $stackPtr  The position of the current token in the
51
     *                                         stack passed in $tokens.
52
     *
53
     * @return void
54
     */
55
    public function process(\PHP_CodeSniffer_File $phpcsFile, $stackPtr)
56
    {
57
        $tokens = $phpcsFile->getTokens();
0 ignored issues
show
Unused Code introduced by
$tokens is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
58
        if ($this->supportsAbove('7.2') === false) {
59
            return;
60
        }
61
62
        $funcName = $phpcsFile->getDeclarationName($stackPtr);
63
        
64
        if (strtolower($funcName) !== '__autoload') {
65
            return;
66
        }
67
68
        if ($this->validDirectScope($phpcsFile, $stackPtr, $this->excludeScopes) === true) {
69
            return;
70
        }
71
72
        if ($this->determineNamespace($phpcsFile, $stackPtr) != '') {
73
            return;
74
        }
75
76
        $phpcsFile->addWarning('Use of __autoload() function is deprecated since PHP 7.2', $stackPtr, 'Found');
77
    }//end process()
78
79
}//end class
80