|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* \PHPCompatibility\Sniffs\PHP\RemovedConstantsSniff. |
|
4
|
|
|
* |
|
5
|
|
|
* @category PHP |
|
6
|
|
|
* @package PHPCompatibility |
|
7
|
|
|
* @author Juliette Reinders Folmer <[email protected]> |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace PHPCompatibility\Sniffs\PHP; |
|
11
|
|
|
|
|
12
|
|
|
use PHPCompatibility\AbstractRemovedFeatureSniff; |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* \PHPCompatibility\Sniffs\PHP\RemovedConstantsSniff. |
|
16
|
|
|
* |
|
17
|
|
|
* @category PHP |
|
18
|
|
|
* @package PHPCompatibility |
|
19
|
|
|
* @author Juliette Reinders Folmer <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class RemovedConstantsSniff extends AbstractRemovedFeatureSniff |
|
22
|
|
|
{ |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* A list of removed PHP Constants. |
|
26
|
|
|
* |
|
27
|
|
|
* The array lists : version number with false (deprecated) or true (removed). |
|
28
|
|
|
* If's sufficient to list the first version where the constant was deprecated/removed. |
|
29
|
|
|
* |
|
30
|
|
|
* Note: PHP Constants are case-sensitive! |
|
31
|
|
|
* |
|
32
|
|
|
* @var array(string => array(string => bool|string|null)) |
|
33
|
|
|
*/ |
|
34
|
|
|
protected $removedConstants = array( |
|
35
|
|
|
// Disabled since PHP 5.3.0 due to thread safety issues. |
|
36
|
|
|
'FILEINFO_COMPRESS' => array( |
|
37
|
|
|
'5.3' => true, |
|
38
|
|
|
), |
|
39
|
|
|
|
|
40
|
|
|
'CURLOPT_CLOSEPOLICY' => array( |
|
41
|
|
|
'5.6' => true, |
|
42
|
|
|
), |
|
43
|
|
|
'CURLCLOSEPOLICY_LEAST_RECENTLY_USED' => array( |
|
44
|
|
|
'5.6' => true, |
|
45
|
|
|
), |
|
46
|
|
|
'CURLCLOSEPOLICY_LEAST_TRAFFIC' => array( |
|
47
|
|
|
'5.6' => true, |
|
48
|
|
|
), |
|
49
|
|
|
'CURLCLOSEPOLICY_SLOWEST' => array( |
|
50
|
|
|
'5.6' => true, |
|
51
|
|
|
), |
|
52
|
|
|
'CURLCLOSEPOLICY_CALLBACK' => array( |
|
53
|
|
|
'5.6' => true, |
|
54
|
|
|
), |
|
55
|
|
|
'CURLCLOSEPOLICY_OLDEST' => array( |
|
56
|
|
|
'5.6' => true, |
|
57
|
|
|
), |
|
58
|
|
|
|
|
59
|
|
|
'PGSQL_ATTR_DISABLE_NATIVE_PREPARED_STATEMENT' => array( |
|
60
|
|
|
'7.0' => true, |
|
61
|
|
|
), |
|
62
|
|
|
|
|
63
|
|
|
'INTL_IDNA_VARIANT_2003' => array( |
|
64
|
|
|
'7.2' => false, |
|
65
|
|
|
), |
|
66
|
|
|
|
|
67
|
|
|
); |
|
68
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Returns an array of tokens this test wants to listen for. |
|
72
|
|
|
* |
|
73
|
|
|
* @return array |
|
74
|
|
|
*/ |
|
75
|
|
|
public function register() |
|
76
|
|
|
{ |
|
77
|
|
|
return array(T_STRING); |
|
78
|
|
|
|
|
79
|
|
|
}//end register() |
|
80
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Processes this test, when one of its tokens is encountered. |
|
84
|
|
|
* |
|
85
|
|
|
* @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
86
|
|
|
* @param int $stackPtr The position of the current token in |
|
87
|
|
|
* the stack passed in $tokens. |
|
88
|
|
|
* |
|
89
|
|
|
* @return void |
|
90
|
|
|
*/ |
|
91
|
|
View Code Duplication |
public function process(\PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
92
|
|
|
{ |
|
93
|
|
|
$tokens = $phpcsFile->getTokens(); |
|
94
|
|
|
$constantName = $tokens[$stackPtr]['content']; |
|
95
|
|
|
|
|
96
|
|
|
if (isset($this->removedConstants[$constantName]) === false) { |
|
97
|
|
|
return; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
if ($this->isUseOfGlobalConstant($phpcsFile, $stackPtr) === false) { |
|
101
|
|
|
return; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
$itemInfo = array( |
|
105
|
|
|
'name' => $constantName, |
|
106
|
|
|
); |
|
107
|
|
|
$this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
108
|
|
|
|
|
109
|
|
|
}//end process() |
|
110
|
|
|
|
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
114
|
|
|
* |
|
115
|
|
|
* @param array $itemInfo Base information about the item. |
|
116
|
|
|
* |
|
117
|
|
|
* @return array Version and other information about the item. |
|
118
|
|
|
*/ |
|
119
|
|
|
public function getItemArray(array $itemInfo) |
|
120
|
|
|
{ |
|
121
|
|
|
return $this->removedConstants[$itemInfo['name']]; |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Get the error message template for this sniff. |
|
127
|
|
|
* |
|
128
|
|
|
* @return string |
|
129
|
|
|
*/ |
|
130
|
|
|
protected function getErrorMsgTemplate() |
|
131
|
|
|
{ |
|
132
|
|
|
return 'The constant "%s" is '; |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
}//end class |
|
136
|
|
|
|