|
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
|
|
|
* Scopes to exclude when testing using validDirectScope |
|
27
|
|
|
* |
|
28
|
|
|
* @var array |
|
29
|
|
|
*/ |
|
30
|
|
|
private $excludeScopes = array( |
|
31
|
|
|
'T_CLASS' => true, |
|
32
|
|
|
'T_ANON_CLASS' => true, |
|
33
|
|
|
'T_INTERFACE' => true, |
|
34
|
|
|
'T_TRAIT' => true, |
|
35
|
|
|
'T_NAMESPACE' => true, // = Only scoped namespaces, non-scoped still needs to be checked in another way. |
|
36
|
|
|
); |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Returns an array of tokens this test wants to listen for. |
|
40
|
|
|
* |
|
41
|
|
|
* @return array |
|
42
|
|
|
*/ |
|
43
|
|
|
public function register() |
|
44
|
|
|
{ |
|
45
|
|
|
return array(T_FUNCTION); |
|
46
|
|
|
}//end register() |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Processes this test, when one of its tokens is encountered. |
|
50
|
|
|
* |
|
51
|
|
|
* @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
52
|
|
|
* @param int $stackPtr The position of the current token in the |
|
53
|
|
|
* stack passed in $tokens. |
|
54
|
|
|
* |
|
55
|
|
|
* @return void |
|
56
|
|
|
*/ |
|
57
|
|
|
public function process(\PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
58
|
|
|
{ |
|
59
|
|
|
if ($this->supportsAbove('7.2') === false) { |
|
60
|
|
|
return; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
$funcName = $phpcsFile->getDeclarationName($stackPtr); |
|
64
|
|
|
|
|
65
|
|
|
if (strtolower($funcName) !== '__autoload') { |
|
66
|
|
|
return; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
if ($this->validDirectScope($phpcsFile, $stackPtr, $this->excludeScopes) === true) { |
|
70
|
|
|
return; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
if ($this->determineNamespace($phpcsFile, $stackPtr) != '') { |
|
74
|
|
|
return; |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
$phpcsFile->addWarning('Use of __autoload() function is deprecated since PHP 7.2', $stackPtr, 'Found'); |
|
78
|
|
|
}//end process() |
|
79
|
|
|
|
|
80
|
|
|
}//end class |
|
81
|
|
|
|