@@ -28,210 +28,210 @@ |
||
28 | 28 | */ |
29 | 29 | class NewClosureSniff extends Sniff |
30 | 30 | { |
31 | - /** |
|
32 | - * Returns an array of tokens this test wants to listen for. |
|
33 | - * |
|
34 | - * @return array |
|
35 | - */ |
|
36 | - public function register() |
|
37 | - { |
|
38 | - return array(\T_CLOSURE); |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * Processes this test, when one of its tokens is encountered. |
|
43 | - * |
|
44 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
45 | - * @param int $stackPtr The position of the current token |
|
46 | - * in the stack passed in $tokens. |
|
47 | - * |
|
48 | - * @return void |
|
49 | - */ |
|
50 | - public function process(File $phpcsFile, $stackPtr) |
|
51 | - { |
|
52 | - if ($this->supportsBelow('5.2')) { |
|
53 | - $phpcsFile->addError( |
|
54 | - 'Closures / anonymous functions are not available in PHP 5.2 or earlier', |
|
55 | - $stackPtr, |
|
56 | - 'Found' |
|
57 | - ); |
|
58 | - } |
|
59 | - |
|
60 | - /* |
|
31 | + /** |
|
32 | + * Returns an array of tokens this test wants to listen for. |
|
33 | + * |
|
34 | + * @return array |
|
35 | + */ |
|
36 | + public function register() |
|
37 | + { |
|
38 | + return array(\T_CLOSURE); |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * Processes this test, when one of its tokens is encountered. |
|
43 | + * |
|
44 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
45 | + * @param int $stackPtr The position of the current token |
|
46 | + * in the stack passed in $tokens. |
|
47 | + * |
|
48 | + * @return void |
|
49 | + */ |
|
50 | + public function process(File $phpcsFile, $stackPtr) |
|
51 | + { |
|
52 | + if ($this->supportsBelow('5.2')) { |
|
53 | + $phpcsFile->addError( |
|
54 | + 'Closures / anonymous functions are not available in PHP 5.2 or earlier', |
|
55 | + $stackPtr, |
|
56 | + 'Found' |
|
57 | + ); |
|
58 | + } |
|
59 | + |
|
60 | + /* |
|
61 | 61 | * Closures can only be declared as static since PHP 5.4. |
62 | 62 | */ |
63 | - $isStatic = $this->isClosureStatic($phpcsFile, $stackPtr); |
|
64 | - if ($this->supportsBelow('5.3') && $isStatic === true) { |
|
65 | - $phpcsFile->addError( |
|
66 | - 'Closures / anonymous functions could not be declared as static in PHP 5.3 or earlier', |
|
67 | - $stackPtr, |
|
68 | - 'StaticFound' |
|
69 | - ); |
|
70 | - } |
|
71 | - |
|
72 | - $tokens = $phpcsFile->getTokens(); |
|
73 | - |
|
74 | - if (isset($tokens[$stackPtr]['scope_opener'], $tokens[$stackPtr]['scope_closer']) === false) { |
|
75 | - // Live coding or parse error. |
|
76 | - return; |
|
77 | - } |
|
78 | - |
|
79 | - $scopeStart = ($tokens[$stackPtr]['scope_opener'] + 1); |
|
80 | - $scopeEnd = $tokens[$stackPtr]['scope_closer']; |
|
81 | - $usesThis = $this->findThisUsageInClosure($phpcsFile, $scopeStart, $scopeEnd); |
|
82 | - |
|
83 | - if ($this->supportsBelow('5.3')) { |
|
84 | - /* |
|
63 | + $isStatic = $this->isClosureStatic($phpcsFile, $stackPtr); |
|
64 | + if ($this->supportsBelow('5.3') && $isStatic === true) { |
|
65 | + $phpcsFile->addError( |
|
66 | + 'Closures / anonymous functions could not be declared as static in PHP 5.3 or earlier', |
|
67 | + $stackPtr, |
|
68 | + 'StaticFound' |
|
69 | + ); |
|
70 | + } |
|
71 | + |
|
72 | + $tokens = $phpcsFile->getTokens(); |
|
73 | + |
|
74 | + if (isset($tokens[$stackPtr]['scope_opener'], $tokens[$stackPtr]['scope_closer']) === false) { |
|
75 | + // Live coding or parse error. |
|
76 | + return; |
|
77 | + } |
|
78 | + |
|
79 | + $scopeStart = ($tokens[$stackPtr]['scope_opener'] + 1); |
|
80 | + $scopeEnd = $tokens[$stackPtr]['scope_closer']; |
|
81 | + $usesThis = $this->findThisUsageInClosure($phpcsFile, $scopeStart, $scopeEnd); |
|
82 | + |
|
83 | + if ($this->supportsBelow('5.3')) { |
|
84 | + /* |
|
85 | 85 | * Closures declared within classes only have access to $this since PHP 5.4. |
86 | 86 | */ |
87 | - if ($usesThis !== false) { |
|
88 | - $thisFound = $usesThis; |
|
89 | - do { |
|
90 | - $phpcsFile->addError( |
|
91 | - 'Closures / anonymous functions did not have access to $this in PHP 5.3 or earlier', |
|
92 | - $thisFound, |
|
93 | - 'ThisFound' |
|
94 | - ); |
|
87 | + if ($usesThis !== false) { |
|
88 | + $thisFound = $usesThis; |
|
89 | + do { |
|
90 | + $phpcsFile->addError( |
|
91 | + 'Closures / anonymous functions did not have access to $this in PHP 5.3 or earlier', |
|
92 | + $thisFound, |
|
93 | + 'ThisFound' |
|
94 | + ); |
|
95 | 95 | |
96 | - $thisFound = $this->findThisUsageInClosure($phpcsFile, ($thisFound + 1), $scopeEnd); |
|
96 | + $thisFound = $this->findThisUsageInClosure($phpcsFile, ($thisFound + 1), $scopeEnd); |
|
97 | 97 | |
98 | - } while ($thisFound !== false); |
|
99 | - } |
|
98 | + } while ($thisFound !== false); |
|
99 | + } |
|
100 | 100 | |
101 | - /* |
|
101 | + /* |
|
102 | 102 | * Closures declared within classes only have access to self/parent/static since PHP 5.4. |
103 | 103 | */ |
104 | - $usesClassRef = $this->findClassRefUsageInClosure($phpcsFile, $scopeStart, $scopeEnd); |
|
104 | + $usesClassRef = $this->findClassRefUsageInClosure($phpcsFile, $scopeStart, $scopeEnd); |
|
105 | 105 | |
106 | - if ($usesClassRef !== false) { |
|
107 | - do { |
|
108 | - $phpcsFile->addError( |
|
109 | - 'Closures / anonymous functions could not use "%s::" in PHP 5.3 or earlier', |
|
110 | - $usesClassRef, |
|
111 | - 'ClassRefFound', |
|
112 | - array(strtolower($tokens[$usesClassRef]['content'])) |
|
113 | - ); |
|
106 | + if ($usesClassRef !== false) { |
|
107 | + do { |
|
108 | + $phpcsFile->addError( |
|
109 | + 'Closures / anonymous functions could not use "%s::" in PHP 5.3 or earlier', |
|
110 | + $usesClassRef, |
|
111 | + 'ClassRefFound', |
|
112 | + array(strtolower($tokens[$usesClassRef]['content'])) |
|
113 | + ); |
|
114 | 114 | |
115 | - $usesClassRef = $this->findClassRefUsageInClosure($phpcsFile, ($usesClassRef + 1), $scopeEnd); |
|
115 | + $usesClassRef = $this->findClassRefUsageInClosure($phpcsFile, ($usesClassRef + 1), $scopeEnd); |
|
116 | 116 | |
117 | - } while ($usesClassRef !== false); |
|
118 | - } |
|
119 | - } |
|
117 | + } while ($usesClassRef !== false); |
|
118 | + } |
|
119 | + } |
|
120 | 120 | |
121 | - /* |
|
121 | + /* |
|
122 | 122 | * Check for correct usage. |
123 | 123 | */ |
124 | - if ($this->supportsAbove('5.4') && $usesThis !== false) { |
|
124 | + if ($this->supportsAbove('5.4') && $usesThis !== false) { |
|
125 | 125 | |
126 | - $thisFound = $usesThis; |
|
126 | + $thisFound = $usesThis; |
|
127 | 127 | |
128 | - do { |
|
129 | - /* |
|
128 | + do { |
|
129 | + /* |
|
130 | 130 | * Closures only have access to $this if not declared as static. |
131 | 131 | */ |
132 | - if ($isStatic === true) { |
|
133 | - $phpcsFile->addError( |
|
134 | - 'Closures / anonymous functions declared as static do not have access to $this', |
|
135 | - $thisFound, |
|
136 | - 'ThisFoundInStatic' |
|
137 | - ); |
|
138 | - } |
|
139 | - |
|
140 | - /* |
|
132 | + if ($isStatic === true) { |
|
133 | + $phpcsFile->addError( |
|
134 | + 'Closures / anonymous functions declared as static do not have access to $this', |
|
135 | + $thisFound, |
|
136 | + 'ThisFoundInStatic' |
|
137 | + ); |
|
138 | + } |
|
139 | + |
|
140 | + /* |
|
141 | 141 | * Closures only have access to $this if used within a class context. |
142 | 142 | */ |
143 | - elseif ($this->inClassScope($phpcsFile, $stackPtr, false) === false) { |
|
144 | - $phpcsFile->addWarning( |
|
145 | - 'Closures / anonymous functions only have access to $this if used within a class or when bound to an object using bindTo(). Please verify.', |
|
146 | - $thisFound, |
|
147 | - 'ThisFoundOutsideClass' |
|
148 | - ); |
|
149 | - } |
|
150 | - |
|
151 | - $thisFound = $this->findThisUsageInClosure($phpcsFile, ($thisFound + 1), $scopeEnd); |
|
152 | - |
|
153 | - } while ($thisFound !== false); |
|
154 | - } |
|
155 | - |
|
156 | - // Prevent double reporting for nested closures. |
|
157 | - return $scopeEnd; |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * Check whether the closure is declared as static. |
|
163 | - * |
|
164 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
165 | - * @param int $stackPtr The position of the current token |
|
166 | - * in the stack passed in $tokens. |
|
167 | - * |
|
168 | - * @return bool |
|
169 | - */ |
|
170 | - protected function isClosureStatic(File $phpcsFile, $stackPtr) |
|
171 | - { |
|
172 | - $tokens = $phpcsFile->getTokens(); |
|
173 | - $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true, null, true); |
|
174 | - |
|
175 | - return ($prevToken !== false && $tokens[$prevToken]['code'] === \T_STATIC); |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * Check if the code within a closure uses the $this variable. |
|
181 | - * |
|
182 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
183 | - * @param int $startToken The position within the closure to continue searching from. |
|
184 | - * @param int $endToken The closure scope closer to stop searching at. |
|
185 | - * |
|
186 | - * @return int|false The stackPtr to the first $this usage if found or false if |
|
187 | - * $this is not used. |
|
188 | - */ |
|
189 | - protected function findThisUsageInClosure(File $phpcsFile, $startToken, $endToken) |
|
190 | - { |
|
191 | - // Make sure the $startToken is valid. |
|
192 | - if ($startToken >= $endToken) { |
|
193 | - return false; |
|
194 | - } |
|
195 | - |
|
196 | - return $phpcsFile->findNext( |
|
197 | - \T_VARIABLE, |
|
198 | - $startToken, |
|
199 | - $endToken, |
|
200 | - false, |
|
201 | - '$this' |
|
202 | - ); |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * Check if the code within a closure uses "self/parent/static". |
|
207 | - * |
|
208 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
209 | - * @param int $startToken The position within the closure to continue searching from. |
|
210 | - * @param int $endToken The closure scope closer to stop searching at. |
|
211 | - * |
|
212 | - * @return int|false The stackPtr to the first classRef usage if found or false if |
|
213 | - * they are not used. |
|
214 | - */ |
|
215 | - protected function findClassRefUsageInClosure(File $phpcsFile, $startToken, $endToken) |
|
216 | - { |
|
217 | - // Make sure the $startToken is valid. |
|
218 | - if ($startToken >= $endToken) { |
|
219 | - return false; |
|
220 | - } |
|
221 | - |
|
222 | - $tokens = $phpcsFile->getTokens(); |
|
223 | - $classRef = $phpcsFile->findNext(array(\T_SELF, \T_PARENT, \T_STATIC), $startToken, $endToken); |
|
224 | - |
|
225 | - if ($classRef === false || $tokens[$classRef]['code'] !== \T_STATIC) { |
|
226 | - return $classRef; |
|
227 | - } |
|
228 | - |
|
229 | - // T_STATIC, make sure it is used as a class reference. |
|
230 | - $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($classRef + 1), $endToken, true); |
|
231 | - if ($next === false || $tokens[$next]['code'] !== \T_DOUBLE_COLON) { |
|
232 | - return false; |
|
233 | - } |
|
234 | - |
|
235 | - return $classRef; |
|
236 | - } |
|
143 | + elseif ($this->inClassScope($phpcsFile, $stackPtr, false) === false) { |
|
144 | + $phpcsFile->addWarning( |
|
145 | + 'Closures / anonymous functions only have access to $this if used within a class or when bound to an object using bindTo(). Please verify.', |
|
146 | + $thisFound, |
|
147 | + 'ThisFoundOutsideClass' |
|
148 | + ); |
|
149 | + } |
|
150 | + |
|
151 | + $thisFound = $this->findThisUsageInClosure($phpcsFile, ($thisFound + 1), $scopeEnd); |
|
152 | + |
|
153 | + } while ($thisFound !== false); |
|
154 | + } |
|
155 | + |
|
156 | + // Prevent double reporting for nested closures. |
|
157 | + return $scopeEnd; |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * Check whether the closure is declared as static. |
|
163 | + * |
|
164 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
165 | + * @param int $stackPtr The position of the current token |
|
166 | + * in the stack passed in $tokens. |
|
167 | + * |
|
168 | + * @return bool |
|
169 | + */ |
|
170 | + protected function isClosureStatic(File $phpcsFile, $stackPtr) |
|
171 | + { |
|
172 | + $tokens = $phpcsFile->getTokens(); |
|
173 | + $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true, null, true); |
|
174 | + |
|
175 | + return ($prevToken !== false && $tokens[$prevToken]['code'] === \T_STATIC); |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * Check if the code within a closure uses the $this variable. |
|
181 | + * |
|
182 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
183 | + * @param int $startToken The position within the closure to continue searching from. |
|
184 | + * @param int $endToken The closure scope closer to stop searching at. |
|
185 | + * |
|
186 | + * @return int|false The stackPtr to the first $this usage if found or false if |
|
187 | + * $this is not used. |
|
188 | + */ |
|
189 | + protected function findThisUsageInClosure(File $phpcsFile, $startToken, $endToken) |
|
190 | + { |
|
191 | + // Make sure the $startToken is valid. |
|
192 | + if ($startToken >= $endToken) { |
|
193 | + return false; |
|
194 | + } |
|
195 | + |
|
196 | + return $phpcsFile->findNext( |
|
197 | + \T_VARIABLE, |
|
198 | + $startToken, |
|
199 | + $endToken, |
|
200 | + false, |
|
201 | + '$this' |
|
202 | + ); |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * Check if the code within a closure uses "self/parent/static". |
|
207 | + * |
|
208 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
209 | + * @param int $startToken The position within the closure to continue searching from. |
|
210 | + * @param int $endToken The closure scope closer to stop searching at. |
|
211 | + * |
|
212 | + * @return int|false The stackPtr to the first classRef usage if found or false if |
|
213 | + * they are not used. |
|
214 | + */ |
|
215 | + protected function findClassRefUsageInClosure(File $phpcsFile, $startToken, $endToken) |
|
216 | + { |
|
217 | + // Make sure the $startToken is valid. |
|
218 | + if ($startToken >= $endToken) { |
|
219 | + return false; |
|
220 | + } |
|
221 | + |
|
222 | + $tokens = $phpcsFile->getTokens(); |
|
223 | + $classRef = $phpcsFile->findNext(array(\T_SELF, \T_PARENT, \T_STATIC), $startToken, $endToken); |
|
224 | + |
|
225 | + if ($classRef === false || $tokens[$classRef]['code'] !== \T_STATIC) { |
|
226 | + return $classRef; |
|
227 | + } |
|
228 | + |
|
229 | + // T_STATIC, make sure it is used as a class reference. |
|
230 | + $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($classRef + 1), $endToken, true); |
|
231 | + if ($next === false || $tokens[$next]['code'] !== \T_DOUBLE_COLON) { |
|
232 | + return false; |
|
233 | + } |
|
234 | + |
|
235 | + return $classRef; |
|
236 | + } |
|
237 | 237 | } |
@@ -29,134 +29,134 @@ |
||
29 | 29 | */ |
30 | 30 | class NewNullableTypesSniff extends Sniff |
31 | 31 | { |
32 | - /** |
|
33 | - * Returns an array of tokens this test wants to listen for. |
|
34 | - * |
|
35 | - * {@internal Not sniffing for T_NULLABLE which was introduced in PHPCS 2.7.2 |
|
36 | - * as in that case we can't distinguish between parameter type hints and |
|
37 | - * return type hints for the error message.}} |
|
38 | - * |
|
39 | - * @return array |
|
40 | - */ |
|
41 | - public function register() |
|
42 | - { |
|
43 | - $tokens = array( |
|
44 | - \T_FUNCTION, |
|
45 | - \T_CLOSURE, |
|
46 | - ); |
|
47 | - |
|
48 | - if (\defined('T_RETURN_TYPE')) { |
|
49 | - $tokens[] = \T_RETURN_TYPE; |
|
50 | - } |
|
51 | - |
|
52 | - return $tokens; |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * Processes this test, when one of its tokens is encountered. |
|
58 | - * |
|
59 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
60 | - * @param int $stackPtr The position of the current token |
|
61 | - * in the stack passed in $tokens. |
|
62 | - * |
|
63 | - * @return void |
|
64 | - */ |
|
65 | - public function process(File $phpcsFile, $stackPtr) |
|
66 | - { |
|
67 | - if ($this->supportsBelow('7.0') === false) { |
|
68 | - return; |
|
69 | - } |
|
70 | - |
|
71 | - $tokens = $phpcsFile->getTokens(); |
|
72 | - $tokenCode = $tokens[$stackPtr]['code']; |
|
73 | - |
|
74 | - if ($tokenCode === \T_FUNCTION || $tokenCode === \T_CLOSURE) { |
|
75 | - $this->processFunctionDeclaration($phpcsFile, $stackPtr); |
|
76 | - |
|
77 | - // Deal with older PHPCS version which don't recognize return type hints |
|
78 | - // as well as newer PHPCS versions (3.3.0+) where the tokenization has changed. |
|
79 | - $returnTypeHint = $this->getReturnTypeHintToken($phpcsFile, $stackPtr); |
|
80 | - if ($returnTypeHint !== false) { |
|
81 | - $this->processReturnType($phpcsFile, $returnTypeHint); |
|
82 | - } |
|
83 | - } else { |
|
84 | - $this->processReturnType($phpcsFile, $stackPtr); |
|
85 | - } |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * Process this test for function tokens. |
|
91 | - * |
|
92 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
93 | - * @param int $stackPtr The position of the current token |
|
94 | - * in the stack passed in $tokens. |
|
95 | - * |
|
96 | - * @return void |
|
97 | - */ |
|
98 | - protected function processFunctionDeclaration(File $phpcsFile, $stackPtr) |
|
99 | - { |
|
100 | - $params = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr); |
|
101 | - |
|
102 | - if (empty($params) === false && \is_array($params)) { |
|
103 | - foreach ($params as $param) { |
|
104 | - if ($param['nullable_type'] === true) { |
|
105 | - $phpcsFile->addError( |
|
106 | - 'Nullable type declarations are not supported in PHP 7.0 or earlier. Found: %s', |
|
107 | - $param['token'], |
|
108 | - 'typeDeclarationFound', |
|
109 | - array($param['type_hint']) |
|
110 | - ); |
|
111 | - } |
|
112 | - } |
|
113 | - } |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * Process this test for return type tokens. |
|
119 | - * |
|
120 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
121 | - * @param int $stackPtr The position of the current token |
|
122 | - * in the stack passed in $tokens. |
|
123 | - * |
|
124 | - * @return void |
|
125 | - */ |
|
126 | - protected function processReturnType(File $phpcsFile, $stackPtr) |
|
127 | - { |
|
128 | - $tokens = $phpcsFile->getTokens(); |
|
129 | - |
|
130 | - if (isset($tokens[($stackPtr - 1)]['code']) === false) { |
|
131 | - return; |
|
132 | - } |
|
133 | - |
|
134 | - $previous = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
|
135 | - |
|
136 | - // Deal with namespaced class names. |
|
137 | - if ($tokens[$previous]['code'] === \T_NS_SEPARATOR) { |
|
138 | - $validTokens = Tokens::$emptyTokens; |
|
139 | - $validTokens[\T_STRING] = true; |
|
140 | - $validTokens[\T_NS_SEPARATOR] = true; |
|
141 | - |
|
142 | - $stackPtr--; |
|
143 | - |
|
144 | - while (isset($validTokens[$tokens[($stackPtr - 1)]['code']]) === true) { |
|
145 | - $stackPtr--; |
|
146 | - } |
|
147 | - |
|
148 | - $previous = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
|
149 | - } |
|
150 | - |
|
151 | - // T_NULLABLE token was introduced in PHPCS 2.7.2. Before that it identified as T_INLINE_THEN. |
|
152 | - if ((\defined('T_NULLABLE') === true && $tokens[$previous]['type'] === 'T_NULLABLE') |
|
153 | - || (\defined('T_NULLABLE') === false && $tokens[$previous]['code'] === \T_INLINE_THEN) |
|
154 | - ) { |
|
155 | - $phpcsFile->addError( |
|
156 | - 'Nullable return types are not supported in PHP 7.0 or earlier.', |
|
157 | - $stackPtr, |
|
158 | - 'returnTypeFound' |
|
159 | - ); |
|
160 | - } |
|
161 | - } |
|
32 | + /** |
|
33 | + * Returns an array of tokens this test wants to listen for. |
|
34 | + * |
|
35 | + * {@internal Not sniffing for T_NULLABLE which was introduced in PHPCS 2.7.2 |
|
36 | + * as in that case we can't distinguish between parameter type hints and |
|
37 | + * return type hints for the error message.}} |
|
38 | + * |
|
39 | + * @return array |
|
40 | + */ |
|
41 | + public function register() |
|
42 | + { |
|
43 | + $tokens = array( |
|
44 | + \T_FUNCTION, |
|
45 | + \T_CLOSURE, |
|
46 | + ); |
|
47 | + |
|
48 | + if (\defined('T_RETURN_TYPE')) { |
|
49 | + $tokens[] = \T_RETURN_TYPE; |
|
50 | + } |
|
51 | + |
|
52 | + return $tokens; |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * Processes this test, when one of its tokens is encountered. |
|
58 | + * |
|
59 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
60 | + * @param int $stackPtr The position of the current token |
|
61 | + * in the stack passed in $tokens. |
|
62 | + * |
|
63 | + * @return void |
|
64 | + */ |
|
65 | + public function process(File $phpcsFile, $stackPtr) |
|
66 | + { |
|
67 | + if ($this->supportsBelow('7.0') === false) { |
|
68 | + return; |
|
69 | + } |
|
70 | + |
|
71 | + $tokens = $phpcsFile->getTokens(); |
|
72 | + $tokenCode = $tokens[$stackPtr]['code']; |
|
73 | + |
|
74 | + if ($tokenCode === \T_FUNCTION || $tokenCode === \T_CLOSURE) { |
|
75 | + $this->processFunctionDeclaration($phpcsFile, $stackPtr); |
|
76 | + |
|
77 | + // Deal with older PHPCS version which don't recognize return type hints |
|
78 | + // as well as newer PHPCS versions (3.3.0+) where the tokenization has changed. |
|
79 | + $returnTypeHint = $this->getReturnTypeHintToken($phpcsFile, $stackPtr); |
|
80 | + if ($returnTypeHint !== false) { |
|
81 | + $this->processReturnType($phpcsFile, $returnTypeHint); |
|
82 | + } |
|
83 | + } else { |
|
84 | + $this->processReturnType($phpcsFile, $stackPtr); |
|
85 | + } |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * Process this test for function tokens. |
|
91 | + * |
|
92 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
93 | + * @param int $stackPtr The position of the current token |
|
94 | + * in the stack passed in $tokens. |
|
95 | + * |
|
96 | + * @return void |
|
97 | + */ |
|
98 | + protected function processFunctionDeclaration(File $phpcsFile, $stackPtr) |
|
99 | + { |
|
100 | + $params = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr); |
|
101 | + |
|
102 | + if (empty($params) === false && \is_array($params)) { |
|
103 | + foreach ($params as $param) { |
|
104 | + if ($param['nullable_type'] === true) { |
|
105 | + $phpcsFile->addError( |
|
106 | + 'Nullable type declarations are not supported in PHP 7.0 or earlier. Found: %s', |
|
107 | + $param['token'], |
|
108 | + 'typeDeclarationFound', |
|
109 | + array($param['type_hint']) |
|
110 | + ); |
|
111 | + } |
|
112 | + } |
|
113 | + } |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * Process this test for return type tokens. |
|
119 | + * |
|
120 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
121 | + * @param int $stackPtr The position of the current token |
|
122 | + * in the stack passed in $tokens. |
|
123 | + * |
|
124 | + * @return void |
|
125 | + */ |
|
126 | + protected function processReturnType(File $phpcsFile, $stackPtr) |
|
127 | + { |
|
128 | + $tokens = $phpcsFile->getTokens(); |
|
129 | + |
|
130 | + if (isset($tokens[($stackPtr - 1)]['code']) === false) { |
|
131 | + return; |
|
132 | + } |
|
133 | + |
|
134 | + $previous = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
|
135 | + |
|
136 | + // Deal with namespaced class names. |
|
137 | + if ($tokens[$previous]['code'] === \T_NS_SEPARATOR) { |
|
138 | + $validTokens = Tokens::$emptyTokens; |
|
139 | + $validTokens[\T_STRING] = true; |
|
140 | + $validTokens[\T_NS_SEPARATOR] = true; |
|
141 | + |
|
142 | + $stackPtr--; |
|
143 | + |
|
144 | + while (isset($validTokens[$tokens[($stackPtr - 1)]['code']]) === true) { |
|
145 | + $stackPtr--; |
|
146 | + } |
|
147 | + |
|
148 | + $previous = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
|
149 | + } |
|
150 | + |
|
151 | + // T_NULLABLE token was introduced in PHPCS 2.7.2. Before that it identified as T_INLINE_THEN. |
|
152 | + if ((\defined('T_NULLABLE') === true && $tokens[$previous]['type'] === 'T_NULLABLE') |
|
153 | + || (\defined('T_NULLABLE') === false && $tokens[$previous]['code'] === \T_INLINE_THEN) |
|
154 | + ) { |
|
155 | + $phpcsFile->addError( |
|
156 | + 'Nullable return types are not supported in PHP 7.0 or earlier.', |
|
157 | + $stackPtr, |
|
158 | + 'returnTypeFound' |
|
159 | + ); |
|
160 | + } |
|
161 | + } |
|
162 | 162 | } |
@@ -28,151 +28,151 @@ |
||
28 | 28 | class NonStaticMagicMethodsSniff extends Sniff |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * A list of PHP magic methods and their visibility and static requirements. |
|
33 | - * |
|
34 | - * Method names in the array should be all *lowercase*. |
|
35 | - * Visibility can be either 'public', 'protected' or 'private'. |
|
36 | - * Static can be either 'true' - *must* be static, or 'false' - *must* be non-static. |
|
37 | - * When a method does not have a specific requirement for either visibility or static, |
|
38 | - * do *not* add the key. |
|
39 | - * |
|
40 | - * @var array(string) |
|
41 | - */ |
|
42 | - protected $magicMethods = array( |
|
43 | - '__get' => array( |
|
44 | - 'visibility' => 'public', |
|
45 | - 'static' => false, |
|
46 | - ), |
|
47 | - '__set' => array( |
|
48 | - 'visibility' => 'public', |
|
49 | - 'static' => false, |
|
50 | - ), |
|
51 | - '__isset' => array( |
|
52 | - 'visibility' => 'public', |
|
53 | - 'static' => false, |
|
54 | - ), |
|
55 | - '__unset' => array( |
|
56 | - 'visibility' => 'public', |
|
57 | - 'static' => false, |
|
58 | - ), |
|
59 | - '__call' => array( |
|
60 | - 'visibility' => 'public', |
|
61 | - 'static' => false, |
|
62 | - ), |
|
63 | - '__callstatic' => array( |
|
64 | - 'visibility' => 'public', |
|
65 | - 'static' => true, |
|
66 | - ), |
|
67 | - '__sleep' => array( |
|
68 | - 'visibility' => 'public', |
|
69 | - ), |
|
70 | - '__tostring' => array( |
|
71 | - 'visibility' => 'public', |
|
72 | - ), |
|
73 | - '__set_state' => array( |
|
74 | - 'static' => true, |
|
75 | - ), |
|
76 | - ); |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * Returns an array of tokens this test wants to listen for. |
|
81 | - * |
|
82 | - * @return array |
|
83 | - */ |
|
84 | - public function register() |
|
85 | - { |
|
86 | - $targets = array( |
|
87 | - \T_CLASS, |
|
88 | - \T_INTERFACE, |
|
89 | - \T_TRAIT, |
|
90 | - ); |
|
91 | - |
|
92 | - if (\defined('T_ANON_CLASS')) { |
|
93 | - $targets[] = \T_ANON_CLASS; |
|
94 | - } |
|
95 | - |
|
96 | - return $targets; |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * Processes this test, when one of its tokens is encountered. |
|
102 | - * |
|
103 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
104 | - * @param int $stackPtr The position of the current token in the |
|
105 | - * stack passed in $tokens. |
|
106 | - * |
|
107 | - * @return void |
|
108 | - */ |
|
109 | - public function process(File $phpcsFile, $stackPtr) |
|
110 | - { |
|
111 | - // Should be removed, the requirement was previously also there, 5.3 just started throwing a warning about it. |
|
112 | - if ($this->supportsAbove('5.3') === false) { |
|
113 | - return; |
|
114 | - } |
|
115 | - |
|
116 | - $tokens = $phpcsFile->getTokens(); |
|
117 | - |
|
118 | - if (isset($tokens[$stackPtr]['scope_closer']) === false) { |
|
119 | - return; |
|
120 | - } |
|
121 | - |
|
122 | - $classScopeCloser = $tokens[$stackPtr]['scope_closer']; |
|
123 | - $functionPtr = $stackPtr; |
|
124 | - |
|
125 | - // Find all the functions in this class or interface. |
|
126 | - while (($functionToken = $phpcsFile->findNext(\T_FUNCTION, $functionPtr, $classScopeCloser)) !== false) { |
|
127 | - /* |
|
31 | + /** |
|
32 | + * A list of PHP magic methods and their visibility and static requirements. |
|
33 | + * |
|
34 | + * Method names in the array should be all *lowercase*. |
|
35 | + * Visibility can be either 'public', 'protected' or 'private'. |
|
36 | + * Static can be either 'true' - *must* be static, or 'false' - *must* be non-static. |
|
37 | + * When a method does not have a specific requirement for either visibility or static, |
|
38 | + * do *not* add the key. |
|
39 | + * |
|
40 | + * @var array(string) |
|
41 | + */ |
|
42 | + protected $magicMethods = array( |
|
43 | + '__get' => array( |
|
44 | + 'visibility' => 'public', |
|
45 | + 'static' => false, |
|
46 | + ), |
|
47 | + '__set' => array( |
|
48 | + 'visibility' => 'public', |
|
49 | + 'static' => false, |
|
50 | + ), |
|
51 | + '__isset' => array( |
|
52 | + 'visibility' => 'public', |
|
53 | + 'static' => false, |
|
54 | + ), |
|
55 | + '__unset' => array( |
|
56 | + 'visibility' => 'public', |
|
57 | + 'static' => false, |
|
58 | + ), |
|
59 | + '__call' => array( |
|
60 | + 'visibility' => 'public', |
|
61 | + 'static' => false, |
|
62 | + ), |
|
63 | + '__callstatic' => array( |
|
64 | + 'visibility' => 'public', |
|
65 | + 'static' => true, |
|
66 | + ), |
|
67 | + '__sleep' => array( |
|
68 | + 'visibility' => 'public', |
|
69 | + ), |
|
70 | + '__tostring' => array( |
|
71 | + 'visibility' => 'public', |
|
72 | + ), |
|
73 | + '__set_state' => array( |
|
74 | + 'static' => true, |
|
75 | + ), |
|
76 | + ); |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * Returns an array of tokens this test wants to listen for. |
|
81 | + * |
|
82 | + * @return array |
|
83 | + */ |
|
84 | + public function register() |
|
85 | + { |
|
86 | + $targets = array( |
|
87 | + \T_CLASS, |
|
88 | + \T_INTERFACE, |
|
89 | + \T_TRAIT, |
|
90 | + ); |
|
91 | + |
|
92 | + if (\defined('T_ANON_CLASS')) { |
|
93 | + $targets[] = \T_ANON_CLASS; |
|
94 | + } |
|
95 | + |
|
96 | + return $targets; |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * Processes this test, when one of its tokens is encountered. |
|
102 | + * |
|
103 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
104 | + * @param int $stackPtr The position of the current token in the |
|
105 | + * stack passed in $tokens. |
|
106 | + * |
|
107 | + * @return void |
|
108 | + */ |
|
109 | + public function process(File $phpcsFile, $stackPtr) |
|
110 | + { |
|
111 | + // Should be removed, the requirement was previously also there, 5.3 just started throwing a warning about it. |
|
112 | + if ($this->supportsAbove('5.3') === false) { |
|
113 | + return; |
|
114 | + } |
|
115 | + |
|
116 | + $tokens = $phpcsFile->getTokens(); |
|
117 | + |
|
118 | + if (isset($tokens[$stackPtr]['scope_closer']) === false) { |
|
119 | + return; |
|
120 | + } |
|
121 | + |
|
122 | + $classScopeCloser = $tokens[$stackPtr]['scope_closer']; |
|
123 | + $functionPtr = $stackPtr; |
|
124 | + |
|
125 | + // Find all the functions in this class or interface. |
|
126 | + while (($functionToken = $phpcsFile->findNext(\T_FUNCTION, $functionPtr, $classScopeCloser)) !== false) { |
|
127 | + /* |
|
128 | 128 | * Get the scope closer for this function in order to know how |
129 | 129 | * to advance to the next function. |
130 | 130 | * If no body of function (e.g. for interfaces), there is |
131 | 131 | * no closing curly brace; advance the pointer differently. |
132 | 132 | */ |
133 | - if (isset($tokens[$functionToken]['scope_closer'])) { |
|
134 | - $scopeCloser = $tokens[$functionToken]['scope_closer']; |
|
135 | - } else { |
|
136 | - $scopeCloser = ($functionToken + 1); |
|
137 | - } |
|
138 | - |
|
139 | - $methodName = $phpcsFile->getDeclarationName($functionToken); |
|
140 | - $methodNameLc = strtolower($methodName); |
|
141 | - if (isset($this->magicMethods[$methodNameLc]) === false) { |
|
142 | - $functionPtr = $scopeCloser; |
|
143 | - continue; |
|
144 | - } |
|
145 | - |
|
146 | - $methodProperties = $phpcsFile->getMethodProperties($functionToken); |
|
147 | - $errorCodeBase = $this->stringToErrorCode($methodNameLc); |
|
148 | - |
|
149 | - if (isset($this->magicMethods[$methodNameLc]['visibility']) && $this->magicMethods[$methodNameLc]['visibility'] !== $methodProperties['scope']) { |
|
150 | - $error = 'Visibility for magic method %s must be %s. Found: %s'; |
|
151 | - $errorCode = $errorCodeBase . 'MethodVisibility'; |
|
152 | - $data = array( |
|
153 | - $methodName, |
|
154 | - $this->magicMethods[$methodNameLc]['visibility'], |
|
155 | - $methodProperties['scope'], |
|
156 | - ); |
|
157 | - |
|
158 | - $phpcsFile->addError($error, $functionToken, $errorCode, $data); |
|
159 | - } |
|
160 | - |
|
161 | - if (isset($this->magicMethods[$methodNameLc]['static']) && $this->magicMethods[$methodNameLc]['static'] !== $methodProperties['is_static']) { |
|
162 | - $error = 'Magic method %s cannot be defined as static.'; |
|
163 | - $errorCode = $errorCodeBase . 'MethodStatic'; |
|
164 | - $data = array($methodName); |
|
165 | - |
|
166 | - if ($this->magicMethods[$methodNameLc]['static'] === true) { |
|
167 | - $error = 'Magic method %s must be defined as static.'; |
|
168 | - $errorCode = $errorCodeBase . 'MethodNonStatic'; |
|
169 | - } |
|
170 | - |
|
171 | - $phpcsFile->addError($error, $functionToken, $errorCode, $data); |
|
172 | - } |
|
173 | - |
|
174 | - // Advance to next function. |
|
175 | - $functionPtr = $scopeCloser; |
|
176 | - } |
|
177 | - } |
|
133 | + if (isset($tokens[$functionToken]['scope_closer'])) { |
|
134 | + $scopeCloser = $tokens[$functionToken]['scope_closer']; |
|
135 | + } else { |
|
136 | + $scopeCloser = ($functionToken + 1); |
|
137 | + } |
|
138 | + |
|
139 | + $methodName = $phpcsFile->getDeclarationName($functionToken); |
|
140 | + $methodNameLc = strtolower($methodName); |
|
141 | + if (isset($this->magicMethods[$methodNameLc]) === false) { |
|
142 | + $functionPtr = $scopeCloser; |
|
143 | + continue; |
|
144 | + } |
|
145 | + |
|
146 | + $methodProperties = $phpcsFile->getMethodProperties($functionToken); |
|
147 | + $errorCodeBase = $this->stringToErrorCode($methodNameLc); |
|
148 | + |
|
149 | + if (isset($this->magicMethods[$methodNameLc]['visibility']) && $this->magicMethods[$methodNameLc]['visibility'] !== $methodProperties['scope']) { |
|
150 | + $error = 'Visibility for magic method %s must be %s. Found: %s'; |
|
151 | + $errorCode = $errorCodeBase . 'MethodVisibility'; |
|
152 | + $data = array( |
|
153 | + $methodName, |
|
154 | + $this->magicMethods[$methodNameLc]['visibility'], |
|
155 | + $methodProperties['scope'], |
|
156 | + ); |
|
157 | + |
|
158 | + $phpcsFile->addError($error, $functionToken, $errorCode, $data); |
|
159 | + } |
|
160 | + |
|
161 | + if (isset($this->magicMethods[$methodNameLc]['static']) && $this->magicMethods[$methodNameLc]['static'] !== $methodProperties['is_static']) { |
|
162 | + $error = 'Magic method %s cannot be defined as static.'; |
|
163 | + $errorCode = $errorCodeBase . 'MethodStatic'; |
|
164 | + $data = array($methodName); |
|
165 | + |
|
166 | + if ($this->magicMethods[$methodNameLc]['static'] === true) { |
|
167 | + $error = 'Magic method %s must be defined as static.'; |
|
168 | + $errorCode = $errorCodeBase . 'MethodNonStatic'; |
|
169 | + } |
|
170 | + |
|
171 | + $phpcsFile->addError($error, $functionToken, $errorCode, $data); |
|
172 | + } |
|
173 | + |
|
174 | + // Advance to next function. |
|
175 | + $functionPtr = $scopeCloser; |
|
176 | + } |
|
177 | + } |
|
178 | 178 | } |
@@ -26,292 +26,292 @@ |
||
26 | 26 | */ |
27 | 27 | class RemovedExtensionsSniff extends AbstractRemovedFeatureSniff |
28 | 28 | { |
29 | - /** |
|
30 | - * A list of functions to whitelist, if any. |
|
31 | - * |
|
32 | - * This is intended for projects using functions which start with the same |
|
33 | - * prefix as one of the removed extensions. |
|
34 | - * |
|
35 | - * This property can be set from the ruleset, like so: |
|
36 | - * <rule ref="PHPCompatibility.Extensions.RemovedExtensions"> |
|
37 | - * <properties> |
|
38 | - * <property name="functionWhitelist" type="array" value="mysql_to_rfc3339,mysql_another_function" /> |
|
39 | - * </properties> |
|
40 | - * </rule> |
|
41 | - * |
|
42 | - * @var array |
|
43 | - */ |
|
44 | - public $functionWhitelist; |
|
29 | + /** |
|
30 | + * A list of functions to whitelist, if any. |
|
31 | + * |
|
32 | + * This is intended for projects using functions which start with the same |
|
33 | + * prefix as one of the removed extensions. |
|
34 | + * |
|
35 | + * This property can be set from the ruleset, like so: |
|
36 | + * <rule ref="PHPCompatibility.Extensions.RemovedExtensions"> |
|
37 | + * <properties> |
|
38 | + * <property name="functionWhitelist" type="array" value="mysql_to_rfc3339,mysql_another_function" /> |
|
39 | + * </properties> |
|
40 | + * </rule> |
|
41 | + * |
|
42 | + * @var array |
|
43 | + */ |
|
44 | + public $functionWhitelist; |
|
45 | 45 | |
46 | - /** |
|
47 | - * A list of removed extensions with their alternative, if any |
|
48 | - * |
|
49 | - * The array lists : version number with false (deprecated) and true (removed). |
|
50 | - * If's sufficient to list the first version where the extension was deprecated/removed. |
|
51 | - * |
|
52 | - * @var array(string|null) |
|
53 | - */ |
|
54 | - protected $removedExtensions = array( |
|
55 | - 'activescript' => array( |
|
56 | - '5.1' => true, |
|
57 | - 'alternative' => 'pecl/activescript', |
|
58 | - ), |
|
59 | - 'cpdf' => array( |
|
60 | - '5.1' => true, |
|
61 | - 'alternative' => 'pecl/pdflib', |
|
62 | - ), |
|
63 | - 'dbase' => array( |
|
64 | - '5.3' => true, |
|
65 | - 'alternative' => null, |
|
66 | - ), |
|
67 | - 'dbx' => array( |
|
68 | - '5.1' => true, |
|
69 | - 'alternative' => 'pecl/dbx', |
|
70 | - ), |
|
71 | - 'dio' => array( |
|
72 | - '5.1' => true, |
|
73 | - 'alternative' => 'pecl/dio', |
|
74 | - ), |
|
75 | - 'ereg' => array( |
|
76 | - '5.3' => false, |
|
77 | - '7.0' => true, |
|
78 | - 'alternative' => 'pcre', |
|
79 | - ), |
|
80 | - 'fam' => array( |
|
81 | - '5.1' => true, |
|
82 | - 'alternative' => null, |
|
83 | - ), |
|
84 | - 'fbsql' => array( |
|
85 | - '5.3' => true, |
|
86 | - 'alternative' => null, |
|
87 | - ), |
|
88 | - 'fdf' => array( |
|
89 | - '5.3' => true, |
|
90 | - 'alternative' => 'pecl/fdf', |
|
91 | - ), |
|
92 | - 'filepro' => array( |
|
93 | - '5.2' => true, |
|
94 | - 'alternative' => null, |
|
95 | - ), |
|
96 | - 'hw_api' => array( |
|
97 | - '5.2' => true, |
|
98 | - 'alternative' => null, |
|
99 | - ), |
|
100 | - 'ibase' => array( |
|
101 | - '7.4' => true, |
|
102 | - 'alternative' => 'pecl/ibase', |
|
103 | - ), |
|
104 | - 'ingres' => array( |
|
105 | - '5.1' => true, |
|
106 | - 'alternative' => 'pecl/ingres', |
|
107 | - ), |
|
108 | - 'ircg' => array( |
|
109 | - '5.1' => true, |
|
110 | - 'alternative' => null, |
|
111 | - ), |
|
112 | - 'mcrypt' => array( |
|
113 | - '7.1' => false, |
|
114 | - '7.2' => true, |
|
115 | - 'alternative' => 'openssl (preferred) or pecl/mcrypt once available', |
|
116 | - ), |
|
117 | - 'mcve' => array( |
|
118 | - '5.1' => true, |
|
119 | - 'alternative' => 'pecl/mcve', |
|
120 | - ), |
|
121 | - 'ming' => array( |
|
122 | - '5.3' => true, |
|
123 | - 'alternative' => 'pecl/ming', |
|
124 | - ), |
|
125 | - 'mnogosearch' => array( |
|
126 | - '5.1' => true, |
|
127 | - 'alternative' => null, |
|
128 | - ), |
|
129 | - 'msql' => array( |
|
130 | - '5.3' => true, |
|
131 | - 'alternative' => null, |
|
132 | - ), |
|
133 | - 'mssql' => array( |
|
134 | - '7.0' => true, |
|
135 | - 'alternative' => null, |
|
136 | - ), |
|
137 | - 'mysql_' => array( |
|
138 | - '5.5' => false, |
|
139 | - '7.0' => true, |
|
140 | - 'alternative' => 'mysqli', |
|
141 | - ), |
|
142 | - 'ncurses' => array( |
|
143 | - '5.3' => true, |
|
144 | - 'alternative' => 'pecl/ncurses', |
|
145 | - ), |
|
146 | - 'oracle' => array( |
|
147 | - '5.1' => true, |
|
148 | - 'alternative' => 'oci8 or pdo_oci', |
|
149 | - ), |
|
150 | - 'ovrimos' => array( |
|
151 | - '5.1' => true, |
|
152 | - 'alternative' => null, |
|
153 | - ), |
|
154 | - 'pfpro_' => array( |
|
155 | - '5.1' => true, |
|
156 | - 'alternative' => null, |
|
157 | - ), |
|
158 | - 'sqlite' => array( |
|
159 | - '5.4' => true, |
|
160 | - 'alternative' => null, |
|
161 | - ), |
|
162 | - // Has to be before `sybase` as otherwise it will never match. |
|
163 | - 'sybase_ct' => array( |
|
164 | - '7.0' => true, |
|
165 | - 'alternative' => null, |
|
166 | - ), |
|
167 | - 'sybase' => array( |
|
168 | - '5.3' => true, |
|
169 | - 'alternative' => 'sybase_ct', |
|
170 | - ), |
|
171 | - 'w32api' => array( |
|
172 | - '5.1' => true, |
|
173 | - 'alternative' => 'pecl/ffi', |
|
174 | - ), |
|
175 | - 'wddx' => array( |
|
176 | - '7.4' => true, |
|
177 | - 'alternative' => 'pecl/wddx', |
|
178 | - ), |
|
179 | - 'yp' => array( |
|
180 | - '5.1' => true, |
|
181 | - 'alternative' => null, |
|
182 | - ), |
|
183 | - ); |
|
46 | + /** |
|
47 | + * A list of removed extensions with their alternative, if any |
|
48 | + * |
|
49 | + * The array lists : version number with false (deprecated) and true (removed). |
|
50 | + * If's sufficient to list the first version where the extension was deprecated/removed. |
|
51 | + * |
|
52 | + * @var array(string|null) |
|
53 | + */ |
|
54 | + protected $removedExtensions = array( |
|
55 | + 'activescript' => array( |
|
56 | + '5.1' => true, |
|
57 | + 'alternative' => 'pecl/activescript', |
|
58 | + ), |
|
59 | + 'cpdf' => array( |
|
60 | + '5.1' => true, |
|
61 | + 'alternative' => 'pecl/pdflib', |
|
62 | + ), |
|
63 | + 'dbase' => array( |
|
64 | + '5.3' => true, |
|
65 | + 'alternative' => null, |
|
66 | + ), |
|
67 | + 'dbx' => array( |
|
68 | + '5.1' => true, |
|
69 | + 'alternative' => 'pecl/dbx', |
|
70 | + ), |
|
71 | + 'dio' => array( |
|
72 | + '5.1' => true, |
|
73 | + 'alternative' => 'pecl/dio', |
|
74 | + ), |
|
75 | + 'ereg' => array( |
|
76 | + '5.3' => false, |
|
77 | + '7.0' => true, |
|
78 | + 'alternative' => 'pcre', |
|
79 | + ), |
|
80 | + 'fam' => array( |
|
81 | + '5.1' => true, |
|
82 | + 'alternative' => null, |
|
83 | + ), |
|
84 | + 'fbsql' => array( |
|
85 | + '5.3' => true, |
|
86 | + 'alternative' => null, |
|
87 | + ), |
|
88 | + 'fdf' => array( |
|
89 | + '5.3' => true, |
|
90 | + 'alternative' => 'pecl/fdf', |
|
91 | + ), |
|
92 | + 'filepro' => array( |
|
93 | + '5.2' => true, |
|
94 | + 'alternative' => null, |
|
95 | + ), |
|
96 | + 'hw_api' => array( |
|
97 | + '5.2' => true, |
|
98 | + 'alternative' => null, |
|
99 | + ), |
|
100 | + 'ibase' => array( |
|
101 | + '7.4' => true, |
|
102 | + 'alternative' => 'pecl/ibase', |
|
103 | + ), |
|
104 | + 'ingres' => array( |
|
105 | + '5.1' => true, |
|
106 | + 'alternative' => 'pecl/ingres', |
|
107 | + ), |
|
108 | + 'ircg' => array( |
|
109 | + '5.1' => true, |
|
110 | + 'alternative' => null, |
|
111 | + ), |
|
112 | + 'mcrypt' => array( |
|
113 | + '7.1' => false, |
|
114 | + '7.2' => true, |
|
115 | + 'alternative' => 'openssl (preferred) or pecl/mcrypt once available', |
|
116 | + ), |
|
117 | + 'mcve' => array( |
|
118 | + '5.1' => true, |
|
119 | + 'alternative' => 'pecl/mcve', |
|
120 | + ), |
|
121 | + 'ming' => array( |
|
122 | + '5.3' => true, |
|
123 | + 'alternative' => 'pecl/ming', |
|
124 | + ), |
|
125 | + 'mnogosearch' => array( |
|
126 | + '5.1' => true, |
|
127 | + 'alternative' => null, |
|
128 | + ), |
|
129 | + 'msql' => array( |
|
130 | + '5.3' => true, |
|
131 | + 'alternative' => null, |
|
132 | + ), |
|
133 | + 'mssql' => array( |
|
134 | + '7.0' => true, |
|
135 | + 'alternative' => null, |
|
136 | + ), |
|
137 | + 'mysql_' => array( |
|
138 | + '5.5' => false, |
|
139 | + '7.0' => true, |
|
140 | + 'alternative' => 'mysqli', |
|
141 | + ), |
|
142 | + 'ncurses' => array( |
|
143 | + '5.3' => true, |
|
144 | + 'alternative' => 'pecl/ncurses', |
|
145 | + ), |
|
146 | + 'oracle' => array( |
|
147 | + '5.1' => true, |
|
148 | + 'alternative' => 'oci8 or pdo_oci', |
|
149 | + ), |
|
150 | + 'ovrimos' => array( |
|
151 | + '5.1' => true, |
|
152 | + 'alternative' => null, |
|
153 | + ), |
|
154 | + 'pfpro_' => array( |
|
155 | + '5.1' => true, |
|
156 | + 'alternative' => null, |
|
157 | + ), |
|
158 | + 'sqlite' => array( |
|
159 | + '5.4' => true, |
|
160 | + 'alternative' => null, |
|
161 | + ), |
|
162 | + // Has to be before `sybase` as otherwise it will never match. |
|
163 | + 'sybase_ct' => array( |
|
164 | + '7.0' => true, |
|
165 | + 'alternative' => null, |
|
166 | + ), |
|
167 | + 'sybase' => array( |
|
168 | + '5.3' => true, |
|
169 | + 'alternative' => 'sybase_ct', |
|
170 | + ), |
|
171 | + 'w32api' => array( |
|
172 | + '5.1' => true, |
|
173 | + 'alternative' => 'pecl/ffi', |
|
174 | + ), |
|
175 | + 'wddx' => array( |
|
176 | + '7.4' => true, |
|
177 | + 'alternative' => 'pecl/wddx', |
|
178 | + ), |
|
179 | + 'yp' => array( |
|
180 | + '5.1' => true, |
|
181 | + 'alternative' => null, |
|
182 | + ), |
|
183 | + ); |
|
184 | 184 | |
185 | - /** |
|
186 | - * Returns an array of tokens this test wants to listen for. |
|
187 | - * |
|
188 | - * @return array |
|
189 | - */ |
|
190 | - public function register() |
|
191 | - { |
|
192 | - // Handle case-insensitivity of function names. |
|
193 | - $this->removedExtensions = $this->arrayKeysToLowercase($this->removedExtensions); |
|
185 | + /** |
|
186 | + * Returns an array of tokens this test wants to listen for. |
|
187 | + * |
|
188 | + * @return array |
|
189 | + */ |
|
190 | + public function register() |
|
191 | + { |
|
192 | + // Handle case-insensitivity of function names. |
|
193 | + $this->removedExtensions = $this->arrayKeysToLowercase($this->removedExtensions); |
|
194 | 194 | |
195 | - return array(\T_STRING); |
|
196 | - } |
|
195 | + return array(\T_STRING); |
|
196 | + } |
|
197 | 197 | |
198 | - /** |
|
199 | - * Processes this test, when one of its tokens is encountered. |
|
200 | - * |
|
201 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
202 | - * @param int $stackPtr The position of the current token in the |
|
203 | - * stack passed in $tokens. |
|
204 | - * |
|
205 | - * @return void |
|
206 | - */ |
|
207 | - public function process(File $phpcsFile, $stackPtr) |
|
208 | - { |
|
209 | - $tokens = $phpcsFile->getTokens(); |
|
198 | + /** |
|
199 | + * Processes this test, when one of its tokens is encountered. |
|
200 | + * |
|
201 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
202 | + * @param int $stackPtr The position of the current token in the |
|
203 | + * stack passed in $tokens. |
|
204 | + * |
|
205 | + * @return void |
|
206 | + */ |
|
207 | + public function process(File $phpcsFile, $stackPtr) |
|
208 | + { |
|
209 | + $tokens = $phpcsFile->getTokens(); |
|
210 | 210 | |
211 | - // Find the next non-empty token. |
|
212 | - $openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); |
|
211 | + // Find the next non-empty token. |
|
212 | + $openBracket = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); |
|
213 | 213 | |
214 | - if ($tokens[$openBracket]['code'] !== \T_OPEN_PARENTHESIS) { |
|
215 | - // Not a function call. |
|
216 | - return; |
|
217 | - } |
|
214 | + if ($tokens[$openBracket]['code'] !== \T_OPEN_PARENTHESIS) { |
|
215 | + // Not a function call. |
|
216 | + return; |
|
217 | + } |
|
218 | 218 | |
219 | - if (isset($tokens[$openBracket]['parenthesis_closer']) === false) { |
|
220 | - // Not a function call. |
|
221 | - return; |
|
222 | - } |
|
219 | + if (isset($tokens[$openBracket]['parenthesis_closer']) === false) { |
|
220 | + // Not a function call. |
|
221 | + return; |
|
222 | + } |
|
223 | 223 | |
224 | - // Find the previous non-empty token. |
|
225 | - $search = Tokens::$emptyTokens; |
|
226 | - $search[] = \T_BITWISE_AND; |
|
227 | - $previous = $phpcsFile->findPrevious($search, ($stackPtr - 1), null, true); |
|
228 | - if ($tokens[$previous]['code'] === \T_FUNCTION) { |
|
229 | - // It's a function definition, not a function call. |
|
230 | - return; |
|
231 | - } |
|
224 | + // Find the previous non-empty token. |
|
225 | + $search = Tokens::$emptyTokens; |
|
226 | + $search[] = \T_BITWISE_AND; |
|
227 | + $previous = $phpcsFile->findPrevious($search, ($stackPtr - 1), null, true); |
|
228 | + if ($tokens[$previous]['code'] === \T_FUNCTION) { |
|
229 | + // It's a function definition, not a function call. |
|
230 | + return; |
|
231 | + } |
|
232 | 232 | |
233 | - if ($tokens[$previous]['code'] === \T_NEW) { |
|
234 | - // We are creating an object, not calling a function. |
|
235 | - return; |
|
236 | - } |
|
233 | + if ($tokens[$previous]['code'] === \T_NEW) { |
|
234 | + // We are creating an object, not calling a function. |
|
235 | + return; |
|
236 | + } |
|
237 | 237 | |
238 | - if ($tokens[$previous]['code'] === \T_OBJECT_OPERATOR) { |
|
239 | - // We are calling a method of an object. |
|
240 | - return; |
|
241 | - } |
|
238 | + if ($tokens[$previous]['code'] === \T_OBJECT_OPERATOR) { |
|
239 | + // We are calling a method of an object. |
|
240 | + return; |
|
241 | + } |
|
242 | 242 | |
243 | - $function = $tokens[$stackPtr]['content']; |
|
244 | - $functionLc = strtolower($function); |
|
243 | + $function = $tokens[$stackPtr]['content']; |
|
244 | + $functionLc = strtolower($function); |
|
245 | 245 | |
246 | - if ($this->isWhiteListed($functionLc) === true) { |
|
247 | - // Function is whitelisted. |
|
248 | - return; |
|
249 | - } |
|
246 | + if ($this->isWhiteListed($functionLc) === true) { |
|
247 | + // Function is whitelisted. |
|
248 | + return; |
|
249 | + } |
|
250 | 250 | |
251 | - foreach ($this->removedExtensions as $extension => $versionList) { |
|
252 | - if (strpos($functionLc, $extension) === 0) { |
|
253 | - $itemInfo = array( |
|
254 | - 'name' => $extension, |
|
255 | - ); |
|
256 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
257 | - break; |
|
258 | - } |
|
259 | - } |
|
260 | - } |
|
251 | + foreach ($this->removedExtensions as $extension => $versionList) { |
|
252 | + if (strpos($functionLc, $extension) === 0) { |
|
253 | + $itemInfo = array( |
|
254 | + 'name' => $extension, |
|
255 | + ); |
|
256 | + $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
257 | + break; |
|
258 | + } |
|
259 | + } |
|
260 | + } |
|
261 | 261 | |
262 | 262 | |
263 | - /** |
|
264 | - * Is the current function being checked whitelisted ? |
|
265 | - * |
|
266 | - * Parsing the list late as it may be provided as a property, but also inline. |
|
267 | - * |
|
268 | - * @param string $content Content of the current token. |
|
269 | - * |
|
270 | - * @return bool |
|
271 | - */ |
|
272 | - protected function isWhiteListed($content) |
|
273 | - { |
|
274 | - if (isset($this->functionWhitelist) === false) { |
|
275 | - return false; |
|
276 | - } |
|
263 | + /** |
|
264 | + * Is the current function being checked whitelisted ? |
|
265 | + * |
|
266 | + * Parsing the list late as it may be provided as a property, but also inline. |
|
267 | + * |
|
268 | + * @param string $content Content of the current token. |
|
269 | + * |
|
270 | + * @return bool |
|
271 | + */ |
|
272 | + protected function isWhiteListed($content) |
|
273 | + { |
|
274 | + if (isset($this->functionWhitelist) === false) { |
|
275 | + return false; |
|
276 | + } |
|
277 | 277 | |
278 | - if (\is_string($this->functionWhitelist) === true) { |
|
279 | - if (strpos($this->functionWhitelist, ',') !== false) { |
|
280 | - $this->functionWhitelist = explode(',', $this->functionWhitelist); |
|
281 | - } else { |
|
282 | - $this->functionWhitelist = (array) $this->functionWhitelist; |
|
283 | - } |
|
284 | - } |
|
278 | + if (\is_string($this->functionWhitelist) === true) { |
|
279 | + if (strpos($this->functionWhitelist, ',') !== false) { |
|
280 | + $this->functionWhitelist = explode(',', $this->functionWhitelist); |
|
281 | + } else { |
|
282 | + $this->functionWhitelist = (array) $this->functionWhitelist; |
|
283 | + } |
|
284 | + } |
|
285 | 285 | |
286 | - if (\is_array($this->functionWhitelist) === true) { |
|
287 | - $this->functionWhitelist = array_map('strtolower', $this->functionWhitelist); |
|
288 | - return \in_array($content, $this->functionWhitelist, true); |
|
289 | - } |
|
286 | + if (\is_array($this->functionWhitelist) === true) { |
|
287 | + $this->functionWhitelist = array_map('strtolower', $this->functionWhitelist); |
|
288 | + return \in_array($content, $this->functionWhitelist, true); |
|
289 | + } |
|
290 | 290 | |
291 | - return false; |
|
292 | - } |
|
291 | + return false; |
|
292 | + } |
|
293 | 293 | |
294 | 294 | |
295 | - /** |
|
296 | - * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
297 | - * |
|
298 | - * @param array $itemInfo Base information about the item. |
|
299 | - * |
|
300 | - * @return array Version and other information about the item. |
|
301 | - */ |
|
302 | - public function getItemArray(array $itemInfo) |
|
303 | - { |
|
304 | - return $this->removedExtensions[$itemInfo['name']]; |
|
305 | - } |
|
295 | + /** |
|
296 | + * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
297 | + * |
|
298 | + * @param array $itemInfo Base information about the item. |
|
299 | + * |
|
300 | + * @return array Version and other information about the item. |
|
301 | + */ |
|
302 | + public function getItemArray(array $itemInfo) |
|
303 | + { |
|
304 | + return $this->removedExtensions[$itemInfo['name']]; |
|
305 | + } |
|
306 | 306 | |
307 | 307 | |
308 | - /** |
|
309 | - * Get the error message template for this sniff. |
|
310 | - * |
|
311 | - * @return string |
|
312 | - */ |
|
313 | - protected function getErrorMsgTemplate() |
|
314 | - { |
|
315 | - return "Extension '%s' is "; |
|
316 | - } |
|
308 | + /** |
|
309 | + * Get the error message template for this sniff. |
|
310 | + * |
|
311 | + * @return string |
|
312 | + */ |
|
313 | + protected function getErrorMsgTemplate() |
|
314 | + { |
|
315 | + return "Extension '%s' is "; |
|
316 | + } |
|
317 | 317 | } |
@@ -26,80 +26,80 @@ |
||
26 | 26 | */ |
27 | 27 | class NewGroupUseDeclarationsSniff extends Sniff |
28 | 28 | { |
29 | - /** |
|
30 | - * Returns an array of tokens this test wants to listen for. |
|
31 | - * |
|
32 | - * @return array |
|
33 | - */ |
|
34 | - public function register() |
|
35 | - { |
|
36 | - if (\defined('T_OPEN_USE_GROUP')) { |
|
37 | - return array(\T_OPEN_USE_GROUP); |
|
38 | - } else { |
|
39 | - return array(\T_USE); |
|
40 | - } |
|
41 | - } |
|
29 | + /** |
|
30 | + * Returns an array of tokens this test wants to listen for. |
|
31 | + * |
|
32 | + * @return array |
|
33 | + */ |
|
34 | + public function register() |
|
35 | + { |
|
36 | + if (\defined('T_OPEN_USE_GROUP')) { |
|
37 | + return array(\T_OPEN_USE_GROUP); |
|
38 | + } else { |
|
39 | + return array(\T_USE); |
|
40 | + } |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * Processes this test, when one of its tokens is encountered. |
|
46 | - * |
|
47 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
48 | - * @param int $stackPtr The position of the current token in |
|
49 | - * the stack passed in $tokens. |
|
50 | - * |
|
51 | - * @return void |
|
52 | - */ |
|
53 | - public function process(File $phpcsFile, $stackPtr) |
|
54 | - { |
|
55 | - if ($this->supportsBelow('7.1') === false) { |
|
56 | - return; |
|
57 | - } |
|
44 | + /** |
|
45 | + * Processes this test, when one of its tokens is encountered. |
|
46 | + * |
|
47 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
48 | + * @param int $stackPtr The position of the current token in |
|
49 | + * the stack passed in $tokens. |
|
50 | + * |
|
51 | + * @return void |
|
52 | + */ |
|
53 | + public function process(File $phpcsFile, $stackPtr) |
|
54 | + { |
|
55 | + if ($this->supportsBelow('7.1') === false) { |
|
56 | + return; |
|
57 | + } |
|
58 | 58 | |
59 | - $tokens = $phpcsFile->getTokens(); |
|
60 | - $token = $tokens[$stackPtr]; |
|
59 | + $tokens = $phpcsFile->getTokens(); |
|
60 | + $token = $tokens[$stackPtr]; |
|
61 | 61 | |
62 | - // Deal with PHPCS pre-2.6.0. |
|
63 | - if ($token['code'] === \T_USE) { |
|
64 | - $hasCurlyBrace = $phpcsFile->findNext(\T_OPEN_CURLY_BRACKET, ($stackPtr + 1), null, false, null, true); |
|
65 | - if ($hasCurlyBrace === false) { |
|
66 | - return; |
|
67 | - } |
|
62 | + // Deal with PHPCS pre-2.6.0. |
|
63 | + if ($token['code'] === \T_USE) { |
|
64 | + $hasCurlyBrace = $phpcsFile->findNext(\T_OPEN_CURLY_BRACKET, ($stackPtr + 1), null, false, null, true); |
|
65 | + if ($hasCurlyBrace === false) { |
|
66 | + return; |
|
67 | + } |
|
68 | 68 | |
69 | - $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($hasCurlyBrace - 1), null, true); |
|
70 | - if ($prevToken === false || $tokens[$prevToken]['code'] !== \T_NS_SEPARATOR) { |
|
71 | - return; |
|
72 | - } |
|
69 | + $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($hasCurlyBrace - 1), null, true); |
|
70 | + if ($prevToken === false || $tokens[$prevToken]['code'] !== \T_NS_SEPARATOR) { |
|
71 | + return; |
|
72 | + } |
|
73 | 73 | |
74 | - $stackPtr = $hasCurlyBrace; |
|
75 | - } |
|
74 | + $stackPtr = $hasCurlyBrace; |
|
75 | + } |
|
76 | 76 | |
77 | - // Still here ? In that case, it is a group use statement. |
|
78 | - if ($this->supportsBelow('5.6') === true) { |
|
79 | - $phpcsFile->addError( |
|
80 | - 'Group use declarations are not allowed in PHP 5.6 or earlier', |
|
81 | - $stackPtr, |
|
82 | - 'Found' |
|
83 | - ); |
|
84 | - } |
|
77 | + // Still here ? In that case, it is a group use statement. |
|
78 | + if ($this->supportsBelow('5.6') === true) { |
|
79 | + $phpcsFile->addError( |
|
80 | + 'Group use declarations are not allowed in PHP 5.6 or earlier', |
|
81 | + $stackPtr, |
|
82 | + 'Found' |
|
83 | + ); |
|
84 | + } |
|
85 | 85 | |
86 | - $closers = array(\T_CLOSE_CURLY_BRACKET); |
|
87 | - if (\defined('T_CLOSE_USE_GROUP')) { |
|
88 | - $closers[] = \T_CLOSE_USE_GROUP; |
|
89 | - } |
|
86 | + $closers = array(\T_CLOSE_CURLY_BRACKET); |
|
87 | + if (\defined('T_CLOSE_USE_GROUP')) { |
|
88 | + $closers[] = \T_CLOSE_USE_GROUP; |
|
89 | + } |
|
90 | 90 | |
91 | - $closeCurly = $phpcsFile->findNext($closers, ($stackPtr + 1), null, false, null, true); |
|
92 | - if ($closeCurly === false) { |
|
93 | - return; |
|
94 | - } |
|
91 | + $closeCurly = $phpcsFile->findNext($closers, ($stackPtr + 1), null, false, null, true); |
|
92 | + if ($closeCurly === false) { |
|
93 | + return; |
|
94 | + } |
|
95 | 95 | |
96 | - $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($closeCurly - 1), null, true); |
|
97 | - if ($tokens[$prevToken]['code'] === \T_COMMA) { |
|
98 | - $phpcsFile->addError( |
|
99 | - 'Trailing comma\'s are not allowed in group use statements in PHP 7.1 or earlier', |
|
100 | - $prevToken, |
|
101 | - 'TrailingCommaFound' |
|
102 | - ); |
|
103 | - } |
|
104 | - } |
|
96 | + $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($closeCurly - 1), null, true); |
|
97 | + if ($tokens[$prevToken]['code'] === \T_COMMA) { |
|
98 | + $phpcsFile->addError( |
|
99 | + 'Trailing comma\'s are not allowed in group use statements in PHP 7.1 or earlier', |
|
100 | + $prevToken, |
|
101 | + 'TrailingCommaFound' |
|
102 | + ); |
|
103 | + } |
|
104 | + } |
|
105 | 105 | } |
@@ -31,72 +31,72 @@ |
||
31 | 31 | class NewUseConstFunctionSniff extends Sniff |
32 | 32 | { |
33 | 33 | |
34 | - /** |
|
35 | - * A list of keywords that can follow use statements. |
|
36 | - * |
|
37 | - * @var array(string => string) |
|
38 | - */ |
|
39 | - protected $validUseNames = array( |
|
40 | - 'const' => true, |
|
41 | - 'function' => true, |
|
42 | - ); |
|
34 | + /** |
|
35 | + * A list of keywords that can follow use statements. |
|
36 | + * |
|
37 | + * @var array(string => string) |
|
38 | + */ |
|
39 | + protected $validUseNames = array( |
|
40 | + 'const' => true, |
|
41 | + 'function' => true, |
|
42 | + ); |
|
43 | 43 | |
44 | - /** |
|
45 | - * Returns an array of tokens this test wants to listen for. |
|
46 | - * |
|
47 | - * @return array |
|
48 | - */ |
|
49 | - public function register() |
|
50 | - { |
|
51 | - return array(\T_USE); |
|
52 | - } |
|
44 | + /** |
|
45 | + * Returns an array of tokens this test wants to listen for. |
|
46 | + * |
|
47 | + * @return array |
|
48 | + */ |
|
49 | + public function register() |
|
50 | + { |
|
51 | + return array(\T_USE); |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * Processes this test, when one of its tokens is encountered. |
|
57 | - * |
|
58 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
59 | - * @param int $stackPtr The position of the current token in the |
|
60 | - * stack passed in $tokens. |
|
61 | - * |
|
62 | - * @return void |
|
63 | - */ |
|
64 | - public function process(File $phpcsFile, $stackPtr) |
|
65 | - { |
|
66 | - if ($this->supportsBelow('5.5') !== true) { |
|
67 | - return; |
|
68 | - } |
|
55 | + /** |
|
56 | + * Processes this test, when one of its tokens is encountered. |
|
57 | + * |
|
58 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
59 | + * @param int $stackPtr The position of the current token in the |
|
60 | + * stack passed in $tokens. |
|
61 | + * |
|
62 | + * @return void |
|
63 | + */ |
|
64 | + public function process(File $phpcsFile, $stackPtr) |
|
65 | + { |
|
66 | + if ($this->supportsBelow('5.5') !== true) { |
|
67 | + return; |
|
68 | + } |
|
69 | 69 | |
70 | - $tokens = $phpcsFile->getTokens(); |
|
70 | + $tokens = $phpcsFile->getTokens(); |
|
71 | 71 | |
72 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); |
|
73 | - if ($nextNonEmpty === false) { |
|
74 | - // Live coding. |
|
75 | - return; |
|
76 | - } |
|
72 | + $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); |
|
73 | + if ($nextNonEmpty === false) { |
|
74 | + // Live coding. |
|
75 | + return; |
|
76 | + } |
|
77 | 77 | |
78 | - if (isset($this->validUseNames[strtolower($tokens[$nextNonEmpty]['content'])]) === false) { |
|
79 | - // Not a `use const` or `use function` statement. |
|
80 | - return; |
|
81 | - } |
|
78 | + if (isset($this->validUseNames[strtolower($tokens[$nextNonEmpty]['content'])]) === false) { |
|
79 | + // Not a `use const` or `use function` statement. |
|
80 | + return; |
|
81 | + } |
|
82 | 82 | |
83 | - // `use const` and `use function` have to be followed by the function/constant name. |
|
84 | - $functionOrConstName = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextNonEmpty + 1), null, true); |
|
85 | - if ($functionOrConstName === false |
|
86 | - // Identifies as T_AS or T_STRING, this covers both. |
|
87 | - || ($tokens[$functionOrConstName]['content'] === 'as' |
|
88 | - || $tokens[$functionOrConstName]['code'] === \T_COMMA) |
|
89 | - ) { |
|
90 | - // Live coding or incorrect use of reserved keyword, but that is |
|
91 | - // covered by the ForbiddenNames sniff. |
|
92 | - return; |
|
93 | - } |
|
83 | + // `use const` and `use function` have to be followed by the function/constant name. |
|
84 | + $functionOrConstName = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextNonEmpty + 1), null, true); |
|
85 | + if ($functionOrConstName === false |
|
86 | + // Identifies as T_AS or T_STRING, this covers both. |
|
87 | + || ($tokens[$functionOrConstName]['content'] === 'as' |
|
88 | + || $tokens[$functionOrConstName]['code'] === \T_COMMA) |
|
89 | + ) { |
|
90 | + // Live coding or incorrect use of reserved keyword, but that is |
|
91 | + // covered by the ForbiddenNames sniff. |
|
92 | + return; |
|
93 | + } |
|
94 | 94 | |
95 | - // Still here ? In that case we have encountered a `use const` or `use function` statement. |
|
96 | - $phpcsFile->addError( |
|
97 | - 'Importing functions and constants through a "use" statement is not supported in PHP 5.5 or lower.', |
|
98 | - $nextNonEmpty, |
|
99 | - 'Found' |
|
100 | - ); |
|
101 | - } |
|
95 | + // Still here ? In that case we have encountered a `use const` or `use function` statement. |
|
96 | + $phpcsFile->addError( |
|
97 | + 'Importing functions and constants through a "use" statement is not supported in PHP 5.5 or lower.', |
|
98 | + $nextNonEmpty, |
|
99 | + 'Found' |
|
100 | + ); |
|
101 | + } |
|
102 | 102 | } |
@@ -21,107 +21,107 @@ |
||
21 | 21 | */ |
22 | 22 | class RemovedTypeCastsSniff extends AbstractRemovedFeatureSniff |
23 | 23 | { |
24 | - /** |
|
25 | - * A list of deprecated and removed type casts with their alternatives. |
|
26 | - * |
|
27 | - * The array lists : version number with false (deprecated) or true (removed) and an alternative function. |
|
28 | - * If no alternative exists, it is NULL, i.e, the function should just not be used. |
|
29 | - * |
|
30 | - * @var array(string => array(string => bool|string|null)) |
|
31 | - */ |
|
32 | - protected $deprecatedTypeCasts = array( |
|
33 | - 'T_UNSET_CAST' => array( |
|
34 | - '7.2' => false, |
|
35 | - 'alternative' => 'unset()', |
|
36 | - 'description' => 'unset', |
|
37 | - ), |
|
38 | - ); |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * Returns an array of tokens this test wants to listen for. |
|
43 | - * |
|
44 | - * @return array |
|
45 | - */ |
|
46 | - public function register() |
|
47 | - { |
|
48 | - $tokens = array(); |
|
49 | - foreach ($this->deprecatedTypeCasts as $token => $versions) { |
|
50 | - $tokens[] = constant($token); |
|
51 | - } |
|
52 | - |
|
53 | - return $tokens; |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Processes this test, when one of its tokens is encountered. |
|
59 | - * |
|
60 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
61 | - * @param int $stackPtr The position of the current token in |
|
62 | - * the stack passed in $tokens. |
|
63 | - * |
|
64 | - * @return void |
|
65 | - */ |
|
66 | - public function process(File $phpcsFile, $stackPtr) |
|
67 | - { |
|
68 | - $tokens = $phpcsFile->getTokens(); |
|
69 | - $tokenType = $tokens[$stackPtr]['type']; |
|
70 | - |
|
71 | - $itemInfo = array( |
|
72 | - 'name' => $tokenType, |
|
73 | - 'description' => $this->deprecatedTypeCasts[$tokenType]['description'], |
|
74 | - ); |
|
75 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * Get an array of the non-PHP-version array keys used in a sub-array. |
|
81 | - * |
|
82 | - * @return array |
|
83 | - */ |
|
84 | - protected function getNonVersionArrayKeys() |
|
85 | - { |
|
86 | - return array('description', 'alternative'); |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
91 | - * |
|
92 | - * @param array $itemInfo Base information about the item. |
|
93 | - * |
|
94 | - * @return array Version and other information about the item. |
|
95 | - */ |
|
96 | - public function getItemArray(array $itemInfo) |
|
97 | - { |
|
98 | - return $this->deprecatedTypeCasts[$itemInfo['name']]; |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * Get the error message template for this sniff. |
|
104 | - * |
|
105 | - * @return string |
|
106 | - */ |
|
107 | - protected function getErrorMsgTemplate() |
|
108 | - { |
|
109 | - return 'The %s cast is '; |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * Filter the error data before it's passed to PHPCS. |
|
115 | - * |
|
116 | - * @param array $data The error data array which was created. |
|
117 | - * @param array $itemInfo Base information about the item this error message applies to. |
|
118 | - * @param array $errorInfo Detail information about an item this error message applies to. |
|
119 | - * |
|
120 | - * @return array |
|
121 | - */ |
|
122 | - protected function filterErrorData(array $data, array $itemInfo, array $errorInfo) |
|
123 | - { |
|
124 | - $data[0] = $itemInfo['description']; |
|
125 | - return $data; |
|
126 | - } |
|
24 | + /** |
|
25 | + * A list of deprecated and removed type casts with their alternatives. |
|
26 | + * |
|
27 | + * The array lists : version number with false (deprecated) or true (removed) and an alternative function. |
|
28 | + * If no alternative exists, it is NULL, i.e, the function should just not be used. |
|
29 | + * |
|
30 | + * @var array(string => array(string => bool|string|null)) |
|
31 | + */ |
|
32 | + protected $deprecatedTypeCasts = array( |
|
33 | + 'T_UNSET_CAST' => array( |
|
34 | + '7.2' => false, |
|
35 | + 'alternative' => 'unset()', |
|
36 | + 'description' => 'unset', |
|
37 | + ), |
|
38 | + ); |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * Returns an array of tokens this test wants to listen for. |
|
43 | + * |
|
44 | + * @return array |
|
45 | + */ |
|
46 | + public function register() |
|
47 | + { |
|
48 | + $tokens = array(); |
|
49 | + foreach ($this->deprecatedTypeCasts as $token => $versions) { |
|
50 | + $tokens[] = constant($token); |
|
51 | + } |
|
52 | + |
|
53 | + return $tokens; |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Processes this test, when one of its tokens is encountered. |
|
59 | + * |
|
60 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
61 | + * @param int $stackPtr The position of the current token in |
|
62 | + * the stack passed in $tokens. |
|
63 | + * |
|
64 | + * @return void |
|
65 | + */ |
|
66 | + public function process(File $phpcsFile, $stackPtr) |
|
67 | + { |
|
68 | + $tokens = $phpcsFile->getTokens(); |
|
69 | + $tokenType = $tokens[$stackPtr]['type']; |
|
70 | + |
|
71 | + $itemInfo = array( |
|
72 | + 'name' => $tokenType, |
|
73 | + 'description' => $this->deprecatedTypeCasts[$tokenType]['description'], |
|
74 | + ); |
|
75 | + $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * Get an array of the non-PHP-version array keys used in a sub-array. |
|
81 | + * |
|
82 | + * @return array |
|
83 | + */ |
|
84 | + protected function getNonVersionArrayKeys() |
|
85 | + { |
|
86 | + return array('description', 'alternative'); |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
91 | + * |
|
92 | + * @param array $itemInfo Base information about the item. |
|
93 | + * |
|
94 | + * @return array Version and other information about the item. |
|
95 | + */ |
|
96 | + public function getItemArray(array $itemInfo) |
|
97 | + { |
|
98 | + return $this->deprecatedTypeCasts[$itemInfo['name']]; |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * Get the error message template for this sniff. |
|
104 | + * |
|
105 | + * @return string |
|
106 | + */ |
|
107 | + protected function getErrorMsgTemplate() |
|
108 | + { |
|
109 | + return 'The %s cast is '; |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * Filter the error data before it's passed to PHPCS. |
|
115 | + * |
|
116 | + * @param array $data The error data array which was created. |
|
117 | + * @param array $itemInfo Base information about the item this error message applies to. |
|
118 | + * @param array $errorInfo Detail information about an item this error message applies to. |
|
119 | + * |
|
120 | + * @return array |
|
121 | + */ |
|
122 | + protected function filterErrorData(array $data, array $itemInfo, array $errorInfo) |
|
123 | + { |
|
124 | + $data[0] = $itemInfo['description']; |
|
125 | + return $data; |
|
126 | + } |
|
127 | 127 | } |
@@ -23,43 +23,43 @@ discard block |
||
23 | 23 | class NewTypeCastsSniff extends AbstractNewFeatureSniff |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * A list of new type casts, not present in older versions. |
|
28 | - * |
|
29 | - * The array lists : version number with false (not present) or true (present). |
|
30 | - * If's sufficient to list the first version where the keyword appears. |
|
31 | - * |
|
32 | - * @var array(string => array(string => int|string|null)) |
|
33 | - */ |
|
34 | - protected $newTypeCasts = array( |
|
35 | - 'T_UNSET_CAST' => array( |
|
36 | - '4.4' => false, |
|
37 | - '5.0' => true, |
|
38 | - 'description' => 'The unset cast', |
|
39 | - ), |
|
40 | - 'T_BINARY_CAST' => array( |
|
41 | - '5.2.0' => false, |
|
42 | - '5.2.1' => true, |
|
43 | - 'description' => 'The binary cast', |
|
44 | - ), |
|
45 | - ); |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * Returns an array of tokens this test wants to listen for. |
|
50 | - * |
|
51 | - * @return array |
|
52 | - */ |
|
53 | - public function register() |
|
54 | - { |
|
55 | - $tokens = array(); |
|
56 | - foreach ($this->newTypeCasts as $token => $versions) { |
|
57 | - if (\defined($token)) { |
|
58 | - $tokens[] = constant($token); |
|
59 | - } |
|
60 | - } |
|
61 | - |
|
62 | - /* |
|
26 | + /** |
|
27 | + * A list of new type casts, not present in older versions. |
|
28 | + * |
|
29 | + * The array lists : version number with false (not present) or true (present). |
|
30 | + * If's sufficient to list the first version where the keyword appears. |
|
31 | + * |
|
32 | + * @var array(string => array(string => int|string|null)) |
|
33 | + */ |
|
34 | + protected $newTypeCasts = array( |
|
35 | + 'T_UNSET_CAST' => array( |
|
36 | + '4.4' => false, |
|
37 | + '5.0' => true, |
|
38 | + 'description' => 'The unset cast', |
|
39 | + ), |
|
40 | + 'T_BINARY_CAST' => array( |
|
41 | + '5.2.0' => false, |
|
42 | + '5.2.1' => true, |
|
43 | + 'description' => 'The binary cast', |
|
44 | + ), |
|
45 | + ); |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * Returns an array of tokens this test wants to listen for. |
|
50 | + * |
|
51 | + * @return array |
|
52 | + */ |
|
53 | + public function register() |
|
54 | + { |
|
55 | + $tokens = array(); |
|
56 | + foreach ($this->newTypeCasts as $token => $versions) { |
|
57 | + if (\defined($token)) { |
|
58 | + $tokens[] = constant($token); |
|
59 | + } |
|
60 | + } |
|
61 | + |
|
62 | + /* |
|
63 | 63 | * Work around tokenizer issues. |
64 | 64 | * |
65 | 65 | * - (binary) cast is incorrectly tokenized as T_STRING_CAST by PHP and PHPCS. |
@@ -68,136 +68,136 @@ discard block |
||
68 | 68 | * |
69 | 69 | * @link https://github.com/squizlabs/PHP_CodeSniffer/issues/1574 |
70 | 70 | */ |
71 | - if (version_compare(PHPCSHelper::getVersion(), '3.4.0', '<') === true) { |
|
72 | - $tokens[] = \T_STRING_CAST; |
|
73 | - $tokens[] = \T_CONSTANT_ENCAPSED_STRING; |
|
74 | - } |
|
75 | - |
|
76 | - return $tokens; |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * Processes this test, when one of its tokens is encountered. |
|
82 | - * |
|
83 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
84 | - * @param int $stackPtr The position of the current token in |
|
85 | - * the stack passed in $tokens. |
|
86 | - * |
|
87 | - * @return void |
|
88 | - */ |
|
89 | - public function process(File $phpcsFile, $stackPtr) |
|
90 | - { |
|
91 | - $tokens = $phpcsFile->getTokens(); |
|
92 | - $tokenType = $tokens[$stackPtr]['type']; |
|
93 | - |
|
94 | - // Detect incorrectly tokenized binary casts. |
|
95 | - if (isset($this->newTypeCasts[$tokenType]) === false) { |
|
96 | - $tokenContent = $tokens[$stackPtr]['content']; |
|
97 | - switch ($tokenType) { |
|
98 | - case 'T_STRING_CAST': |
|
99 | - if (preg_match('`^\(\s*binary\s*\)$`i', $tokenContent) !== 1) { |
|
100 | - return; |
|
101 | - } |
|
102 | - |
|
103 | - $tokenType = 'T_BINARY_CAST'; |
|
104 | - break; |
|
105 | - |
|
106 | - case 'T_CONSTANT_ENCAPSED_STRING': |
|
107 | - if ((strpos($tokenContent, 'b"') === 0 && substr($tokenContent, -1) === '"') |
|
108 | - || (strpos($tokenContent, "b'") === 0 && substr($tokenContent, -1) === "'") |
|
109 | - ) { |
|
110 | - $tokenType = 'T_BINARY_CAST'; |
|
111 | - } else { |
|
112 | - return; |
|
113 | - } |
|
114 | - break; |
|
115 | - |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - // If the translation did not yield one of the tokens we are looking for, bow out. |
|
120 | - if (isset($this->newTypeCasts[$tokenType]) === false) { |
|
121 | - return; |
|
122 | - } |
|
123 | - |
|
124 | - $itemInfo = array( |
|
125 | - 'name' => $tokenType, |
|
126 | - 'content' => $tokens[$stackPtr]['content'], |
|
127 | - ); |
|
128 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
134 | - * |
|
135 | - * @param array $itemInfo Base information about the item. |
|
136 | - * |
|
137 | - * @return array Version and other information about the item. |
|
138 | - */ |
|
139 | - public function getItemArray(array $itemInfo) |
|
140 | - { |
|
141 | - return $this->newTypeCasts[$itemInfo['name']]; |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * Get an array of the non-PHP-version array keys used in a sub-array. |
|
147 | - * |
|
148 | - * @return array |
|
149 | - */ |
|
150 | - protected function getNonVersionArrayKeys() |
|
151 | - { |
|
152 | - return array('description'); |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * Retrieve the relevant detail (version) information for use in an error message. |
|
158 | - * |
|
159 | - * @param array $itemArray Version and other information about the item. |
|
160 | - * @param array $itemInfo Base information about the item. |
|
161 | - * |
|
162 | - * @return array |
|
163 | - */ |
|
164 | - public function getErrorInfo(array $itemArray, array $itemInfo) |
|
165 | - { |
|
166 | - $errorInfo = parent::getErrorInfo($itemArray, $itemInfo); |
|
167 | - $errorInfo['description'] = $itemArray['description']; |
|
168 | - |
|
169 | - return $errorInfo; |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * Filter the error message before it's passed to PHPCS. |
|
175 | - * |
|
176 | - * @param string $error The error message which was created. |
|
177 | - * @param array $itemInfo Base information about the item this error message applies to. |
|
178 | - * @param array $errorInfo Detail information about an item this error message applies to. |
|
179 | - * |
|
180 | - * @return string |
|
181 | - */ |
|
182 | - protected function filterErrorMsg($error, array $itemInfo, array $errorInfo) |
|
183 | - { |
|
184 | - return $error . '. Found: %s'; |
|
185 | - } |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * Filter the error data before it's passed to PHPCS. |
|
190 | - * |
|
191 | - * @param array $data The error data array which was created. |
|
192 | - * @param array $itemInfo Base information about the item this error message applies to. |
|
193 | - * @param array $errorInfo Detail information about an item this error message applies to. |
|
194 | - * |
|
195 | - * @return array |
|
196 | - */ |
|
197 | - protected function filterErrorData(array $data, array $itemInfo, array $errorInfo) |
|
198 | - { |
|
199 | - $data[0] = $errorInfo['description']; |
|
200 | - $data[] = $itemInfo['content']; |
|
201 | - return $data; |
|
202 | - } |
|
71 | + if (version_compare(PHPCSHelper::getVersion(), '3.4.0', '<') === true) { |
|
72 | + $tokens[] = \T_STRING_CAST; |
|
73 | + $tokens[] = \T_CONSTANT_ENCAPSED_STRING; |
|
74 | + } |
|
75 | + |
|
76 | + return $tokens; |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * Processes this test, when one of its tokens is encountered. |
|
82 | + * |
|
83 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
84 | + * @param int $stackPtr The position of the current token in |
|
85 | + * the stack passed in $tokens. |
|
86 | + * |
|
87 | + * @return void |
|
88 | + */ |
|
89 | + public function process(File $phpcsFile, $stackPtr) |
|
90 | + { |
|
91 | + $tokens = $phpcsFile->getTokens(); |
|
92 | + $tokenType = $tokens[$stackPtr]['type']; |
|
93 | + |
|
94 | + // Detect incorrectly tokenized binary casts. |
|
95 | + if (isset($this->newTypeCasts[$tokenType]) === false) { |
|
96 | + $tokenContent = $tokens[$stackPtr]['content']; |
|
97 | + switch ($tokenType) { |
|
98 | + case 'T_STRING_CAST': |
|
99 | + if (preg_match('`^\(\s*binary\s*\)$`i', $tokenContent) !== 1) { |
|
100 | + return; |
|
101 | + } |
|
102 | + |
|
103 | + $tokenType = 'T_BINARY_CAST'; |
|
104 | + break; |
|
105 | + |
|
106 | + case 'T_CONSTANT_ENCAPSED_STRING': |
|
107 | + if ((strpos($tokenContent, 'b"') === 0 && substr($tokenContent, -1) === '"') |
|
108 | + || (strpos($tokenContent, "b'") === 0 && substr($tokenContent, -1) === "'") |
|
109 | + ) { |
|
110 | + $tokenType = 'T_BINARY_CAST'; |
|
111 | + } else { |
|
112 | + return; |
|
113 | + } |
|
114 | + break; |
|
115 | + |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + // If the translation did not yield one of the tokens we are looking for, bow out. |
|
120 | + if (isset($this->newTypeCasts[$tokenType]) === false) { |
|
121 | + return; |
|
122 | + } |
|
123 | + |
|
124 | + $itemInfo = array( |
|
125 | + 'name' => $tokenType, |
|
126 | + 'content' => $tokens[$stackPtr]['content'], |
|
127 | + ); |
|
128 | + $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
134 | + * |
|
135 | + * @param array $itemInfo Base information about the item. |
|
136 | + * |
|
137 | + * @return array Version and other information about the item. |
|
138 | + */ |
|
139 | + public function getItemArray(array $itemInfo) |
|
140 | + { |
|
141 | + return $this->newTypeCasts[$itemInfo['name']]; |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * Get an array of the non-PHP-version array keys used in a sub-array. |
|
147 | + * |
|
148 | + * @return array |
|
149 | + */ |
|
150 | + protected function getNonVersionArrayKeys() |
|
151 | + { |
|
152 | + return array('description'); |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * Retrieve the relevant detail (version) information for use in an error message. |
|
158 | + * |
|
159 | + * @param array $itemArray Version and other information about the item. |
|
160 | + * @param array $itemInfo Base information about the item. |
|
161 | + * |
|
162 | + * @return array |
|
163 | + */ |
|
164 | + public function getErrorInfo(array $itemArray, array $itemInfo) |
|
165 | + { |
|
166 | + $errorInfo = parent::getErrorInfo($itemArray, $itemInfo); |
|
167 | + $errorInfo['description'] = $itemArray['description']; |
|
168 | + |
|
169 | + return $errorInfo; |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * Filter the error message before it's passed to PHPCS. |
|
175 | + * |
|
176 | + * @param string $error The error message which was created. |
|
177 | + * @param array $itemInfo Base information about the item this error message applies to. |
|
178 | + * @param array $errorInfo Detail information about an item this error message applies to. |
|
179 | + * |
|
180 | + * @return string |
|
181 | + */ |
|
182 | + protected function filterErrorMsg($error, array $itemInfo, array $errorInfo) |
|
183 | + { |
|
184 | + return $error . '. Found: %s'; |
|
185 | + } |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * Filter the error data before it's passed to PHPCS. |
|
190 | + * |
|
191 | + * @param array $data The error data array which was created. |
|
192 | + * @param array $itemInfo Base information about the item this error message applies to. |
|
193 | + * @param array $errorInfo Detail information about an item this error message applies to. |
|
194 | + * |
|
195 | + * @return array |
|
196 | + */ |
|
197 | + protected function filterErrorData(array $data, array $itemInfo, array $errorInfo) |
|
198 | + { |
|
199 | + $data[0] = $errorInfo['description']; |
|
200 | + $data[] = $itemInfo['content']; |
|
201 | + return $data; |
|
202 | + } |
|
203 | 203 | } |
@@ -25,374 +25,374 @@ |
||
25 | 25 | */ |
26 | 26 | class RemovedIniDirectivesSniff extends AbstractRemovedFeatureSniff |
27 | 27 | { |
28 | - /** |
|
29 | - * A list of deprecated INI directives. |
|
30 | - * |
|
31 | - * The array lists : version number with false (deprecated) and true (removed). |
|
32 | - * If's sufficient to list the first version where the ini directive was deprecated/removed. |
|
33 | - * |
|
34 | - * @var array(string) |
|
35 | - */ |
|
36 | - protected $deprecatedIniDirectives = array( |
|
37 | - 'fbsql.batchSize' => array( |
|
38 | - '5.1' => true, |
|
39 | - 'alternative' => 'fbsql.batchsize', |
|
40 | - ), |
|
41 | - 'pfpro.defaulthost' => array( |
|
42 | - '5.1' => true, |
|
43 | - ), |
|
44 | - 'pfpro.defaultport' => array( |
|
45 | - '5.1' => true, |
|
46 | - ), |
|
47 | - 'pfpro.defaulttimeout' => array( |
|
48 | - '5.1' => true, |
|
49 | - ), |
|
50 | - 'pfpro.proxyaddress' => array( |
|
51 | - '5.1' => true, |
|
52 | - ), |
|
53 | - 'pfpro.proxyport' => array( |
|
54 | - '5.1' => true, |
|
55 | - ), |
|
56 | - 'pfpro.proxylogon' => array( |
|
57 | - '5.1' => true, |
|
58 | - ), |
|
59 | - 'pfpro.proxypassword' => array( |
|
60 | - '5.1' => true, |
|
61 | - ), |
|
28 | + /** |
|
29 | + * A list of deprecated INI directives. |
|
30 | + * |
|
31 | + * The array lists : version number with false (deprecated) and true (removed). |
|
32 | + * If's sufficient to list the first version where the ini directive was deprecated/removed. |
|
33 | + * |
|
34 | + * @var array(string) |
|
35 | + */ |
|
36 | + protected $deprecatedIniDirectives = array( |
|
37 | + 'fbsql.batchSize' => array( |
|
38 | + '5.1' => true, |
|
39 | + 'alternative' => 'fbsql.batchsize', |
|
40 | + ), |
|
41 | + 'pfpro.defaulthost' => array( |
|
42 | + '5.1' => true, |
|
43 | + ), |
|
44 | + 'pfpro.defaultport' => array( |
|
45 | + '5.1' => true, |
|
46 | + ), |
|
47 | + 'pfpro.defaulttimeout' => array( |
|
48 | + '5.1' => true, |
|
49 | + ), |
|
50 | + 'pfpro.proxyaddress' => array( |
|
51 | + '5.1' => true, |
|
52 | + ), |
|
53 | + 'pfpro.proxyport' => array( |
|
54 | + '5.1' => true, |
|
55 | + ), |
|
56 | + 'pfpro.proxylogon' => array( |
|
57 | + '5.1' => true, |
|
58 | + ), |
|
59 | + 'pfpro.proxypassword' => array( |
|
60 | + '5.1' => true, |
|
61 | + ), |
|
62 | 62 | |
63 | - 'ifx.allow_persistent' => array( |
|
64 | - '5.2.1' => true, |
|
65 | - ), |
|
66 | - 'ifx.blobinfile' => array( |
|
67 | - '5.2.1' => true, |
|
68 | - ), |
|
69 | - 'ifx.byteasvarchar' => array( |
|
70 | - '5.2.1' => true, |
|
71 | - ), |
|
72 | - 'ifx.charasvarchar' => array( |
|
73 | - '5.2.1' => true, |
|
74 | - ), |
|
75 | - 'ifx.default_host' => array( |
|
76 | - '5.2.1' => true, |
|
77 | - ), |
|
78 | - 'ifx.default_password' => array( |
|
79 | - '5.2.1' => true, |
|
80 | - ), |
|
81 | - 'ifx.default_user' => array( |
|
82 | - '5.2.1' => true, |
|
83 | - ), |
|
84 | - 'ifx.max_links' => array( |
|
85 | - '5.2.1' => true, |
|
86 | - ), |
|
87 | - 'ifx.max_persistent' => array( |
|
88 | - '5.2.1' => true, |
|
89 | - ), |
|
90 | - 'ifx.nullformat' => array( |
|
91 | - '5.2.1' => true, |
|
92 | - ), |
|
93 | - 'ifx.textasvarchar' => array( |
|
94 | - '5.2.1' => true, |
|
95 | - ), |
|
63 | + 'ifx.allow_persistent' => array( |
|
64 | + '5.2.1' => true, |
|
65 | + ), |
|
66 | + 'ifx.blobinfile' => array( |
|
67 | + '5.2.1' => true, |
|
68 | + ), |
|
69 | + 'ifx.byteasvarchar' => array( |
|
70 | + '5.2.1' => true, |
|
71 | + ), |
|
72 | + 'ifx.charasvarchar' => array( |
|
73 | + '5.2.1' => true, |
|
74 | + ), |
|
75 | + 'ifx.default_host' => array( |
|
76 | + '5.2.1' => true, |
|
77 | + ), |
|
78 | + 'ifx.default_password' => array( |
|
79 | + '5.2.1' => true, |
|
80 | + ), |
|
81 | + 'ifx.default_user' => array( |
|
82 | + '5.2.1' => true, |
|
83 | + ), |
|
84 | + 'ifx.max_links' => array( |
|
85 | + '5.2.1' => true, |
|
86 | + ), |
|
87 | + 'ifx.max_persistent' => array( |
|
88 | + '5.2.1' => true, |
|
89 | + ), |
|
90 | + 'ifx.nullformat' => array( |
|
91 | + '5.2.1' => true, |
|
92 | + ), |
|
93 | + 'ifx.textasvarchar' => array( |
|
94 | + '5.2.1' => true, |
|
95 | + ), |
|
96 | 96 | |
97 | - 'zend.ze1_compatibility_mode' => array( |
|
98 | - '5.3' => true, |
|
99 | - ), |
|
97 | + 'zend.ze1_compatibility_mode' => array( |
|
98 | + '5.3' => true, |
|
99 | + ), |
|
100 | 100 | |
101 | - 'allow_call_time_pass_reference' => array( |
|
102 | - '5.3' => false, |
|
103 | - '5.4' => true, |
|
104 | - ), |
|
105 | - 'define_syslog_variables' => array( |
|
106 | - '5.3' => false, |
|
107 | - '5.4' => true, |
|
108 | - ), |
|
109 | - 'detect_unicode' => array( |
|
110 | - '5.4' => true, |
|
111 | - 'alternative' => 'zend.detect_unicode', |
|
112 | - ), |
|
113 | - 'highlight.bg' => array( |
|
114 | - '5.3' => false, |
|
115 | - '5.4' => true, |
|
116 | - ), |
|
117 | - 'magic_quotes_gpc' => array( |
|
118 | - '5.3' => false, |
|
119 | - '5.4' => true, |
|
120 | - ), |
|
121 | - 'magic_quotes_runtime' => array( |
|
122 | - '5.3' => false, |
|
123 | - '5.4' => true, |
|
124 | - ), |
|
125 | - 'magic_quotes_sybase' => array( |
|
126 | - '5.3' => false, |
|
127 | - '5.4' => true, |
|
128 | - ), |
|
129 | - 'mbstring.script_encoding' => array( |
|
130 | - '5.4' => true, |
|
131 | - 'alternative' => 'zend.script_encoding', |
|
132 | - ), |
|
133 | - 'register_globals' => array( |
|
134 | - '5.3' => false, |
|
135 | - '5.4' => true, |
|
136 | - ), |
|
137 | - 'register_long_arrays' => array( |
|
138 | - '5.3' => false, |
|
139 | - '5.4' => true, |
|
140 | - ), |
|
141 | - 'safe_mode' => array( |
|
142 | - '5.3' => false, |
|
143 | - '5.4' => true, |
|
144 | - ), |
|
145 | - 'safe_mode_allowed_env_vars' => array( |
|
146 | - '5.3' => false, |
|
147 | - '5.4' => true, |
|
148 | - ), |
|
149 | - 'safe_mode_exec_dir' => array( |
|
150 | - '5.3' => false, |
|
151 | - '5.4' => true, |
|
152 | - ), |
|
153 | - 'safe_mode_gid' => array( |
|
154 | - '5.3' => false, |
|
155 | - '5.4' => true, |
|
156 | - ), |
|
157 | - 'safe_mode_include_dir' => array( |
|
158 | - '5.3' => false, |
|
159 | - '5.4' => true, |
|
160 | - ), |
|
161 | - 'safe_mode_protected_env_vars' => array( |
|
162 | - '5.3' => false, |
|
163 | - '5.4' => true, |
|
164 | - ), |
|
165 | - 'session.bug_compat_42' => array( |
|
166 | - '5.3' => false, |
|
167 | - '5.4' => true, |
|
168 | - ), |
|
169 | - 'session.bug_compat_warn' => array( |
|
170 | - '5.3' => false, |
|
171 | - '5.4' => true, |
|
172 | - ), |
|
173 | - 'y2k_compliance' => array( |
|
174 | - '5.3' => false, |
|
175 | - '5.4' => true, |
|
176 | - ), |
|
101 | + 'allow_call_time_pass_reference' => array( |
|
102 | + '5.3' => false, |
|
103 | + '5.4' => true, |
|
104 | + ), |
|
105 | + 'define_syslog_variables' => array( |
|
106 | + '5.3' => false, |
|
107 | + '5.4' => true, |
|
108 | + ), |
|
109 | + 'detect_unicode' => array( |
|
110 | + '5.4' => true, |
|
111 | + 'alternative' => 'zend.detect_unicode', |
|
112 | + ), |
|
113 | + 'highlight.bg' => array( |
|
114 | + '5.3' => false, |
|
115 | + '5.4' => true, |
|
116 | + ), |
|
117 | + 'magic_quotes_gpc' => array( |
|
118 | + '5.3' => false, |
|
119 | + '5.4' => true, |
|
120 | + ), |
|
121 | + 'magic_quotes_runtime' => array( |
|
122 | + '5.3' => false, |
|
123 | + '5.4' => true, |
|
124 | + ), |
|
125 | + 'magic_quotes_sybase' => array( |
|
126 | + '5.3' => false, |
|
127 | + '5.4' => true, |
|
128 | + ), |
|
129 | + 'mbstring.script_encoding' => array( |
|
130 | + '5.4' => true, |
|
131 | + 'alternative' => 'zend.script_encoding', |
|
132 | + ), |
|
133 | + 'register_globals' => array( |
|
134 | + '5.3' => false, |
|
135 | + '5.4' => true, |
|
136 | + ), |
|
137 | + 'register_long_arrays' => array( |
|
138 | + '5.3' => false, |
|
139 | + '5.4' => true, |
|
140 | + ), |
|
141 | + 'safe_mode' => array( |
|
142 | + '5.3' => false, |
|
143 | + '5.4' => true, |
|
144 | + ), |
|
145 | + 'safe_mode_allowed_env_vars' => array( |
|
146 | + '5.3' => false, |
|
147 | + '5.4' => true, |
|
148 | + ), |
|
149 | + 'safe_mode_exec_dir' => array( |
|
150 | + '5.3' => false, |
|
151 | + '5.4' => true, |
|
152 | + ), |
|
153 | + 'safe_mode_gid' => array( |
|
154 | + '5.3' => false, |
|
155 | + '5.4' => true, |
|
156 | + ), |
|
157 | + 'safe_mode_include_dir' => array( |
|
158 | + '5.3' => false, |
|
159 | + '5.4' => true, |
|
160 | + ), |
|
161 | + 'safe_mode_protected_env_vars' => array( |
|
162 | + '5.3' => false, |
|
163 | + '5.4' => true, |
|
164 | + ), |
|
165 | + 'session.bug_compat_42' => array( |
|
166 | + '5.3' => false, |
|
167 | + '5.4' => true, |
|
168 | + ), |
|
169 | + 'session.bug_compat_warn' => array( |
|
170 | + '5.3' => false, |
|
171 | + '5.4' => true, |
|
172 | + ), |
|
173 | + 'y2k_compliance' => array( |
|
174 | + '5.3' => false, |
|
175 | + '5.4' => true, |
|
176 | + ), |
|
177 | 177 | |
178 | - 'always_populate_raw_post_data' => array( |
|
179 | - '5.6' => false, |
|
180 | - '7.0' => true, |
|
181 | - ), |
|
182 | - 'iconv.input_encoding' => array( |
|
183 | - '5.6' => false, |
|
184 | - ), |
|
185 | - 'iconv.output_encoding' => array( |
|
186 | - '5.6' => false, |
|
187 | - ), |
|
188 | - 'iconv.internal_encoding' => array( |
|
189 | - '5.6' => false, |
|
190 | - ), |
|
191 | - 'mbstring.http_input' => array( |
|
192 | - '5.6' => false, |
|
193 | - ), |
|
194 | - 'mbstring.http_output' => array( |
|
195 | - '5.6' => false, |
|
196 | - ), |
|
197 | - 'mbstring.internal_encoding' => array( |
|
198 | - '5.6' => false, |
|
199 | - ), |
|
178 | + 'always_populate_raw_post_data' => array( |
|
179 | + '5.6' => false, |
|
180 | + '7.0' => true, |
|
181 | + ), |
|
182 | + 'iconv.input_encoding' => array( |
|
183 | + '5.6' => false, |
|
184 | + ), |
|
185 | + 'iconv.output_encoding' => array( |
|
186 | + '5.6' => false, |
|
187 | + ), |
|
188 | + 'iconv.internal_encoding' => array( |
|
189 | + '5.6' => false, |
|
190 | + ), |
|
191 | + 'mbstring.http_input' => array( |
|
192 | + '5.6' => false, |
|
193 | + ), |
|
194 | + 'mbstring.http_output' => array( |
|
195 | + '5.6' => false, |
|
196 | + ), |
|
197 | + 'mbstring.internal_encoding' => array( |
|
198 | + '5.6' => false, |
|
199 | + ), |
|
200 | 200 | |
201 | - 'asp_tags' => array( |
|
202 | - '7.0' => true, |
|
203 | - ), |
|
204 | - 'xsl.security_prefs' => array( |
|
205 | - '7.0' => true, |
|
206 | - ), |
|
201 | + 'asp_tags' => array( |
|
202 | + '7.0' => true, |
|
203 | + ), |
|
204 | + 'xsl.security_prefs' => array( |
|
205 | + '7.0' => true, |
|
206 | + ), |
|
207 | 207 | |
208 | - 'mcrypt.algorithms_dir' => array( |
|
209 | - '7.1' => false, |
|
210 | - '7.2' => true, |
|
211 | - ), |
|
212 | - 'mcrypt.modes_dir' => array( |
|
213 | - '7.1' => false, |
|
214 | - '7.2' => true, |
|
215 | - ), |
|
216 | - 'session.entropy_file' => array( |
|
217 | - '7.1' => true, |
|
218 | - ), |
|
219 | - 'session.entropy_length' => array( |
|
220 | - '7.1' => true, |
|
221 | - ), |
|
222 | - 'session.hash_function' => array( |
|
223 | - '7.1' => true, |
|
224 | - ), |
|
225 | - 'session.hash_bits_per_character' => array( |
|
226 | - '7.1' => true, |
|
227 | - ), |
|
208 | + 'mcrypt.algorithms_dir' => array( |
|
209 | + '7.1' => false, |
|
210 | + '7.2' => true, |
|
211 | + ), |
|
212 | + 'mcrypt.modes_dir' => array( |
|
213 | + '7.1' => false, |
|
214 | + '7.2' => true, |
|
215 | + ), |
|
216 | + 'session.entropy_file' => array( |
|
217 | + '7.1' => true, |
|
218 | + ), |
|
219 | + 'session.entropy_length' => array( |
|
220 | + '7.1' => true, |
|
221 | + ), |
|
222 | + 'session.hash_function' => array( |
|
223 | + '7.1' => true, |
|
224 | + ), |
|
225 | + 'session.hash_bits_per_character' => array( |
|
226 | + '7.1' => true, |
|
227 | + ), |
|
228 | 228 | |
229 | - 'mbstring.func_overload' => array( |
|
230 | - '7.2' => false, |
|
231 | - ), |
|
232 | - 'sql.safe_mode' => array( |
|
233 | - '7.2' => true, |
|
234 | - ), |
|
235 | - 'track_errors' => array( |
|
236 | - '7.2' => false, |
|
237 | - ), |
|
238 | - 'opcache.fast_shutdown' => array( |
|
239 | - '7.2' => true, |
|
240 | - ), |
|
229 | + 'mbstring.func_overload' => array( |
|
230 | + '7.2' => false, |
|
231 | + ), |
|
232 | + 'sql.safe_mode' => array( |
|
233 | + '7.2' => true, |
|
234 | + ), |
|
235 | + 'track_errors' => array( |
|
236 | + '7.2' => false, |
|
237 | + ), |
|
238 | + 'opcache.fast_shutdown' => array( |
|
239 | + '7.2' => true, |
|
240 | + ), |
|
241 | 241 | |
242 | - 'birdstep.max_links' => array( |
|
243 | - '7.3' => true, |
|
244 | - ), |
|
245 | - 'opcache.inherited_hack' => array( |
|
246 | - '5.3' => false, // Soft deprecated, i.e. ignored. |
|
247 | - '7.3' => true, |
|
248 | - ), |
|
249 | - 'pdo_odbc.db2_instance_name' => array( |
|
250 | - '7.3' => false, // Has been marked as deprecated in the manual from before this time. Now hard-deprecated. |
|
251 | - ), |
|
242 | + 'birdstep.max_links' => array( |
|
243 | + '7.3' => true, |
|
244 | + ), |
|
245 | + 'opcache.inherited_hack' => array( |
|
246 | + '5.3' => false, // Soft deprecated, i.e. ignored. |
|
247 | + '7.3' => true, |
|
248 | + ), |
|
249 | + 'pdo_odbc.db2_instance_name' => array( |
|
250 | + '7.3' => false, // Has been marked as deprecated in the manual from before this time. Now hard-deprecated. |
|
251 | + ), |
|
252 | 252 | |
253 | - 'ibase.allow_persistent' => array( |
|
254 | - '7.4' => true, |
|
255 | - ), |
|
256 | - 'ibase.max_persistent' => array( |
|
257 | - '7.4' => true, |
|
258 | - ), |
|
259 | - 'ibase.max_links' => array( |
|
260 | - '7.4' => true, |
|
261 | - ), |
|
262 | - 'ibase.default_db' => array( |
|
263 | - '7.4' => true, |
|
264 | - ), |
|
265 | - 'ibase.default_user' => array( |
|
266 | - '7.4' => true, |
|
267 | - ), |
|
268 | - 'ibase.default_password' => array( |
|
269 | - '7.4' => true, |
|
270 | - ), |
|
271 | - 'ibase.default_charset' => array( |
|
272 | - '7.4' => true, |
|
273 | - ), |
|
274 | - 'ibase.timestampformat' => array( |
|
275 | - '7.4' => true, |
|
276 | - ), |
|
277 | - 'ibase.dateformat' => array( |
|
278 | - '7.4' => true, |
|
279 | - ), |
|
280 | - 'ibase.timeformat' => array( |
|
281 | - '7.4' => true, |
|
282 | - ), |
|
283 | - ); |
|
253 | + 'ibase.allow_persistent' => array( |
|
254 | + '7.4' => true, |
|
255 | + ), |
|
256 | + 'ibase.max_persistent' => array( |
|
257 | + '7.4' => true, |
|
258 | + ), |
|
259 | + 'ibase.max_links' => array( |
|
260 | + '7.4' => true, |
|
261 | + ), |
|
262 | + 'ibase.default_db' => array( |
|
263 | + '7.4' => true, |
|
264 | + ), |
|
265 | + 'ibase.default_user' => array( |
|
266 | + '7.4' => true, |
|
267 | + ), |
|
268 | + 'ibase.default_password' => array( |
|
269 | + '7.4' => true, |
|
270 | + ), |
|
271 | + 'ibase.default_charset' => array( |
|
272 | + '7.4' => true, |
|
273 | + ), |
|
274 | + 'ibase.timestampformat' => array( |
|
275 | + '7.4' => true, |
|
276 | + ), |
|
277 | + 'ibase.dateformat' => array( |
|
278 | + '7.4' => true, |
|
279 | + ), |
|
280 | + 'ibase.timeformat' => array( |
|
281 | + '7.4' => true, |
|
282 | + ), |
|
283 | + ); |
|
284 | 284 | |
285 | - /** |
|
286 | - * Returns an array of tokens this test wants to listen for. |
|
287 | - * |
|
288 | - * @return array |
|
289 | - */ |
|
290 | - public function register() |
|
291 | - { |
|
292 | - return array(\T_STRING); |
|
293 | - } |
|
285 | + /** |
|
286 | + * Returns an array of tokens this test wants to listen for. |
|
287 | + * |
|
288 | + * @return array |
|
289 | + */ |
|
290 | + public function register() |
|
291 | + { |
|
292 | + return array(\T_STRING); |
|
293 | + } |
|
294 | 294 | |
295 | - /** |
|
296 | - * Processes this test, when one of its tokens is encountered. |
|
297 | - * |
|
298 | - * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
299 | - * @param int $stackPtr The position of the current token in the |
|
300 | - * stack passed in $tokens. |
|
301 | - * |
|
302 | - * @return void |
|
303 | - */ |
|
304 | - public function process(File $phpcsFile, $stackPtr) |
|
305 | - { |
|
306 | - $tokens = $phpcsFile->getTokens(); |
|
295 | + /** |
|
296 | + * Processes this test, when one of its tokens is encountered. |
|
297 | + * |
|
298 | + * @param \PHP_CodeSniffer_File $phpcsFile The file being scanned. |
|
299 | + * @param int $stackPtr The position of the current token in the |
|
300 | + * stack passed in $tokens. |
|
301 | + * |
|
302 | + * @return void |
|
303 | + */ |
|
304 | + public function process(File $phpcsFile, $stackPtr) |
|
305 | + { |
|
306 | + $tokens = $phpcsFile->getTokens(); |
|
307 | 307 | |
308 | - $ignore = array( |
|
309 | - \T_DOUBLE_COLON => true, |
|
310 | - \T_OBJECT_OPERATOR => true, |
|
311 | - \T_FUNCTION => true, |
|
312 | - \T_CONST => true, |
|
313 | - ); |
|
308 | + $ignore = array( |
|
309 | + \T_DOUBLE_COLON => true, |
|
310 | + \T_OBJECT_OPERATOR => true, |
|
311 | + \T_FUNCTION => true, |
|
312 | + \T_CONST => true, |
|
313 | + ); |
|
314 | 314 | |
315 | - $prevToken = $phpcsFile->findPrevious(\T_WHITESPACE, ($stackPtr - 1), null, true); |
|
316 | - if (isset($ignore[$tokens[$prevToken]['code']]) === true) { |
|
317 | - // Not a call to a PHP function. |
|
318 | - return; |
|
319 | - } |
|
315 | + $prevToken = $phpcsFile->findPrevious(\T_WHITESPACE, ($stackPtr - 1), null, true); |
|
316 | + if (isset($ignore[$tokens[$prevToken]['code']]) === true) { |
|
317 | + // Not a call to a PHP function. |
|
318 | + return; |
|
319 | + } |
|
320 | 320 | |
321 | - $functionLc = strtolower($tokens[$stackPtr]['content']); |
|
322 | - if (isset($this->iniFunctions[$functionLc]) === false) { |
|
323 | - return; |
|
324 | - } |
|
321 | + $functionLc = strtolower($tokens[$stackPtr]['content']); |
|
322 | + if (isset($this->iniFunctions[$functionLc]) === false) { |
|
323 | + return; |
|
324 | + } |
|
325 | 325 | |
326 | - $iniToken = $this->getFunctionCallParameter($phpcsFile, $stackPtr, $this->iniFunctions[$functionLc]); |
|
327 | - if ($iniToken === false) { |
|
328 | - return; |
|
329 | - } |
|
326 | + $iniToken = $this->getFunctionCallParameter($phpcsFile, $stackPtr, $this->iniFunctions[$functionLc]); |
|
327 | + if ($iniToken === false) { |
|
328 | + return; |
|
329 | + } |
|
330 | 330 | |
331 | - $filteredToken = $this->stripQuotes($iniToken['raw']); |
|
332 | - if (isset($this->deprecatedIniDirectives[$filteredToken]) === false) { |
|
333 | - return; |
|
334 | - } |
|
331 | + $filteredToken = $this->stripQuotes($iniToken['raw']); |
|
332 | + if (isset($this->deprecatedIniDirectives[$filteredToken]) === false) { |
|
333 | + return; |
|
334 | + } |
|
335 | 335 | |
336 | - $itemInfo = array( |
|
337 | - 'name' => $filteredToken, |
|
338 | - 'functionLc' => $functionLc, |
|
339 | - ); |
|
340 | - $this->handleFeature($phpcsFile, $iniToken['end'], $itemInfo); |
|
341 | - } |
|
336 | + $itemInfo = array( |
|
337 | + 'name' => $filteredToken, |
|
338 | + 'functionLc' => $functionLc, |
|
339 | + ); |
|
340 | + $this->handleFeature($phpcsFile, $iniToken['end'], $itemInfo); |
|
341 | + } |
|
342 | 342 | |
343 | 343 | |
344 | - /** |
|
345 | - * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
346 | - * |
|
347 | - * @param array $itemInfo Base information about the item. |
|
348 | - * |
|
349 | - * @return array Version and other information about the item. |
|
350 | - */ |
|
351 | - public function getItemArray(array $itemInfo) |
|
352 | - { |
|
353 | - return $this->deprecatedIniDirectives[$itemInfo['name']]; |
|
354 | - } |
|
344 | + /** |
|
345 | + * Get the relevant sub-array for a specific item from a multi-dimensional array. |
|
346 | + * |
|
347 | + * @param array $itemInfo Base information about the item. |
|
348 | + * |
|
349 | + * @return array Version and other information about the item. |
|
350 | + */ |
|
351 | + public function getItemArray(array $itemInfo) |
|
352 | + { |
|
353 | + return $this->deprecatedIniDirectives[$itemInfo['name']]; |
|
354 | + } |
|
355 | 355 | |
356 | 356 | |
357 | - /** |
|
358 | - * Retrieve the relevant detail (version) information for use in an error message. |
|
359 | - * |
|
360 | - * @param array $itemArray Version and other information about the item. |
|
361 | - * @param array $itemInfo Base information about the item. |
|
362 | - * |
|
363 | - * @return array |
|
364 | - */ |
|
365 | - public function getErrorInfo(array $itemArray, array $itemInfo) |
|
366 | - { |
|
367 | - $errorInfo = parent::getErrorInfo($itemArray, $itemInfo); |
|
357 | + /** |
|
358 | + * Retrieve the relevant detail (version) information for use in an error message. |
|
359 | + * |
|
360 | + * @param array $itemArray Version and other information about the item. |
|
361 | + * @param array $itemInfo Base information about the item. |
|
362 | + * |
|
363 | + * @return array |
|
364 | + */ |
|
365 | + public function getErrorInfo(array $itemArray, array $itemInfo) |
|
366 | + { |
|
367 | + $errorInfo = parent::getErrorInfo($itemArray, $itemInfo); |
|
368 | 368 | |
369 | - // Lower error level to warning if the function used was ini_get. |
|
370 | - if ($errorInfo['error'] === true && $itemInfo['functionLc'] === 'ini_get') { |
|
371 | - $errorInfo['error'] = false; |
|
372 | - } |
|
369 | + // Lower error level to warning if the function used was ini_get. |
|
370 | + if ($errorInfo['error'] === true && $itemInfo['functionLc'] === 'ini_get') { |
|
371 | + $errorInfo['error'] = false; |
|
372 | + } |
|
373 | 373 | |
374 | - return $errorInfo; |
|
375 | - } |
|
374 | + return $errorInfo; |
|
375 | + } |
|
376 | 376 | |
377 | 377 | |
378 | - /** |
|
379 | - * Get the error message template for this sniff. |
|
380 | - * |
|
381 | - * @return string |
|
382 | - */ |
|
383 | - protected function getErrorMsgTemplate() |
|
384 | - { |
|
385 | - return "INI directive '%s' is "; |
|
386 | - } |
|
378 | + /** |
|
379 | + * Get the error message template for this sniff. |
|
380 | + * |
|
381 | + * @return string |
|
382 | + */ |
|
383 | + protected function getErrorMsgTemplate() |
|
384 | + { |
|
385 | + return "INI directive '%s' is "; |
|
386 | + } |
|
387 | 387 | |
388 | 388 | |
389 | - /** |
|
390 | - * Get the error message template for suggesting an alternative for a specific sniff. |
|
391 | - * |
|
392 | - * @return string |
|
393 | - */ |
|
394 | - protected function getAlternativeOptionTemplate() |
|
395 | - { |
|
396 | - return str_replace("%s", "'%s'", parent::getAlternativeOptionTemplate()); |
|
397 | - } |
|
389 | + /** |
|
390 | + * Get the error message template for suggesting an alternative for a specific sniff. |
|
391 | + * |
|
392 | + * @return string |
|
393 | + */ |
|
394 | + protected function getAlternativeOptionTemplate() |
|
395 | + { |
|
396 | + return str_replace("%s", "'%s'", parent::getAlternativeOptionTemplate()); |
|
397 | + } |
|
398 | 398 | } |