Completed
Push — php72-deprecations ( 91fc69 )
by Wim
02:23
created

DeprecatedMagicAutoloadSniff   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 39
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 5 1
B process() 0 29 4
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
/**
13
 * PHPCompatibility_Sniffs_PHP_DeprecatedMagicAutoloadSniff.
14
 *
15
 * @category  PHP
16
 * @package   PHPCompatibility
17
 * @author    Wim Godden <[email protected]
18
 */
19
class PHPCompatibility_Sniffs_PHP_DeprecatedMagicAutoloadSniff extends PHPCompatibility_Sniff
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
20
{
21
22
    public function register()
23
    {
24
        return array(T_FUNCTION);
25
26
    }//end register()
27
28
    public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
29
    {
30
        if ($this->supportsAbove('7.2') === false) {
31
            return;
32
        }
33
34
        $tokens = $phpcsFile->getTokens();
35
36
        $function = $tokens[$stackPtr];
37
        
38
        $funcName = $phpcsFile->getDeclarationName($function);
39
        
40
        if ($funcName != '__autoload') {
41
            return;
42
        }
43
        
44
        
45
        $class = $tokens[$stackPtr];
46
47
        if (isset($class['scope_closer']) === false) {
48
            return;
49
        }
50
51
        $phpcsFile->addWarning(
52
            'Use of __autoload() function is deprecated since PHP 7.2',
53
            $stackPtr,
54
            'Found'
55
        );
56
    }
57
}
58