@@ -190,26 +190,26 @@ discard block |
||
190 | 190 | |
191 | 191 | $this->mergeFunctionLists(); |
192 | 192 | |
193 | - $function = $this->tokens[ $stackPtr ]['content']; |
|
193 | + $function = $this->tokens[ $stackPtr ][ 'content' ]; |
|
194 | 194 | |
195 | 195 | // Find the opening parenthesis (if present; T_ECHO might not have it). |
196 | 196 | $open_paren = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); |
197 | 197 | |
198 | 198 | // If function, not T_ECHO nor T_PRINT. |
199 | - if ( \T_STRING === $this->tokens[ $stackPtr ]['code'] ) { |
|
199 | + if ( \T_STRING === $this->tokens[ $stackPtr ][ 'code' ] ) { |
|
200 | 200 | // Skip if it is a function but is not one of the printing functions. |
201 | - if ( ! isset( $this->printingFunctions[ $this->tokens[ $stackPtr ]['content'] ] ) ) { |
|
201 | + if ( ! isset( $this->printingFunctions[ $this->tokens[ $stackPtr ][ 'content' ] ] ) ) { |
|
202 | 202 | return; |
203 | 203 | } |
204 | 204 | |
205 | - if ( isset( $this->tokens[ $open_paren ]['parenthesis_closer'] ) ) { |
|
206 | - $end_of_statement = $this->tokens[ $open_paren ]['parenthesis_closer']; |
|
205 | + if ( isset( $this->tokens[ $open_paren ][ 'parenthesis_closer' ] ) ) { |
|
206 | + $end_of_statement = $this->tokens[ $open_paren ][ 'parenthesis_closer' ]; |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | // These functions only need to have the first argument escaped. |
210 | 210 | if ( \in_array( $function, array( 'trigger_error', 'user_error' ), true ) ) { |
211 | 211 | $first_param = $this->get_function_call_parameter( $stackPtr, 1 ); |
212 | - $end_of_statement = ( $first_param['end'] + 1 ); |
|
212 | + $end_of_statement = ( $first_param[ 'end' ] + 1 ); |
|
213 | 213 | unset( $first_param ); |
214 | 214 | } |
215 | 215 | } |
@@ -243,13 +243,13 @@ discard block |
||
243 | 243 | |
244 | 244 | // Check for the ternary operator. We only need to do this here if this |
245 | 245 | // echo is lacking parenthesis. Otherwise it will be handled below. |
246 | - if ( \T_OPEN_PARENTHESIS !== $this->tokens[ $open_paren ]['code'] || \T_CLOSE_PARENTHESIS !== $this->tokens[ $last_token ]['code'] ) { |
|
246 | + if ( \T_OPEN_PARENTHESIS !== $this->tokens[ $open_paren ][ 'code' ] || \T_CLOSE_PARENTHESIS !== $this->tokens[ $last_token ][ 'code' ] ) { |
|
247 | 247 | |
248 | 248 | $ternary = $this->phpcsFile->findNext( \T_INLINE_THEN, $stackPtr, $end_of_statement ); |
249 | 249 | |
250 | 250 | // If there is a ternary skip over the part before the ?. However, if |
251 | 251 | // the ternary is within parentheses, it will be handled in the loop. |
252 | - if ( false !== $ternary && empty( $this->tokens[ $ternary ]['nested_parenthesis'] ) ) { |
|
252 | + if ( false !== $ternary && empty( $this->tokens[ $ternary ][ 'nested_parenthesis' ] ) ) { |
|
253 | 253 | $stackPtr = $ternary; |
254 | 254 | } |
255 | 255 | } |
@@ -265,18 +265,18 @@ discard block |
||
265 | 265 | for ( $i = $stackPtr; $i < $end_of_statement; $i++ ) { |
266 | 266 | |
267 | 267 | // Ignore whitespaces and comments. |
268 | - if ( isset( Tokens::$emptyTokens[ $this->tokens[ $i ]['code'] ] ) ) { |
|
268 | + if ( isset( Tokens::$emptyTokens[ $this->tokens[ $i ][ 'code' ] ] ) ) { |
|
269 | 269 | continue; |
270 | 270 | } |
271 | 271 | |
272 | 272 | // Ignore namespace separators. |
273 | - if ( \T_NS_SEPARATOR === $this->tokens[ $i ]['code'] ) { |
|
273 | + if ( \T_NS_SEPARATOR === $this->tokens[ $i ][ 'code' ] ) { |
|
274 | 274 | continue; |
275 | 275 | } |
276 | 276 | |
277 | - if ( \T_OPEN_PARENTHESIS === $this->tokens[ $i ]['code'] ) { |
|
277 | + if ( \T_OPEN_PARENTHESIS === $this->tokens[ $i ][ 'code' ] ) { |
|
278 | 278 | |
279 | - if ( ! isset( $this->tokens[ $i ]['parenthesis_closer'] ) ) { |
|
279 | + if ( ! isset( $this->tokens[ $i ][ 'parenthesis_closer' ] ) ) { |
|
280 | 280 | // Live coding or parse error. |
281 | 281 | break; |
282 | 282 | } |
@@ -284,20 +284,20 @@ discard block |
||
284 | 284 | if ( $in_cast ) { |
285 | 285 | |
286 | 286 | // Skip to the end of a function call if it has been casted to a safe value. |
287 | - $i = $this->tokens[ $i ]['parenthesis_closer']; |
|
287 | + $i = $this->tokens[ $i ][ 'parenthesis_closer' ]; |
|
288 | 288 | $in_cast = false; |
289 | 289 | |
290 | 290 | } else { |
291 | 291 | |
292 | 292 | // Skip over the condition part of a ternary (i.e., to after the ?). |
293 | - $ternary = $this->phpcsFile->findNext( \T_INLINE_THEN, $i, $this->tokens[ $i ]['parenthesis_closer'] ); |
|
293 | + $ternary = $this->phpcsFile->findNext( \T_INLINE_THEN, $i, $this->tokens[ $i ][ 'parenthesis_closer' ] ); |
|
294 | 294 | |
295 | 295 | if ( false !== $ternary ) { |
296 | 296 | |
297 | - $next_paren = $this->phpcsFile->findNext( \T_OPEN_PARENTHESIS, ( $i + 1 ), $this->tokens[ $i ]['parenthesis_closer'] ); |
|
297 | + $next_paren = $this->phpcsFile->findNext( \T_OPEN_PARENTHESIS, ( $i + 1 ), $this->tokens[ $i ][ 'parenthesis_closer' ] ); |
|
298 | 298 | |
299 | 299 | // We only do it if the ternary isn't within a subset of parentheses. |
300 | - if ( false === $next_paren || ( isset( $this->tokens[ $next_paren ]['parenthesis_closer'] ) && $ternary > $this->tokens[ $next_paren ]['parenthesis_closer'] ) ) { |
|
300 | + if ( false === $next_paren || ( isset( $this->tokens[ $next_paren ][ 'parenthesis_closer' ] ) && $ternary > $this->tokens[ $next_paren ][ 'parenthesis_closer' ] ) ) { |
|
301 | 301 | $i = $ternary; |
302 | 302 | } |
303 | 303 | } |
@@ -307,48 +307,48 @@ discard block |
||
307 | 307 | } |
308 | 308 | |
309 | 309 | // Handle arrays for those functions that accept them. |
310 | - if ( \T_ARRAY === $this->tokens[ $i ]['code'] ) { |
|
310 | + if ( \T_ARRAY === $this->tokens[ $i ][ 'code' ] ) { |
|
311 | 311 | $i++; // Skip the opening parenthesis. |
312 | 312 | continue; |
313 | 313 | } |
314 | 314 | |
315 | - if ( \T_OPEN_SHORT_ARRAY === $this->tokens[ $i ]['code'] |
|
316 | - || \T_CLOSE_SHORT_ARRAY === $this->tokens[ $i ]['code'] |
|
315 | + if ( \T_OPEN_SHORT_ARRAY === $this->tokens[ $i ][ 'code' ] |
|
316 | + || \T_CLOSE_SHORT_ARRAY === $this->tokens[ $i ][ 'code' ] |
|
317 | 317 | ) { |
318 | 318 | continue; |
319 | 319 | } |
320 | 320 | |
321 | - if ( \in_array( $this->tokens[ $i ]['code'], array( \T_DOUBLE_ARROW, \T_CLOSE_PARENTHESIS ), true ) ) { |
|
321 | + if ( \in_array( $this->tokens[ $i ][ 'code' ], array( \T_DOUBLE_ARROW, \T_CLOSE_PARENTHESIS ), true ) ) { |
|
322 | 322 | continue; |
323 | 323 | } |
324 | 324 | |
325 | 325 | // Handle magic constants for debug functions. |
326 | - if ( isset( $this->magic_constant_tokens[ $this->tokens[ $i ]['type'] ] ) ) { |
|
326 | + if ( isset( $this->magic_constant_tokens[ $this->tokens[ $i ][ 'type' ] ] ) ) { |
|
327 | 327 | continue; |
328 | 328 | } |
329 | 329 | |
330 | 330 | // Handle safe PHP native constants. |
331 | - if ( \T_STRING === $this->tokens[ $i ]['code'] |
|
332 | - && isset( $this->safe_php_constants[ $this->tokens[ $i ]['content'] ] ) |
|
331 | + if ( \T_STRING === $this->tokens[ $i ][ 'code' ] |
|
332 | + && isset( $this->safe_php_constants[ $this->tokens[ $i ][ 'content' ] ] ) |
|
333 | 333 | && $this->is_use_of_global_constant( $i ) |
334 | 334 | ) { |
335 | 335 | continue; |
336 | 336 | } |
337 | 337 | |
338 | 338 | // Wake up on concatenation characters, another part to check. |
339 | - if ( \T_STRING_CONCAT === $this->tokens[ $i ]['code'] ) { |
|
339 | + if ( \T_STRING_CONCAT === $this->tokens[ $i ][ 'code' ] ) { |
|
340 | 340 | $watch = true; |
341 | 341 | continue; |
342 | 342 | } |
343 | 343 | |
344 | 344 | // Wake up after a ternary else (:). |
345 | - if ( false !== $ternary && \T_INLINE_ELSE === $this->tokens[ $i ]['code'] ) { |
|
345 | + if ( false !== $ternary && \T_INLINE_ELSE === $this->tokens[ $i ][ 'code' ] ) { |
|
346 | 346 | $watch = true; |
347 | 347 | continue; |
348 | 348 | } |
349 | 349 | |
350 | 350 | // Wake up for commas. |
351 | - if ( \T_COMMA === $this->tokens[ $i ]['code'] ) { |
|
351 | + if ( \T_COMMA === $this->tokens[ $i ][ 'code' ] ) { |
|
352 | 352 | $in_cast = false; |
353 | 353 | $watch = true; |
354 | 354 | continue; |
@@ -360,23 +360,23 @@ discard block |
||
360 | 360 | |
361 | 361 | // Allow T_CONSTANT_ENCAPSED_STRING eg: echo 'Some String'; |
362 | 362 | // Also T_LNUMBER, e.g.: echo 45; exit -1; and booleans. |
363 | - if ( isset( $this->safe_components[ $this->tokens[ $i ]['type'] ] ) ) { |
|
363 | + if ( isset( $this->safe_components[ $this->tokens[ $i ][ 'type' ] ] ) ) { |
|
364 | 364 | continue; |
365 | 365 | } |
366 | 366 | |
367 | 367 | $watch = false; |
368 | 368 | |
369 | 369 | // Allow int/double/bool casted variables. |
370 | - if ( isset( $this->safe_cast_tokens[ $this->tokens[ $i ]['type'] ] ) ) { |
|
370 | + if ( isset( $this->safe_cast_tokens[ $this->tokens[ $i ][ 'type' ] ] ) ) { |
|
371 | 371 | $in_cast = true; |
372 | 372 | continue; |
373 | 373 | } |
374 | 374 | |
375 | 375 | // Now check that next token is a function call. |
376 | - if ( \T_STRING === $this->tokens[ $i ]['code'] ) { |
|
376 | + if ( \T_STRING === $this->tokens[ $i ][ 'code' ] ) { |
|
377 | 377 | |
378 | 378 | $ptr = $i; |
379 | - $functionName = $this->tokens[ $i ]['content']; |
|
379 | + $functionName = $this->tokens[ $i ][ 'content' ]; |
|
380 | 380 | $function_opener = $this->phpcsFile->findNext( \T_OPEN_PARENTHESIS, ( $i + 1 ), null, false, null, true ); |
381 | 381 | $is_formatting_function = isset( $this->formattingFunctions[ $functionName ] ); |
382 | 382 | |
@@ -397,15 +397,15 @@ discard block |
||
397 | 397 | */ |
398 | 398 | $mapped_function = $this->phpcsFile->findNext( |
399 | 399 | Tokens::$emptyTokens, |
400 | - $callback['start'], |
|
401 | - ( $callback['end'] + 1 ), |
|
400 | + $callback[ 'start' ], |
|
401 | + ( $callback[ 'end' ] + 1 ), |
|
402 | 402 | true |
403 | 403 | ); |
404 | 404 | |
405 | 405 | if ( false !== $mapped_function |
406 | - && \T_CONSTANT_ENCAPSED_STRING === $this->tokens[ $mapped_function ]['code'] |
|
406 | + && \T_CONSTANT_ENCAPSED_STRING === $this->tokens[ $mapped_function ][ 'code' ] |
|
407 | 407 | ) { |
408 | - $functionName = $this->strip_quotes( $this->tokens[ $mapped_function ]['content'] ); |
|
408 | + $functionName = $this->strip_quotes( $this->tokens[ $mapped_function ][ 'content' ] ); |
|
409 | 409 | $ptr = $mapped_function; |
410 | 410 | } |
411 | 411 | } |
@@ -418,8 +418,8 @@ discard block |
||
418 | 418 | $i = ( $function_opener + 1 ); |
419 | 419 | $watch = true; |
420 | 420 | } else { |
421 | - if ( isset( $this->tokens[ $function_opener ]['parenthesis_closer'] ) ) { |
|
422 | - $i = $this->tokens[ $function_opener ]['parenthesis_closer']; |
|
421 | + if ( isset( $this->tokens[ $function_opener ][ 'parenthesis_closer' ] ) ) { |
|
422 | + $i = $this->tokens[ $function_opener ][ 'parenthesis_closer' ]; |
|
423 | 423 | } else { |
424 | 424 | // Live coding or parse error. |
425 | 425 | break; |
@@ -439,7 +439,7 @@ discard block |
||
439 | 439 | $content = $functionName; |
440 | 440 | |
441 | 441 | } else { |
442 | - $content = $this->tokens[ $i ]['content']; |
|
442 | + $content = $this->tokens[ $i ][ 'content' ]; |
|
443 | 443 | $ptr = $i; |
444 | 444 | } |
445 | 445 | |
@@ -462,7 +462,7 @@ discard block |
||
462 | 462 | * @return void |
463 | 463 | */ |
464 | 464 | protected function mergeFunctionLists() { |
465 | - if ( $this->customEscapingFunctions !== $this->addedCustomFunctions['escape'] ) { |
|
465 | + if ( $this->customEscapingFunctions !== $this->addedCustomFunctions[ 'escape' ] ) { |
|
466 | 466 | $customEscapeFunctions = $this->merge_custom_array( $this->customEscapingFunctions, array(), false ); |
467 | 467 | |
468 | 468 | $this->escapingFunctions = $this->merge_custom_array( |
@@ -470,26 +470,26 @@ discard block |
||
470 | 470 | $this->escapingFunctions |
471 | 471 | ); |
472 | 472 | |
473 | - $this->addedCustomFunctions['escape'] = $this->customEscapingFunctions; |
|
473 | + $this->addedCustomFunctions[ 'escape' ] = $this->customEscapingFunctions; |
|
474 | 474 | } |
475 | 475 | |
476 | - if ( $this->customAutoEscapedFunctions !== $this->addedCustomFunctions['autoescape'] ) { |
|
476 | + if ( $this->customAutoEscapedFunctions !== $this->addedCustomFunctions[ 'autoescape' ] ) { |
|
477 | 477 | $this->autoEscapedFunctions = $this->merge_custom_array( |
478 | 478 | $this->customAutoEscapedFunctions, |
479 | 479 | $this->autoEscapedFunctions |
480 | 480 | ); |
481 | 481 | |
482 | - $this->addedCustomFunctions['autoescape'] = $this->customAutoEscapedFunctions; |
|
482 | + $this->addedCustomFunctions[ 'autoescape' ] = $this->customAutoEscapedFunctions; |
|
483 | 483 | } |
484 | 484 | |
485 | - if ( $this->customPrintingFunctions !== $this->addedCustomFunctions['print'] ) { |
|
485 | + if ( $this->customPrintingFunctions !== $this->addedCustomFunctions[ 'print' ] ) { |
|
486 | 486 | |
487 | 487 | $this->printingFunctions = $this->merge_custom_array( |
488 | 488 | $this->customPrintingFunctions, |
489 | 489 | $this->printingFunctions |
490 | 490 | ); |
491 | 491 | |
492 | - $this->addedCustomFunctions['print'] = $this->customPrintingFunctions; |
|
492 | + $this->addedCustomFunctions[ 'print' ] = $this->customPrintingFunctions; |
|
493 | 493 | } |
494 | 494 | } |
495 | 495 |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | |
108 | 108 | $instance = $this->tokens[ $stackPtr ]; |
109 | 109 | |
110 | - if ( ! isset( $this->superglobals[ $instance['content'] ] ) ) { |
|
110 | + if ( ! isset( $this->superglobals[ $instance[ 'content' ] ] ) ) { |
|
111 | 111 | return; |
112 | 112 | } |
113 | 113 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | } |
127 | 127 | |
128 | 128 | $error_code = 'Missing'; |
129 | - if ( false === $this->superglobals[ $instance['content'] ] ) { |
|
129 | + if ( false === $this->superglobals[ $instance[ 'content' ] ] ) { |
|
130 | 130 | $error_code = 'Recommended'; |
131 | 131 | } |
132 | 132 | |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | $this->addMessage( |
135 | 135 | 'Processing form data without nonce verification.', |
136 | 136 | $stackPtr, |
137 | - $this->superglobals[ $instance['content'] ], |
|
137 | + $this->superglobals[ $instance[ 'content' ] ], |
|
138 | 138 | $error_code |
139 | 139 | ); |
140 | 140 | } |
@@ -147,31 +147,31 @@ discard block |
||
147 | 147 | * @return void |
148 | 148 | */ |
149 | 149 | protected function mergeFunctionLists() { |
150 | - if ( $this->customNonceVerificationFunctions !== $this->addedCustomFunctions['nonce'] ) { |
|
150 | + if ( $this->customNonceVerificationFunctions !== $this->addedCustomFunctions[ 'nonce' ] ) { |
|
151 | 151 | $this->nonceVerificationFunctions = $this->merge_custom_array( |
152 | 152 | $this->customNonceVerificationFunctions, |
153 | 153 | $this->nonceVerificationFunctions |
154 | 154 | ); |
155 | 155 | |
156 | - $this->addedCustomFunctions['nonce'] = $this->customNonceVerificationFunctions; |
|
156 | + $this->addedCustomFunctions[ 'nonce' ] = $this->customNonceVerificationFunctions; |
|
157 | 157 | } |
158 | 158 | |
159 | - if ( $this->customSanitizingFunctions !== $this->addedCustomFunctions['sanitize'] ) { |
|
159 | + if ( $this->customSanitizingFunctions !== $this->addedCustomFunctions[ 'sanitize' ] ) { |
|
160 | 160 | $this->sanitizingFunctions = $this->merge_custom_array( |
161 | 161 | $this->customSanitizingFunctions, |
162 | 162 | $this->sanitizingFunctions |
163 | 163 | ); |
164 | 164 | |
165 | - $this->addedCustomFunctions['sanitize'] = $this->customSanitizingFunctions; |
|
165 | + $this->addedCustomFunctions[ 'sanitize' ] = $this->customSanitizingFunctions; |
|
166 | 166 | } |
167 | 167 | |
168 | - if ( $this->customUnslashingSanitizingFunctions !== $this->addedCustomFunctions['unslashsanitize'] ) { |
|
168 | + if ( $this->customUnslashingSanitizingFunctions !== $this->addedCustomFunctions[ 'unslashsanitize' ] ) { |
|
169 | 169 | $this->unslashingSanitizingFunctions = $this->merge_custom_array( |
170 | 170 | $this->customUnslashingSanitizingFunctions, |
171 | 171 | $this->unslashingSanitizingFunctions |
172 | 172 | ); |
173 | 173 | |
174 | - $this->addedCustomFunctions['unslashsanitize'] = $this->customUnslashingSanitizingFunctions; |
|
174 | + $this->addedCustomFunctions[ 'unslashsanitize' ] = $this->customUnslashingSanitizingFunctions; |
|
175 | 175 | } |
176 | 176 | } |
177 | 177 |
@@ -93,24 +93,24 @@ discard block |
||
93 | 93 | $superglobals = $this->input_superglobals; |
94 | 94 | |
95 | 95 | // Handling string interpolation. |
96 | - if ( \T_DOUBLE_QUOTED_STRING === $this->tokens[ $stackPtr ]['code'] |
|
97 | - || \T_HEREDOC === $this->tokens[ $stackPtr ]['code'] |
|
96 | + if ( \T_DOUBLE_QUOTED_STRING === $this->tokens[ $stackPtr ][ 'code' ] |
|
97 | + || \T_HEREDOC === $this->tokens[ $stackPtr ][ 'code' ] |
|
98 | 98 | ) { |
99 | 99 | $interpolated_variables = array_map( |
100 | - function ( $symbol ) { |
|
100 | + function( $symbol ) { |
|
101 | 101 | return '$' . $symbol; |
102 | 102 | }, |
103 | - $this->get_interpolated_variables( $this->tokens[ $stackPtr ]['content'] ) |
|
103 | + $this->get_interpolated_variables( $this->tokens[ $stackPtr ][ 'content' ] ) |
|
104 | 104 | ); |
105 | 105 | foreach ( array_intersect( $interpolated_variables, $superglobals ) as $bad_variable ) { |
106 | - $this->phpcsFile->addError( 'Detected usage of a non-sanitized, non-validated input variable %s: %s', $stackPtr, 'InputNotValidatedNotSanitized', array( $bad_variable, $this->tokens[ $stackPtr ]['content'] ) ); |
|
106 | + $this->phpcsFile->addError( 'Detected usage of a non-sanitized, non-validated input variable %s: %s', $stackPtr, 'InputNotValidatedNotSanitized', array( $bad_variable, $this->tokens[ $stackPtr ][ 'content' ] ) ); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | return; |
110 | 110 | } |
111 | 111 | |
112 | 112 | // Check if this is a superglobal. |
113 | - if ( ! \in_array( $this->tokens[ $stackPtr ]['content'], $superglobals, true ) ) { |
|
113 | + if ( ! \in_array( $this->tokens[ $stackPtr ][ 'content' ], $superglobals, true ) ) { |
|
114 | 114 | return; |
115 | 115 | } |
116 | 116 | |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | return; |
131 | 131 | } |
132 | 132 | |
133 | - $error_data = array( $this->tokens[ $stackPtr ]['content'] . '[' . implode( '][', $array_keys ) . ']' ); |
|
133 | + $error_data = array( $this->tokens[ $stackPtr ][ 'content' ] . '[' . implode( '][', $array_keys ) . ']' ); |
|
134 | 134 | |
135 | 135 | /* |
136 | 136 | * Check for validation first. |
@@ -138,19 +138,19 @@ discard block |
||
138 | 138 | $validated = false; |
139 | 139 | |
140 | 140 | for ( $i = ( $stackPtr + 1 ); $i < $this->phpcsFile->numTokens; $i++ ) { |
141 | - if ( isset( Tokens::$emptyTokens[ $this->tokens[ $i ]['code'] ] ) ) { |
|
141 | + if ( isset( Tokens::$emptyTokens[ $this->tokens[ $i ][ 'code' ] ] ) ) { |
|
142 | 142 | continue; |
143 | 143 | } |
144 | 144 | |
145 | - if ( \T_OPEN_SQUARE_BRACKET === $this->tokens[ $i ]['code'] |
|
146 | - && isset( $this->tokens[ $i ]['bracket_closer'] ) |
|
145 | + if ( \T_OPEN_SQUARE_BRACKET === $this->tokens[ $i ][ 'code' ] |
|
146 | + && isset( $this->tokens[ $i ][ 'bracket_closer' ] ) |
|
147 | 147 | ) { |
148 | 148 | // Skip over array keys. |
149 | - $i = $this->tokens[ $i ]['bracket_closer']; |
|
149 | + $i = $this->tokens[ $i ][ 'bracket_closer' ]; |
|
150 | 150 | continue; |
151 | 151 | } |
152 | 152 | |
153 | - if ( \T_COALESCE === $this->tokens[ $i ]['code'] ) { |
|
153 | + if ( \T_COALESCE === $this->tokens[ $i ][ 'code' ] ) { |
|
154 | 154 | $validated = true; |
155 | 155 | } |
156 | 156 | |
@@ -211,22 +211,22 @@ discard block |
||
211 | 211 | * @return void |
212 | 212 | */ |
213 | 213 | protected function mergeFunctionLists() { |
214 | - if ( $this->customSanitizingFunctions !== $this->addedCustomFunctions['sanitize'] ) { |
|
214 | + if ( $this->customSanitizingFunctions !== $this->addedCustomFunctions[ 'sanitize' ] ) { |
|
215 | 215 | $this->sanitizingFunctions = $this->merge_custom_array( |
216 | 216 | $this->customSanitizingFunctions, |
217 | 217 | $this->sanitizingFunctions |
218 | 218 | ); |
219 | 219 | |
220 | - $this->addedCustomFunctions['sanitize'] = $this->customSanitizingFunctions; |
|
220 | + $this->addedCustomFunctions[ 'sanitize' ] = $this->customSanitizingFunctions; |
|
221 | 221 | } |
222 | 222 | |
223 | - if ( $this->customUnslashingSanitizingFunctions !== $this->addedCustomFunctions['unslashsanitize'] ) { |
|
223 | + if ( $this->customUnslashingSanitizingFunctions !== $this->addedCustomFunctions[ 'unslashsanitize' ] ) { |
|
224 | 224 | $this->unslashingSanitizingFunctions = $this->merge_custom_array( |
225 | 225 | $this->customUnslashingSanitizingFunctions, |
226 | 226 | $this->unslashingSanitizingFunctions |
227 | 227 | ); |
228 | 228 | |
229 | - $this->addedCustomFunctions['unslashsanitize'] = $this->customUnslashingSanitizingFunctions; |
|
229 | + $this->addedCustomFunctions[ 'unslashsanitize' ] = $this->customUnslashingSanitizingFunctions; |
|
230 | 230 | } |
231 | 231 | } |
232 | 232 |
@@ -77,7 +77,7 @@ |
||
77 | 77 | public function process_parameters( $stackPtr, $group_name, $matched_content, $parameters ) { |
78 | 78 | foreach ( $this->target_functions[ $matched_content ] as $position ) { |
79 | 79 | if ( isset( $parameters[ $position ] ) ) { |
80 | - $file_constant = $this->phpcsFile->findNext( \T_FILE, $parameters[ $position ]['start'], ( $parameters[ $position ]['end'] + 1 ) ); |
|
80 | + $file_constant = $this->phpcsFile->findNext( \T_FILE, $parameters[ $position ][ 'start' ], ( $parameters[ $position ][ 'end' ] + 1 ) ); |
|
81 | 81 | |
82 | 82 | if ( false !== $file_constant ) { |
83 | 83 | $this->phpcsFile->addWarning( 'Using __FILE__ for menu slugs risks exposing filesystem structure.', $stackPtr, 'Using__FILE__' ); |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | protected function processVariable( File $phpcs_file, $stack_ptr ) { |
108 | 108 | |
109 | 109 | $tokens = $phpcs_file->getTokens(); |
110 | - $var_name = ltrim( $tokens[ $stack_ptr ]['content'], '$' ); |
|
110 | + $var_name = ltrim( $tokens[ $stack_ptr ][ 'content' ], '$' ); |
|
111 | 111 | |
112 | 112 | // If it's a php reserved var, then its ok. |
113 | 113 | if ( isset( $this->phpReservedVars[ $var_name ] ) ) { |
@@ -123,13 +123,13 @@ discard block |
||
123 | 123 | } |
124 | 124 | |
125 | 125 | $obj_operator = $phpcs_file->findNext( Tokens::$emptyTokens, ( $stack_ptr + 1 ), null, true ); |
126 | - if ( \T_OBJECT_OPERATOR === $tokens[ $obj_operator ]['code'] ) { |
|
126 | + if ( \T_OBJECT_OPERATOR === $tokens[ $obj_operator ][ 'code' ] ) { |
|
127 | 127 | // Check to see if we are using a variable from an object. |
128 | 128 | $var = $phpcs_file->findNext( Tokens::$emptyTokens, ( $obj_operator + 1 ), null, true ); |
129 | - if ( \T_STRING === $tokens[ $var ]['code'] ) { |
|
129 | + if ( \T_STRING === $tokens[ $var ][ 'code' ] ) { |
|
130 | 130 | $bracket = $phpcs_file->findNext( Tokens::$emptyTokens, ( $var + 1 ), null, true ); |
131 | - if ( \T_OPEN_PARENTHESIS !== $tokens[ $bracket ]['code'] ) { |
|
132 | - $obj_var_name = $tokens[ $var ]['content']; |
|
131 | + if ( \T_OPEN_PARENTHESIS !== $tokens[ $bracket ][ 'code' ] ) { |
|
132 | + $obj_var_name = $tokens[ $var ][ 'content' ]; |
|
133 | 133 | |
134 | 134 | // There is no way for us to know if the var is public or |
135 | 135 | // private, so we have to ignore a leading underscore if there is |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | |
154 | 154 | $in_class = false; |
155 | 155 | $obj_operator = $phpcs_file->findPrevious( Tokens::$emptyTokens, ( $stack_ptr - 1 ), null, true ); |
156 | - if ( \T_DOUBLE_COLON === $tokens[ $obj_operator ]['code'] || \T_OBJECT_OPERATOR === $tokens[ $obj_operator ]['code'] ) { |
|
156 | + if ( \T_DOUBLE_COLON === $tokens[ $obj_operator ][ 'code' ] || \T_OBJECT_OPERATOR === $tokens[ $obj_operator ][ 'code' ] ) { |
|
157 | 157 | // The variable lives within a class, and is referenced like |
158 | 158 | // this: MyClass::$_variable or $class->variable. |
159 | 159 | $in_class = true; |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | |
200 | 200 | $tokens = $phpcs_file->getTokens(); |
201 | 201 | |
202 | - $var_name = ltrim( $tokens[ $stack_ptr ]['content'], '$' ); |
|
202 | + $var_name = ltrim( $tokens[ $stack_ptr ][ 'content' ], '$' ); |
|
203 | 203 | $member_props = $phpcs_file->getMemberProperties( $stack_ptr ); |
204 | 204 | if ( empty( $member_props ) ) { |
205 | 205 | // Couldn't get any info about this variable, which |
@@ -235,12 +235,12 @@ discard block |
||
235 | 235 | |
236 | 236 | $tokens = $phpcs_file->getTokens(); |
237 | 237 | |
238 | - if ( preg_match_all( '|[^\\\]\${?([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)|', $tokens[ $stack_ptr ]['content'], $matches ) > 0 ) { |
|
238 | + if ( preg_match_all( '|[^\\\]\${?([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)|', $tokens[ $stack_ptr ][ 'content' ], $matches ) > 0 ) { |
|
239 | 239 | |
240 | 240 | // Merge any custom variables with the defaults. |
241 | 241 | $this->mergeWhiteList(); |
242 | 242 | |
243 | - foreach ( $matches[1] as $var_name ) { |
|
243 | + foreach ( $matches[ 1 ] as $var_name ) { |
|
244 | 244 | // If it's a php reserved var, then its ok. |
245 | 245 | if ( isset( $this->phpReservedVars[ $var_name ] ) ) { |
246 | 246 | continue; |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | * @return bool |
271 | 271 | */ |
272 | 272 | public static function isSnakeCase( $var_name ) { |
273 | - return (bool) preg_match( '/^[a-z0-9_]+$/', $var_name ); |
|
273 | + return (bool)preg_match( '/^[a-z0-9_]+$/', $var_name ); |
|
274 | 274 | } |
275 | 275 | |
276 | 276 | /** |
@@ -283,7 +283,7 @@ discard block |
||
283 | 283 | * @return void |
284 | 284 | */ |
285 | 285 | protected function mergeWhiteList() { |
286 | - if ( $this->customPropertiesWhitelist !== $this->addedCustomProperties['properties'] ) { |
|
286 | + if ( $this->customPropertiesWhitelist !== $this->addedCustomProperties[ 'properties' ] ) { |
|
287 | 287 | // Fix property potentially passed as comma-delimited string. |
288 | 288 | $customProperties = Sniff::merge_custom_array( $this->customPropertiesWhitelist, array(), false ); |
289 | 289 | |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | $this->whitelisted_mixed_case_member_var_names |
293 | 293 | ); |
294 | 294 | |
295 | - $this->addedCustomProperties['properties'] = $this->customPropertiesWhitelist; |
|
295 | + $this->addedCustomProperties[ 'properties' ] = $this->customPropertiesWhitelist; |
|
296 | 296 | } |
297 | 297 | } |
298 | 298 |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | return; |
94 | 94 | } |
95 | 95 | |
96 | - if ( ! isset( $parameters[1] ) ) { |
|
96 | + if ( ! isset( $parameters[ 1 ] ) ) { |
|
97 | 97 | return; |
98 | 98 | } |
99 | 99 | |
@@ -104,18 +104,18 @@ discard block |
||
104 | 104 | $content = array(); |
105 | 105 | $expected = array(); |
106 | 106 | |
107 | - for ( $i = $parameters[1]['start']; $i <= $parameters[1]['end']; $i++ ) { |
|
108 | - $content[ $i ] = $this->tokens[ $i ]['content']; |
|
109 | - $expected[ $i ] = $this->tokens[ $i ]['content']; |
|
107 | + for ( $i = $parameters[ 1 ][ 'start' ]; $i <= $parameters[ 1 ][ 'end' ]; $i++ ) { |
|
108 | + $content[ $i ] = $this->tokens[ $i ][ 'content' ]; |
|
109 | + $expected[ $i ] = $this->tokens[ $i ][ 'content' ]; |
|
110 | 110 | |
111 | - if ( \in_array( $this->tokens[ $i ]['code'], array( \T_CONSTANT_ENCAPSED_STRING, \T_DOUBLE_QUOTED_STRING ), true ) ) { |
|
112 | - $string = $this->strip_quotes( $this->tokens[ $i ]['content'] ); |
|
111 | + if ( \in_array( $this->tokens[ $i ][ 'code' ], array( \T_CONSTANT_ENCAPSED_STRING, \T_DOUBLE_QUOTED_STRING ), true ) ) { |
|
112 | + $string = $this->strip_quotes( $this->tokens[ $i ][ 'content' ] ); |
|
113 | 113 | |
114 | 114 | /* |
115 | 115 | * Here be dragons - a double quoted string can contain extrapolated variables |
116 | 116 | * which don't have to comply with these rules. |
117 | 117 | */ |
118 | - if ( \T_DOUBLE_QUOTED_STRING === $this->tokens[ $i ]['code'] ) { |
|
118 | + if ( \T_DOUBLE_QUOTED_STRING === $this->tokens[ $i ][ 'code' ] ) { |
|
119 | 119 | $transform = $this->transform_complex_string( $string, $regex ); |
120 | 120 | $case_transform = $this->transform_complex_string( $string, $regex, 'case' ); |
121 | 121 | $punct_transform = $this->transform_complex_string( $string, $regex, 'punctuation' ); |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | continue; |
130 | 130 | } |
131 | 131 | |
132 | - if ( \T_DOUBLE_QUOTED_STRING === $this->tokens[ $i ]['code'] ) { |
|
132 | + if ( \T_DOUBLE_QUOTED_STRING === $this->tokens[ $i ][ 'code' ] ) { |
|
133 | 133 | $expected[ $i ] = '"' . $transform . '"'; |
134 | 134 | } else { |
135 | 135 | $expected[ $i ] = '\'' . $transform . '\''; |
@@ -95,7 +95,7 @@ |
||
95 | 95 | $tokens = $phpcsFile->getTokens(); |
96 | 96 | |
97 | 97 | // Determine if this is a function which needs to be examined. |
98 | - $conditions = $tokens[ $stackPtr ]['conditions']; |
|
98 | + $conditions = $tokens[ $stackPtr ][ 'conditions' ]; |
|
99 | 99 | end( $conditions ); |
100 | 100 | $deepestScope = key( $conditions ); |
101 | 101 | if ( $deepestScope !== $currScope ) { |
@@ -195,10 +195,10 @@ discard block |
||
195 | 195 | public function register() { |
196 | 196 | // Get a list of all PHP native functions. |
197 | 197 | $all_functions = get_defined_functions(); |
198 | - $this->built_in_functions = array_flip( $all_functions['internal'] ); |
|
198 | + $this->built_in_functions = array_flip( $all_functions[ 'internal' ] ); |
|
199 | 199 | |
200 | 200 | // Set the sniff targets. |
201 | - $targets = array( |
|
201 | + $targets = array( |
|
202 | 202 | \T_NAMESPACE => \T_NAMESPACE, |
203 | 203 | \T_FUNCTION => \T_FUNCTION, |
204 | 204 | \T_CONST => \T_CONST, |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | // Add function call target for hook names and constants defined using define(). |
211 | 211 | $parent = parent::register(); |
212 | 212 | if ( ! empty( $parent ) ) { |
213 | - $targets[] = \T_STRING; |
|
213 | + $targets[ ] = \T_STRING; |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | return $targets; |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | */ |
226 | 226 | public function getGroups() { |
227 | 227 | $this->target_functions = $this->hookInvokeFunctions; |
228 | - $this->target_functions['define'] = true; |
|
228 | + $this->target_functions[ 'define' ] = true; |
|
229 | 229 | |
230 | 230 | return parent::getGroups(); |
231 | 231 | } |
@@ -273,36 +273,36 @@ discard block |
||
273 | 273 | } |
274 | 274 | |
275 | 275 | // Ignore test classes. |
276 | - if ( isset( Tokens::$ooScopeTokens[ $this->tokens[ $stackPtr ]['code'] ] ) |
|
276 | + if ( isset( Tokens::$ooScopeTokens[ $this->tokens[ $stackPtr ][ 'code' ] ] ) |
|
277 | 277 | && true === $this->is_test_class( $stackPtr ) |
278 | 278 | ) { |
279 | - if ( $this->tokens[ $stackPtr ]['scope_condition'] === $stackPtr && isset( $this->tokens[ $stackPtr ]['scope_closer'] ) ) { |
|
279 | + if ( $this->tokens[ $stackPtr ][ 'scope_condition' ] === $stackPtr && isset( $this->tokens[ $stackPtr ][ 'scope_closer' ] ) ) { |
|
280 | 280 | // Skip forward to end of test class. |
281 | - return $this->tokens[ $stackPtr ]['scope_closer']; |
|
281 | + return $this->tokens[ $stackPtr ][ 'scope_closer' ]; |
|
282 | 282 | } |
283 | 283 | return; |
284 | 284 | } |
285 | 285 | |
286 | - if ( \T_ANON_CLASS === $this->tokens[ $stackPtr ]['code'] ) { |
|
286 | + if ( \T_ANON_CLASS === $this->tokens[ $stackPtr ][ 'code' ] ) { |
|
287 | 287 | // Token was only registered to allow skipping over test classes. |
288 | 288 | return; |
289 | 289 | } |
290 | 290 | |
291 | - if ( \T_STRING === $this->tokens[ $stackPtr ]['code'] ) { |
|
291 | + if ( \T_STRING === $this->tokens[ $stackPtr ][ 'code' ] ) { |
|
292 | 292 | // Disallow excluding function groups for this sniff. |
293 | 293 | $this->exclude = array(); |
294 | 294 | |
295 | 295 | return parent::process_token( $stackPtr ); |
296 | 296 | |
297 | - } elseif ( \T_DOLLAR === $this->tokens[ $stackPtr ]['code'] ) { |
|
297 | + } elseif ( \T_DOLLAR === $this->tokens[ $stackPtr ][ 'code' ] ) { |
|
298 | 298 | |
299 | 299 | return $this->process_variable_variable( $stackPtr ); |
300 | 300 | |
301 | - } elseif ( \T_VARIABLE === $this->tokens[ $stackPtr ]['code'] ) { |
|
301 | + } elseif ( \T_VARIABLE === $this->tokens[ $stackPtr ][ 'code' ] ) { |
|
302 | 302 | |
303 | 303 | return $this->process_variable_assignment( $stackPtr ); |
304 | 304 | |
305 | - } elseif ( \T_NAMESPACE === $this->tokens[ $stackPtr ]['code'] ) { |
|
305 | + } elseif ( \T_NAMESPACE === $this->tokens[ $stackPtr ][ 'code' ] ) { |
|
306 | 306 | $namespace_name = $this->get_declared_namespace_name( $stackPtr ); |
307 | 307 | |
308 | 308 | if ( false === $namespace_name || '' === $namespace_name || '\\' === $namespace_name ) { |
@@ -310,14 +310,14 @@ discard block |
||
310 | 310 | } |
311 | 311 | |
312 | 312 | foreach ( $this->validated_namespace_prefixes as $key => $prefix_info ) { |
313 | - if ( false === $prefix_info['is_regex'] ) { |
|
314 | - if ( stripos( $namespace_name, $prefix_info['prefix'] ) === 0 ) { |
|
313 | + if ( false === $prefix_info[ 'is_regex' ] ) { |
|
314 | + if ( stripos( $namespace_name, $prefix_info[ 'prefix' ] ) === 0 ) { |
|
315 | 315 | $this->phpcsFile->recordMetric( $stackPtr, 'Prefix all globals: allowed prefixes', $key ); |
316 | 316 | return; |
317 | 317 | } |
318 | 318 | } else { |
319 | 319 | // Ok, so this prefix should be used as a regex. |
320 | - $regex = '`^' . $prefix_info['prefix'] . '`i'; |
|
320 | + $regex = '`^' . $prefix_info[ 'prefix' ] . '`i'; |
|
321 | 321 | if ( preg_match( $regex, $namespace_name ) > 0 ) { |
322 | 322 | $this->phpcsFile->recordMetric( $stackPtr, 'Prefix all globals: allowed prefixes', $key ); |
323 | 323 | return; |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | $error_text = 'Unknown syntax used'; |
355 | 355 | $error_code = 'NonPrefixedSyntaxFound'; |
356 | 356 | |
357 | - switch ( $this->tokens[ $stackPtr ]['type'] ) { |
|
357 | + switch ( $this->tokens[ $stackPtr ][ 'type' ] ) { |
|
358 | 358 | case 'T_FUNCTION': |
359 | 359 | // Methods in a class do not need to be prefixed. |
360 | 360 | if ( $this->phpcsFile->hasCondition( $stackPtr, Tokens::$ooScopeTokens ) === true ) { |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | $error_text = 'Classes declared'; |
379 | 379 | $error_code = 'NonPrefixedClassFound'; |
380 | 380 | |
381 | - switch ( $this->tokens[ $stackPtr ]['type'] ) { |
|
381 | + switch ( $this->tokens[ $stackPtr ][ 'type' ] ) { |
|
382 | 382 | case 'T_CLASS': |
383 | 383 | if ( class_exists( '\\' . $item_name, false ) ) { |
384 | 384 | // Backfill for PHP native class. |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | return; |
427 | 427 | } |
428 | 428 | |
429 | - $item_name = $this->tokens[ $constant_name_ptr ]['content']; |
|
429 | + $item_name = $this->tokens[ $constant_name_ptr ][ 'content' ]; |
|
430 | 430 | if ( \defined( '\\' . $item_name ) ) { |
431 | 431 | // Backfill for PHP native constant. |
432 | 432 | return; |
@@ -486,26 +486,26 @@ discard block |
||
486 | 486 | // Is this a variable variable ? |
487 | 487 | // Not concerned with nested ones as those will be recognized on their own token. |
488 | 488 | $next_non_empty = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true ); |
489 | - if ( false === $next_non_empty || ! isset( $indicators[ $this->tokens[ $next_non_empty ]['code'] ] ) ) { |
|
489 | + if ( false === $next_non_empty || ! isset( $indicators[ $this->tokens[ $next_non_empty ][ 'code' ] ] ) ) { |
|
490 | 490 | return; |
491 | 491 | } |
492 | 492 | |
493 | - if ( \T_OPEN_CURLY_BRACKET === $this->tokens[ $next_non_empty ]['code'] |
|
494 | - && isset( $this->tokens[ $next_non_empty ]['bracket_closer'] ) |
|
493 | + if ( \T_OPEN_CURLY_BRACKET === $this->tokens[ $next_non_empty ][ 'code' ] |
|
494 | + && isset( $this->tokens[ $next_non_empty ][ 'bracket_closer' ] ) |
|
495 | 495 | ) { |
496 | 496 | // Skip over the variable part. |
497 | - $next_non_empty = $this->tokens[ $next_non_empty ]['bracket_closer']; |
|
497 | + $next_non_empty = $this->tokens[ $next_non_empty ][ 'bracket_closer' ]; |
|
498 | 498 | } |
499 | 499 | |
500 | 500 | $maybe_assignment = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $next_non_empty + 1 ), null, true, null, true ); |
501 | 501 | |
502 | 502 | while ( false !== $maybe_assignment |
503 | - && \T_OPEN_SQUARE_BRACKET === $this->tokens[ $maybe_assignment ]['code'] |
|
504 | - && isset( $this->tokens[ $maybe_assignment ]['bracket_closer'] ) |
|
503 | + && \T_OPEN_SQUARE_BRACKET === $this->tokens[ $maybe_assignment ][ 'code' ] |
|
504 | + && isset( $this->tokens[ $maybe_assignment ][ 'bracket_closer' ] ) |
|
505 | 505 | ) { |
506 | 506 | $maybe_assignment = $this->phpcsFile->findNext( |
507 | 507 | Tokens::$emptyTokens, |
508 | - ( $this->tokens[ $maybe_assignment ]['bracket_closer'] + 1 ), |
|
508 | + ( $this->tokens[ $maybe_assignment ][ 'bracket_closer' ] + 1 ), |
|
509 | 509 | null, |
510 | 510 | true, |
511 | 511 | null, |
@@ -517,7 +517,7 @@ discard block |
||
517 | 517 | return; |
518 | 518 | } |
519 | 519 | |
520 | - if ( ! isset( Tokens::$assignmentTokens[ $this->tokens[ $maybe_assignment ]['code'] ] ) ) { |
|
520 | + if ( ! isset( Tokens::$assignmentTokens[ $this->tokens[ $maybe_assignment ][ 'code' ] ] ) ) { |
|
521 | 521 | // Not an assignment. |
522 | 522 | return; |
523 | 523 | } |
@@ -538,7 +538,7 @@ discard block |
||
538 | 538 | $condition = $this->phpcsFile->getCondition( $stackPtr, \T_CLOSURE ); |
539 | 539 | } |
540 | 540 | |
541 | - $has_global = $this->phpcsFile->findPrevious( \T_GLOBAL, ( $stackPtr - 1 ), $this->tokens[ $condition ]['scope_opener'] ); |
|
541 | + $has_global = $this->phpcsFile->findPrevious( \T_GLOBAL, ( $stackPtr - 1 ), $this->tokens[ $condition ][ 'scope_opener' ] ); |
|
542 | 542 | if ( false === $has_global ) { |
543 | 543 | // No variable import happening. |
544 | 544 | return; |
@@ -592,7 +592,7 @@ discard block |
||
592 | 592 | } |
593 | 593 | |
594 | 594 | $is_error = true; |
595 | - $variable_name = substr( $this->tokens[ $stackPtr ]['content'], 1 ); // Strip the dollar sign. |
|
595 | + $variable_name = substr( $this->tokens[ $stackPtr ][ 'content' ], 1 ); // Strip the dollar sign. |
|
596 | 596 | |
597 | 597 | // Bow out early if we know for certain no prefix is needed. |
598 | 598 | if ( $this->variable_prefixed_or_whitelisted( $stackPtr, $variable_name ) === true ) { |
@@ -601,7 +601,7 @@ discard block |
||
601 | 601 | |
602 | 602 | if ( 'GLOBALS' === $variable_name ) { |
603 | 603 | $array_open = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true ); |
604 | - if ( false === $array_open || \T_OPEN_SQUARE_BRACKET !== $this->tokens[ $array_open ]['code'] ) { |
|
604 | + if ( false === $array_open || \T_OPEN_SQUARE_BRACKET !== $this->tokens[ $array_open ][ 'code' ] ) { |
|
605 | 605 | // Live coding or something very silly. |
606 | 606 | return; |
607 | 607 | } |
@@ -613,20 +613,20 @@ discard block |
||
613 | 613 | } |
614 | 614 | |
615 | 615 | $stackPtr = $array_key; |
616 | - $variable_name = $this->strip_quotes( $this->tokens[ $array_key ]['content'] ); |
|
616 | + $variable_name = $this->strip_quotes( $this->tokens[ $array_key ][ 'content' ] ); |
|
617 | 617 | |
618 | 618 | // Check whether a prefix is needed. |
619 | - if ( isset( Tokens::$stringTokens[ $this->tokens[ $array_key ]['code'] ] ) |
|
619 | + if ( isset( Tokens::$stringTokens[ $this->tokens[ $array_key ][ 'code' ] ] ) |
|
620 | 620 | && $this->variable_prefixed_or_whitelisted( $stackPtr, $variable_name ) === true |
621 | 621 | ) { |
622 | 622 | return; |
623 | 623 | } |
624 | 624 | |
625 | - if ( \T_DOUBLE_QUOTED_STRING === $this->tokens[ $array_key ]['code'] ) { |
|
625 | + if ( \T_DOUBLE_QUOTED_STRING === $this->tokens[ $array_key ][ 'code' ] ) { |
|
626 | 626 | // If the array key is a double quoted string, try again with only |
627 | 627 | // the part before the first variable (if any). |
628 | 628 | $exploded = explode( '$', $variable_name ); |
629 | - $first = rtrim( $exploded[0], '{' ); |
|
629 | + $first = rtrim( $exploded[ 0 ], '{' ); |
|
630 | 630 | if ( '' !== $first ) { |
631 | 631 | if ( $this->variable_prefixed_or_whitelisted( $array_key, $first ) === true ) { |
632 | 632 | return; |
@@ -635,17 +635,17 @@ discard block |
||
635 | 635 | // If the first part was dynamic, throw a warning. |
636 | 636 | $is_error = false; |
637 | 637 | } |
638 | - } elseif ( ! isset( Tokens::$stringTokens[ $this->tokens[ $array_key ]['code'] ] ) ) { |
|
638 | + } elseif ( ! isset( Tokens::$stringTokens[ $this->tokens[ $array_key ][ 'code' ] ] ) ) { |
|
639 | 639 | // Dynamic array key, throw a warning. |
640 | 640 | $is_error = false; |
641 | 641 | } |
642 | 642 | } else { |
643 | 643 | // Function parameters do not need to be prefixed. |
644 | - if ( isset( $this->tokens[ $stackPtr ]['nested_parenthesis'] ) ) { |
|
645 | - foreach ( $this->tokens[ $stackPtr ]['nested_parenthesis'] as $opener => $closer ) { |
|
646 | - if ( isset( $this->tokens[ $opener ]['parenthesis_owner'] ) |
|
647 | - && ( \T_FUNCTION === $this->tokens[ $this->tokens[ $opener ]['parenthesis_owner'] ]['code'] |
|
648 | - || \T_CLOSURE === $this->tokens[ $this->tokens[ $opener ]['parenthesis_owner'] ]['code'] ) |
|
644 | + if ( isset( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) ) { |
|
645 | + foreach ( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] as $opener => $closer ) { |
|
646 | + if ( isset( $this->tokens[ $opener ][ 'parenthesis_owner' ] ) |
|
647 | + && ( \T_FUNCTION === $this->tokens[ $this->tokens[ $opener ][ 'parenthesis_owner' ] ][ 'code' ] |
|
648 | + || \T_CLOSURE === $this->tokens[ $this->tokens[ $opener ][ 'parenthesis_owner' ] ][ 'code' ] ) |
|
649 | 649 | ) { |
650 | 650 | return; |
651 | 651 | } |
@@ -665,7 +665,7 @@ discard block |
||
665 | 665 | $condition = $this->phpcsFile->getCondition( $stackPtr, \T_CLOSURE ); |
666 | 666 | } |
667 | 667 | |
668 | - $has_global = $this->phpcsFile->findPrevious( \T_GLOBAL, ( $stackPtr - 1 ), $this->tokens[ $condition ]['scope_opener'] ); |
|
668 | + $has_global = $this->phpcsFile->findPrevious( \T_GLOBAL, ( $stackPtr - 1 ), $this->tokens[ $condition ][ 'scope_opener' ] ); |
|
669 | 669 | if ( false === $has_global ) { |
670 | 670 | // No variable import happening. |
671 | 671 | return; |
@@ -688,7 +688,7 @@ discard block |
||
688 | 688 | return; |
689 | 689 | } |
690 | 690 | |
691 | - if ( substr( $this->tokens[ $ptr ]['content'], 1 ) === $variable_name ) { |
|
691 | + if ( substr( $this->tokens[ $ptr ][ 'content' ], 1 ) === $variable_name ) { |
|
692 | 692 | break; |
693 | 693 | } |
694 | 694 | } |
@@ -735,12 +735,12 @@ discard block |
||
735 | 735 | } |
736 | 736 | |
737 | 737 | // No matter whether it is a constant definition or a hook call, both use the first parameter. |
738 | - if ( ! isset( $parameters[1] ) ) { |
|
738 | + if ( ! isset( $parameters[ 1 ] ) ) { |
|
739 | 739 | return; |
740 | 740 | } |
741 | 741 | |
742 | 742 | $is_error = true; |
743 | - $raw_content = $this->strip_quotes( $parameters[1]['raw'] ); |
|
743 | + $raw_content = $this->strip_quotes( $parameters[ 1 ][ 'raw' ] ); |
|
744 | 744 | |
745 | 745 | if ( ( 'define' !== $matched_content |
746 | 746 | && isset( $this->whitelisted_core_hooks[ $raw_content ] ) ) |
@@ -750,14 +750,14 @@ discard block |
||
750 | 750 | return; |
751 | 751 | } |
752 | 752 | |
753 | - if ( $this->is_prefixed( $parameters[1]['start'], $raw_content ) === true ) { |
|
753 | + if ( $this->is_prefixed( $parameters[ 1 ][ 'start' ], $raw_content ) === true ) { |
|
754 | 754 | return; |
755 | 755 | } else { |
756 | 756 | // This may be a dynamic hook/constant name. |
757 | 757 | $first_non_empty = $this->phpcsFile->findNext( |
758 | 758 | Tokens::$emptyTokens, |
759 | - $parameters[1]['start'], |
|
760 | - ( $parameters[1]['end'] + 1 ), |
|
759 | + $parameters[ 1 ][ 'start' ], |
|
760 | + ( $parameters[ 1 ][ 'end' ] + 1 ), |
|
761 | 761 | true |
762 | 762 | ); |
763 | 763 | |
@@ -765,29 +765,29 @@ discard block |
||
765 | 765 | return; |
766 | 766 | } |
767 | 767 | |
768 | - $first_non_empty_content = $this->strip_quotes( $this->tokens[ $first_non_empty ]['content'] ); |
|
768 | + $first_non_empty_content = $this->strip_quotes( $this->tokens[ $first_non_empty ][ 'content' ] ); |
|
769 | 769 | |
770 | 770 | // Try again with just the first token if it's a text string. |
771 | - if ( isset( Tokens::$stringTokens[ $this->tokens[ $first_non_empty ]['code'] ] ) |
|
772 | - && $this->is_prefixed( $parameters[1]['start'], $first_non_empty_content ) === true |
|
771 | + if ( isset( Tokens::$stringTokens[ $this->tokens[ $first_non_empty ][ 'code' ] ] ) |
|
772 | + && $this->is_prefixed( $parameters[ 1 ][ 'start' ], $first_non_empty_content ) === true |
|
773 | 773 | ) { |
774 | 774 | return; |
775 | 775 | } |
776 | 776 | |
777 | - if ( \T_DOUBLE_QUOTED_STRING === $this->tokens[ $first_non_empty ]['code'] ) { |
|
777 | + if ( \T_DOUBLE_QUOTED_STRING === $this->tokens[ $first_non_empty ][ 'code' ] ) { |
|
778 | 778 | // If the first part of the parameter is a double quoted string, try again with only |
779 | 779 | // the part before the first variable (if any). |
780 | 780 | $exploded = explode( '$', $first_non_empty_content ); |
781 | - $first = rtrim( $exploded[0], '{' ); |
|
781 | + $first = rtrim( $exploded[ 0 ], '{' ); |
|
782 | 782 | if ( '' !== $first ) { |
783 | - if ( $this->is_prefixed( $parameters[1]['start'], $first ) === true ) { |
|
783 | + if ( $this->is_prefixed( $parameters[ 1 ][ 'start' ], $first ) === true ) { |
|
784 | 784 | return; |
785 | 785 | } |
786 | 786 | } else { |
787 | 787 | // Start of hook/constant name is dynamic, throw a warning. |
788 | 788 | $is_error = false; |
789 | 789 | } |
790 | - } elseif ( ! isset( Tokens::$stringTokens[ $this->tokens[ $first_non_empty ]['code'] ] ) ) { |
|
790 | + } elseif ( ! isset( Tokens::$stringTokens[ $this->tokens[ $first_non_empty ][ 'code' ] ] ) ) { |
|
791 | 791 | // Dynamic hook/constant name, throw a warning. |
792 | 792 | $is_error = false; |
793 | 793 | } |
@@ -817,7 +817,7 @@ discard block |
||
817 | 817 | } |
818 | 818 | } |
819 | 819 | |
820 | - $data[] = $raw_content; |
|
820 | + $data[ ] = $raw_content; |
|
821 | 821 | |
822 | 822 | $recorded = $this->addMessage( self::ERROR_MSG, $first_non_empty, $is_error, $error_code, $data ); |
823 | 823 | |
@@ -959,9 +959,9 @@ discard block |
||
959 | 959 | */ |
960 | 960 | private function record_potential_prefix_metric( $stackPtr, $construct_name ) { |
961 | 961 | if ( preg_match( '`^([A-Z]*[a-z0-9]*+)`', ltrim( $construct_name, '\$_' ), $matches ) > 0 |
962 | - && isset( $matches[1] ) && '' !== $matches[1] |
|
962 | + && isset( $matches[ 1 ] ) && '' !== $matches[ 1 ] |
|
963 | 963 | ) { |
964 | - $this->phpcsFile->recordMetric( $stackPtr, 'Prefix all globals: potential prefixes - start of non-prefixed construct', strtolower( $matches[1] ) ); |
|
964 | + $this->phpcsFile->recordMetric( $stackPtr, 'Prefix all globals: potential prefixes - start of non-prefixed construct', strtolower( $matches[ 1 ] ) ); |
|
965 | 965 | } |
966 | 966 | } |
967 | 967 | } |
@@ -111,11 +111,11 @@ discard block |
||
111 | 111 | * @return void |
112 | 112 | */ |
113 | 113 | public function process_token( $stackPtr ) { |
114 | - $this->spaces_before_closure_open_paren = (int) $this->spaces_before_closure_open_paren; |
|
114 | + $this->spaces_before_closure_open_paren = (int)$this->spaces_before_closure_open_paren; |
|
115 | 115 | |
116 | - if ( isset( $this->tokens[ ( $stackPtr + 1 ) ] ) && \T_WHITESPACE !== $this->tokens[ ( $stackPtr + 1 ) ]['code'] |
|
117 | - && ! ( \T_ELSE === $this->tokens[ $stackPtr ]['code'] && \T_COLON === $this->tokens[ ( $stackPtr + 1 ) ]['code'] ) |
|
118 | - && ! ( \T_CLOSURE === $this->tokens[ $stackPtr ]['code'] |
|
116 | + if ( isset( $this->tokens[ ( $stackPtr + 1 ) ] ) && \T_WHITESPACE !== $this->tokens[ ( $stackPtr + 1 ) ][ 'code' ] |
|
117 | + && ! ( \T_ELSE === $this->tokens[ $stackPtr ][ 'code' ] && \T_COLON === $this->tokens[ ( $stackPtr + 1 ) ][ 'code' ] ) |
|
118 | + && ! ( \T_CLOSURE === $this->tokens[ $stackPtr ][ 'code' ] |
|
119 | 119 | && 0 >= $this->spaces_before_closure_open_paren ) |
120 | 120 | ) { |
121 | 121 | $error = 'Space after opening control structure is required'; |
@@ -126,25 +126,25 @@ discard block |
||
126 | 126 | } |
127 | 127 | } |
128 | 128 | |
129 | - if ( ! isset( $this->tokens[ $stackPtr ]['scope_closer'] ) ) { |
|
129 | + if ( ! isset( $this->tokens[ $stackPtr ][ 'scope_closer' ] ) ) { |
|
130 | 130 | |
131 | - if ( \T_USE === $this->tokens[ $stackPtr ]['code'] && 'closure' === $this->get_use_type( $stackPtr ) ) { |
|
131 | + if ( \T_USE === $this->tokens[ $stackPtr ][ 'code' ] && 'closure' === $this->get_use_type( $stackPtr ) ) { |
|
132 | 132 | $scopeOpener = $this->phpcsFile->findNext( \T_OPEN_CURLY_BRACKET, ( $stackPtr + 1 ) ); |
133 | - $scopeCloser = $this->tokens[ $scopeOpener ]['scope_closer']; |
|
134 | - } elseif ( \T_WHILE !== $this->tokens[ $stackPtr ]['code'] ) { |
|
133 | + $scopeCloser = $this->tokens[ $scopeOpener ][ 'scope_closer' ]; |
|
134 | + } elseif ( \T_WHILE !== $this->tokens[ $stackPtr ][ 'code' ] ) { |
|
135 | 135 | return; |
136 | 136 | } |
137 | 137 | } else { |
138 | - $scopeOpener = $this->tokens[ $stackPtr ]['scope_opener']; |
|
139 | - $scopeCloser = $this->tokens[ $stackPtr ]['scope_closer']; |
|
138 | + $scopeOpener = $this->tokens[ $stackPtr ][ 'scope_opener' ]; |
|
139 | + $scopeCloser = $this->tokens[ $stackPtr ][ 'scope_closer' ]; |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | // Alternative syntax. |
143 | - if ( isset( $scopeOpener ) && \T_COLON === $this->tokens[ $scopeOpener ]['code'] ) { |
|
143 | + if ( isset( $scopeOpener ) && \T_COLON === $this->tokens[ $scopeOpener ][ 'code' ] ) { |
|
144 | 144 | |
145 | 145 | if ( 'required' === $this->space_before_colon ) { |
146 | 146 | |
147 | - if ( \T_WHITESPACE !== $this->tokens[ ( $scopeOpener - 1 ) ]['code'] ) { |
|
147 | + if ( \T_WHITESPACE !== $this->tokens[ ( $scopeOpener - 1 ) ][ 'code' ] ) { |
|
148 | 148 | $error = 'Space between opening control structure and T_COLON is required'; |
149 | 149 | $fix = $this->phpcsFile->addFixableError( $error, $scopeOpener, 'NoSpaceBetweenStructureColon' ); |
150 | 150 | |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | } |
155 | 155 | } elseif ( 'forbidden' === $this->space_before_colon ) { |
156 | 156 | |
157 | - if ( \T_WHITESPACE === $this->tokens[ ( $scopeOpener - 1 ) ]['code'] ) { |
|
157 | + if ( \T_WHITESPACE === $this->tokens[ ( $scopeOpener - 1 ) ][ 'code' ] ) { |
|
158 | 158 | $error = 'Extra space between opening control structure and T_COLON found'; |
159 | 159 | $fix = $this->phpcsFile->addFixableError( $error, ( $scopeOpener - 1 ), 'SpaceBetweenStructureColon' ); |
160 | 160 | |
@@ -168,13 +168,13 @@ discard block |
||
168 | 168 | $parenthesisOpener = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); |
169 | 169 | |
170 | 170 | // If this is a function declaration. |
171 | - if ( \T_FUNCTION === $this->tokens[ $stackPtr ]['code'] ) { |
|
171 | + if ( \T_FUNCTION === $this->tokens[ $stackPtr ][ 'code' ] ) { |
|
172 | 172 | |
173 | - if ( \T_STRING === $this->tokens[ $parenthesisOpener ]['code'] ) { |
|
173 | + if ( \T_STRING === $this->tokens[ $parenthesisOpener ][ 'code' ] ) { |
|
174 | 174 | |
175 | 175 | $function_name_ptr = $parenthesisOpener; |
176 | 176 | |
177 | - } elseif ( \T_BITWISE_AND === $this->tokens[ $parenthesisOpener ]['code'] ) { |
|
177 | + } elseif ( \T_BITWISE_AND === $this->tokens[ $parenthesisOpener ][ 'code' ] ) { |
|
178 | 178 | |
179 | 179 | // This function returns by reference (function &function_name() {}). |
180 | 180 | $parenthesisOpener = $this->phpcsFile->findNext( |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | $error, |
203 | 203 | $stackPtr, |
204 | 204 | 'SpaceBeforeFunctionOpenParenthesis', |
205 | - $this->tokens[ ( $function_name_ptr + 1 ) ]['content'] |
|
205 | + $this->tokens[ ( $function_name_ptr + 1 ) ][ 'content' ] |
|
206 | 206 | ); |
207 | 207 | |
208 | 208 | if ( true === $fix ) { |
@@ -210,14 +210,14 @@ discard block |
||
210 | 210 | } |
211 | 211 | } |
212 | 212 | } |
213 | - } elseif ( \T_CLOSURE === $this->tokens[ $stackPtr ]['code'] ) { |
|
213 | + } elseif ( \T_CLOSURE === $this->tokens[ $stackPtr ][ 'code' ] ) { |
|
214 | 214 | |
215 | 215 | // Check if there is a use () statement. |
216 | - if ( isset( $this->tokens[ $parenthesisOpener ]['parenthesis_closer'] ) ) { |
|
216 | + if ( isset( $this->tokens[ $parenthesisOpener ][ 'parenthesis_closer' ] ) ) { |
|
217 | 217 | |
218 | 218 | $usePtr = $this->phpcsFile->findNext( |
219 | 219 | Tokens::$emptyTokens, |
220 | - ( $this->tokens[ $parenthesisOpener ]['parenthesis_closer'] + 1 ), |
|
220 | + ( $this->tokens[ $parenthesisOpener ][ 'parenthesis_closer' ] + 1 ), |
|
221 | 221 | null, |
222 | 222 | true, |
223 | 223 | null, |
@@ -225,17 +225,17 @@ discard block |
||
225 | 225 | ); |
226 | 226 | |
227 | 227 | // If it is, we set that as the "scope opener". |
228 | - if ( \T_USE === $this->tokens[ $usePtr ]['code'] ) { |
|
228 | + if ( \T_USE === $this->tokens[ $usePtr ][ 'code' ] ) { |
|
229 | 229 | $scopeOpener = $usePtr; |
230 | 230 | } |
231 | 231 | } |
232 | 232 | } |
233 | 233 | |
234 | - if ( \T_COLON !== $this->tokens[ $parenthesisOpener ]['code'] |
|
235 | - && \T_FUNCTION !== $this->tokens[ $stackPtr ]['code'] |
|
234 | + if ( \T_COLON !== $this->tokens[ $parenthesisOpener ][ 'code' ] |
|
235 | + && \T_FUNCTION !== $this->tokens[ $stackPtr ][ 'code' ] |
|
236 | 236 | ) { |
237 | 237 | |
238 | - if ( \T_CLOSURE === $this->tokens[ $stackPtr ]['code'] |
|
238 | + if ( \T_CLOSURE === $this->tokens[ $stackPtr ][ 'code' ] |
|
239 | 239 | && 0 === $this->spaces_before_closure_open_paren |
240 | 240 | ) { |
241 | 241 | |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | } |
251 | 251 | } elseif ( |
252 | 252 | ( |
253 | - \T_CLOSURE !== $this->tokens[ $stackPtr ]['code'] |
|
253 | + \T_CLOSURE !== $this->tokens[ $stackPtr ][ 'code' ] |
|
254 | 254 | || 1 === $this->spaces_before_closure_open_paren |
255 | 255 | ) |
256 | 256 | && ( $stackPtr + 1 ) === $parenthesisOpener |
@@ -266,8 +266,8 @@ discard block |
||
266 | 266 | } |
267 | 267 | } |
268 | 268 | |
269 | - if ( \T_WHITESPACE === $this->tokens[ ( $stackPtr + 1 ) ]['code'] |
|
270 | - && ' ' !== $this->tokens[ ( $stackPtr + 1 ) ]['content'] |
|
269 | + if ( \T_WHITESPACE === $this->tokens[ ( $stackPtr + 1 ) ][ 'code' ] |
|
270 | + && ' ' !== $this->tokens[ ( $stackPtr + 1 ) ][ 'content' ] |
|
271 | 271 | ) { |
272 | 272 | // Checking this: if [*](...) {}. |
273 | 273 | $error = 'Expected exactly one space before opening parenthesis; "%s" found.'; |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | $error, |
276 | 276 | $stackPtr, |
277 | 277 | 'ExtraSpaceBeforeOpenParenthesis', |
278 | - $this->tokens[ ( $stackPtr + 1 ) ]['content'] |
|
278 | + $this->tokens[ ( $stackPtr + 1 ) ][ 'content' ] |
|
279 | 279 | ); |
280 | 280 | |
281 | 281 | if ( true === $fix ) { |
@@ -283,8 +283,8 @@ discard block |
||
283 | 283 | } |
284 | 284 | } |
285 | 285 | |
286 | - if ( \T_CLOSE_PARENTHESIS !== $this->tokens[ ( $parenthesisOpener + 1 ) ]['code'] ) { |
|
287 | - if ( \T_WHITESPACE !== $this->tokens[ ( $parenthesisOpener + 1 ) ]['code'] ) { |
|
286 | + if ( \T_CLOSE_PARENTHESIS !== $this->tokens[ ( $parenthesisOpener + 1 ) ][ 'code' ] ) { |
|
287 | + if ( \T_WHITESPACE !== $this->tokens[ ( $parenthesisOpener + 1 ) ][ 'code' ] ) { |
|
288 | 288 | // Checking this: $value = my_function([*]...). |
289 | 289 | $error = 'No space after opening parenthesis is prohibited'; |
290 | 290 | $fix = $this->phpcsFile->addFixableError( $error, $stackPtr, 'NoSpaceAfterOpenParenthesis' ); |
@@ -292,10 +292,10 @@ discard block |
||
292 | 292 | if ( true === $fix ) { |
293 | 293 | $this->phpcsFile->fixer->addContent( $parenthesisOpener, ' ' ); |
294 | 294 | } |
295 | - } elseif ( ( ' ' !== $this->tokens[ ( $parenthesisOpener + 1 ) ]['content'] |
|
296 | - && "\n" !== $this->tokens[ ( $parenthesisOpener + 1 ) ]['content'] |
|
297 | - && "\r\n" !== $this->tokens[ ( $parenthesisOpener + 1 ) ]['content'] ) |
|
298 | - && ! isset( $this->ignore_extra_space_after_open_paren[ $this->tokens[ $stackPtr ]['code'] ] ) |
|
295 | + } elseif ( ( ' ' !== $this->tokens[ ( $parenthesisOpener + 1 ) ][ 'content' ] |
|
296 | + && "\n" !== $this->tokens[ ( $parenthesisOpener + 1 ) ][ 'content' ] |
|
297 | + && "\r\n" !== $this->tokens[ ( $parenthesisOpener + 1 ) ][ 'content' ] ) |
|
298 | + && ! isset( $this->ignore_extra_space_after_open_paren[ $this->tokens[ $stackPtr ][ 'code' ] ] ) |
|
299 | 299 | ) { |
300 | 300 | // Checking this: if ([*]...) {}. |
301 | 301 | $error = 'Expected exactly one space after opening parenthesis; "%s" found.'; |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | $error, |
304 | 304 | $stackPtr, |
305 | 305 | 'ExtraSpaceAfterOpenParenthesis', |
306 | - $this->tokens[ ( $parenthesisOpener + 1 ) ]['content'] |
|
306 | + $this->tokens[ ( $parenthesisOpener + 1 ) ][ 'content' ] |
|
307 | 307 | ); |
308 | 308 | |
309 | 309 | if ( true === $fix ) { |
@@ -312,29 +312,29 @@ discard block |
||
312 | 312 | } |
313 | 313 | } |
314 | 314 | |
315 | - if ( isset( $this->tokens[ $parenthesisOpener ]['parenthesis_closer'] ) ) { |
|
315 | + if ( isset( $this->tokens[ $parenthesisOpener ][ 'parenthesis_closer' ] ) ) { |
|
316 | 316 | |
317 | - $parenthesisCloser = $this->tokens[ $parenthesisOpener ]['parenthesis_closer']; |
|
317 | + $parenthesisCloser = $this->tokens[ $parenthesisOpener ][ 'parenthesis_closer' ]; |
|
318 | 318 | |
319 | - if ( \T_CLOSE_PARENTHESIS !== $this->tokens[ ( $parenthesisOpener + 1 ) ]['code'] ) { |
|
319 | + if ( \T_CLOSE_PARENTHESIS !== $this->tokens[ ( $parenthesisOpener + 1 ) ][ 'code' ] ) { |
|
320 | 320 | |
321 | 321 | // Checking this: if (...[*]) {}. |
322 | - if ( \T_WHITESPACE !== $this->tokens[ ( $parenthesisCloser - 1 ) ]['code'] ) { |
|
322 | + if ( \T_WHITESPACE !== $this->tokens[ ( $parenthesisCloser - 1 ) ][ 'code' ] ) { |
|
323 | 323 | $error = 'No space before closing parenthesis is prohibited'; |
324 | 324 | $fix = $this->phpcsFile->addFixableError( $error, $parenthesisCloser, 'NoSpaceBeforeCloseParenthesis' ); |
325 | 325 | |
326 | 326 | if ( true === $fix ) { |
327 | 327 | $this->phpcsFile->fixer->addContentBefore( $parenthesisCloser, ' ' ); |
328 | 328 | } |
329 | - } elseif ( ' ' !== $this->tokens[ ( $parenthesisCloser - 1 ) ]['content'] ) { |
|
329 | + } elseif ( ' ' !== $this->tokens[ ( $parenthesisCloser - 1 ) ][ 'content' ] ) { |
|
330 | 330 | $prevNonEmpty = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $parenthesisCloser - 1 ), null, true ); |
331 | - if ( $this->tokens[ ( $parenthesisCloser ) ]['line'] === $this->tokens[ ( $prevNonEmpty + 1 ) ]['line'] ) { |
|
331 | + if ( $this->tokens[ ( $parenthesisCloser ) ][ 'line' ] === $this->tokens[ ( $prevNonEmpty + 1 ) ][ 'line' ] ) { |
|
332 | 332 | $error = 'Expected exactly one space before closing parenthesis; "%s" found.'; |
333 | 333 | $fix = $this->phpcsFile->addFixableError( |
334 | 334 | $error, |
335 | 335 | $stackPtr, |
336 | 336 | 'ExtraSpaceBeforeCloseParenthesis', |
337 | - $this->tokens[ ( $parenthesisCloser - 1 ) ]['content'] |
|
337 | + $this->tokens[ ( $parenthesisCloser - 1 ) ][ 'content' ] |
|
338 | 338 | ); |
339 | 339 | |
340 | 340 | if ( true === $fix ) { |
@@ -343,12 +343,12 @@ discard block |
||
343 | 343 | } |
344 | 344 | } |
345 | 345 | |
346 | - if ( \T_WHITESPACE !== $this->tokens[ ( $parenthesisCloser + 1 ) ]['code'] |
|
346 | + if ( \T_WHITESPACE !== $this->tokens[ ( $parenthesisCloser + 1 ) ][ 'code' ] |
|
347 | 347 | && ! ( // Do NOT flag : immediately following ) for return types declarations. |
348 | - \T_COLON === $this->tokens[ ( $parenthesisCloser + 1 ) ]['code'] |
|
349 | - && in_array( $this->tokens[ $this->tokens[ $parenthesisCloser ]['parenthesis_owner'] ]['code'], array( \T_FUNCTION, \T_CLOSURE ), true ) |
|
348 | + \T_COLON === $this->tokens[ ( $parenthesisCloser + 1 ) ][ 'code' ] |
|
349 | + && in_array( $this->tokens[ $this->tokens[ $parenthesisCloser ][ 'parenthesis_owner' ] ][ 'code' ], array( \T_FUNCTION, \T_CLOSURE ), true ) |
|
350 | 350 | ) |
351 | - && ( isset( $scopeOpener ) && \T_COLON !== $this->tokens[ $scopeOpener ]['code'] ) |
|
351 | + && ( isset( $scopeOpener ) && \T_COLON !== $this->tokens[ $scopeOpener ][ 'code' ] ) |
|
352 | 352 | ) { |
353 | 353 | $error = 'Space between opening control structure and closing parenthesis is required'; |
354 | 354 | $fix = $this->phpcsFile->addFixableError( $error, $scopeOpener, 'NoSpaceAfterCloseParenthesis' ); |
@@ -360,11 +360,11 @@ discard block |
||
360 | 360 | } |
361 | 361 | |
362 | 362 | // Ignore this for function declarations. Handled by the OpeningFunctionBraceKernighanRitchie sniff. |
363 | - if ( \T_FUNCTION !== $this->tokens[ $stackPtr ]['code'] |
|
364 | - && \T_CLOSURE !== $this->tokens[ $stackPtr ]['code'] |
|
365 | - && isset( $this->tokens[ $parenthesisOpener ]['parenthesis_owner'] ) |
|
363 | + if ( \T_FUNCTION !== $this->tokens[ $stackPtr ][ 'code' ] |
|
364 | + && \T_CLOSURE !== $this->tokens[ $stackPtr ][ 'code' ] |
|
365 | + && isset( $this->tokens[ $parenthesisOpener ][ 'parenthesis_owner' ] ) |
|
366 | 366 | && ( isset( $scopeOpener ) |
367 | - && $this->tokens[ $parenthesisCloser ]['line'] !== $this->tokens[ $scopeOpener ]['line'] ) |
|
367 | + && $this->tokens[ $parenthesisCloser ][ 'line' ] !== $this->tokens[ $scopeOpener ][ 'line' ] ) |
|
368 | 368 | ) { |
369 | 369 | $error = 'Opening brace should be on the same line as the declaration'; |
370 | 370 | $fix = $this->phpcsFile->addFixableError( $error, $parenthesisOpener, 'OpenBraceNotSameLine' ); |
@@ -381,8 +381,8 @@ discard block |
||
381 | 381 | } |
382 | 382 | return; |
383 | 383 | |
384 | - } elseif ( \T_WHITESPACE === $this->tokens[ ( $parenthesisCloser + 1 ) ]['code'] |
|
385 | - && ' ' !== $this->tokens[ ( $parenthesisCloser + 1 ) ]['content'] |
|
384 | + } elseif ( \T_WHITESPACE === $this->tokens[ ( $parenthesisCloser + 1 ) ][ 'code' ] |
|
385 | + && ' ' !== $this->tokens[ ( $parenthesisCloser + 1 ) ][ 'content' ] |
|
386 | 386 | ) { |
387 | 387 | |
388 | 388 | // Checking this: if (...) [*]{}. |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | $error, |
392 | 392 | $stackPtr, |
393 | 393 | 'ExtraSpaceAfterCloseParenthesis', |
394 | - $this->tokens[ ( $parenthesisCloser + 1 ) ]['content'] |
|
394 | + $this->tokens[ ( $parenthesisCloser + 1 ) ][ 'content' ] |
|
395 | 395 | ); |
396 | 396 | |
397 | 397 | if ( true === $fix ) { |
@@ -404,7 +404,7 @@ discard block |
||
404 | 404 | $firstContent = $this->phpcsFile->findNext( \T_WHITESPACE, ( $scopeOpener + 1 ), null, true ); |
405 | 405 | |
406 | 406 | // We ignore spacing for some structures that tend to have their own rules. |
407 | - $ignore = array( |
|
407 | + $ignore = array( |
|
408 | 408 | \T_FUNCTION => true, |
409 | 409 | \T_CLOSURE => true, |
410 | 410 | \T_DOC_COMMENT_OPEN_TAG => true, |
@@ -413,8 +413,8 @@ discard block |
||
413 | 413 | ); |
414 | 414 | $ignore += Tokens::$ooScopeTokens; |
415 | 415 | |
416 | - if ( ! isset( $ignore[ $this->tokens[ $firstContent ]['code'] ] ) |
|
417 | - && $this->tokens[ $firstContent ]['line'] > ( $this->tokens[ $scopeOpener ]['line'] + 1 ) |
|
416 | + if ( ! isset( $ignore[ $this->tokens[ $firstContent ][ 'code' ] ] ) |
|
417 | + && $this->tokens[ $firstContent ][ 'line' ] > ( $this->tokens[ $scopeOpener ][ 'line' ] + 1 ) |
|
418 | 418 | ) { |
419 | 419 | $error = 'Blank line found at start of control structure'; |
420 | 420 | $fix = $this->phpcsFile->addFixableError( $error, $scopeOpener, 'BlankLineAfterStart' ); |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | $this->phpcsFile->fixer->beginChangeset(); |
424 | 424 | |
425 | 425 | for ( $i = ( $scopeOpener + 1 ); $i < $firstContent; $i++ ) { |
426 | - if ( $this->tokens[ $i ]['line'] === $this->tokens[ $firstContent ]['line'] ) { |
|
426 | + if ( $this->tokens[ $i ][ 'line' ] === $this->tokens[ $firstContent ][ 'line' ] ) { |
|
427 | 427 | break; |
428 | 428 | } |
429 | 429 | $this->phpcsFile->fixer->replaceToken( $i, '' ); |
@@ -440,16 +440,16 @@ discard block |
||
440 | 440 | $lastNonEmptyContent = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $scopeCloser - 1 ), null, true ); |
441 | 441 | |
442 | 442 | $checkToken = $lastContent; |
443 | - if ( isset( $this->tokens[ $lastNonEmptyContent ]['scope_condition'] ) ) { |
|
444 | - $checkToken = $this->tokens[ $lastNonEmptyContent ]['scope_condition']; |
|
443 | + if ( isset( $this->tokens[ $lastNonEmptyContent ][ 'scope_condition' ] ) ) { |
|
444 | + $checkToken = $this->tokens[ $lastNonEmptyContent ][ 'scope_condition' ]; |
|
445 | 445 | } |
446 | 446 | |
447 | - if ( ! isset( $ignore[ $this->tokens[ $checkToken ]['code'] ] ) |
|
448 | - && $this->tokens[ $lastContent ]['line'] <= ( $this->tokens[ $scopeCloser ]['line'] - 2 ) |
|
447 | + if ( ! isset( $ignore[ $this->tokens[ $checkToken ][ 'code' ] ] ) |
|
448 | + && $this->tokens[ $lastContent ][ 'line' ] <= ( $this->tokens[ $scopeCloser ][ 'line' ] - 2 ) |
|
449 | 449 | ) { |
450 | 450 | for ( $i = ( $scopeCloser - 1 ); $i > $lastContent; $i-- ) { |
451 | - if ( $this->tokens[ $i ]['line'] < $this->tokens[ $scopeCloser ]['line'] |
|
452 | - && \T_OPEN_TAG !== $this->tokens[ $firstContent ]['code'] |
|
451 | + if ( $this->tokens[ $i ][ 'line' ] < $this->tokens[ $scopeCloser ][ 'line' ] |
|
452 | + && \T_OPEN_TAG !== $this->tokens[ $firstContent ][ 'code' ] |
|
453 | 453 | ) { |
454 | 454 | // TODO: Reporting error at empty line won't highlight it in IDE. |
455 | 455 | $error = 'Blank line found at end of control structure'; |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | $this->phpcsFile->fixer->beginChangeset(); |
460 | 460 | |
461 | 461 | for ( $j = ( $lastContent + 1 ); $j < $scopeCloser; $j++ ) { |
462 | - if ( $this->tokens[ $j ]['line'] === $this->tokens[ $scopeCloser ]['line'] ) { |
|
462 | + if ( $this->tokens[ $j ][ 'line' ] === $this->tokens[ $scopeCloser ][ 'line' ] ) { |
|
463 | 463 | break; |
464 | 464 | } |
465 | 465 | $this->phpcsFile->fixer->replaceToken( $j, '' ); |
@@ -470,8 +470,8 @@ discard block |
||
470 | 470 | * the new line at the end, so don't add any extra as it would cause a fixer |
471 | 471 | * conflict. |
472 | 472 | */ |
473 | - if ( \T_COMMENT !== $this->tokens[ $lastContent ]['code'] |
|
474 | - && ! isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $lastContent ]['code'] ] ) ) { |
|
473 | + if ( \T_COMMENT !== $this->tokens[ $lastContent ][ 'code' ] |
|
474 | + && ! isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $lastContent ][ 'code' ] ] ) ) { |
|
475 | 475 | $this->phpcsFile->fixer->addNewlineBefore( $j ); |
476 | 476 | } |
477 | 477 | |
@@ -496,53 +496,53 @@ discard block |
||
496 | 496 | return; |
497 | 497 | } |
498 | 498 | |
499 | - if ( \T_COMMENT === $this->tokens[ $trailingContent ]['code'] |
|
500 | - || isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $trailingContent ]['code'] ] ) |
|
499 | + if ( \T_COMMENT === $this->tokens[ $trailingContent ][ 'code' ] |
|
500 | + || isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $trailingContent ][ 'code' ] ] ) |
|
501 | 501 | ) { |
502 | 502 | // Special exception for code where the comment about |
503 | 503 | // an ELSE or ELSEIF is written between the control structures. |
504 | 504 | $nextCode = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $scopeCloser + 1 ), null, true ); |
505 | 505 | |
506 | - if ( \T_ELSE === $this->tokens[ $nextCode ]['code'] || \T_ELSEIF === $this->tokens[ $nextCode ]['code'] ) { |
|
506 | + if ( \T_ELSE === $this->tokens[ $nextCode ][ 'code' ] || \T_ELSEIF === $this->tokens[ $nextCode ][ 'code' ] ) { |
|
507 | 507 | $trailingContent = $nextCode; |
508 | 508 | } |
509 | 509 | |
510 | 510 | // Move past end comments. |
511 | - if ( $this->tokens[ $trailingContent ]['line'] === $this->tokens[ $scopeCloser ]['line'] ) { |
|
512 | - if ( preg_match( '`^//[ ]?end`i', $this->tokens[ $trailingContent ]['content'], $matches ) > 0 ) { |
|
511 | + if ( $this->tokens[ $trailingContent ][ 'line' ] === $this->tokens[ $scopeCloser ][ 'line' ] ) { |
|
512 | + if ( preg_match( '`^//[ ]?end`i', $this->tokens[ $trailingContent ][ 'content' ], $matches ) > 0 ) { |
|
513 | 513 | $scopeCloser = $trailingContent; |
514 | 514 | $trailingContent = $this->phpcsFile->findNext( \T_WHITESPACE, ( $trailingContent + 1 ), null, true ); |
515 | 515 | } |
516 | 516 | } |
517 | 517 | } |
518 | 518 | |
519 | - if ( \T_ELSE === $this->tokens[ $trailingContent ]['code'] && \T_IF === $this->tokens[ $stackPtr ]['code'] ) { |
|
519 | + if ( \T_ELSE === $this->tokens[ $trailingContent ][ 'code' ] && \T_IF === $this->tokens[ $stackPtr ][ 'code' ] ) { |
|
520 | 520 | // IF with ELSE. |
521 | 521 | return; |
522 | 522 | } |
523 | 523 | |
524 | - if ( \T_WHILE === $this->tokens[ $trailingContent ]['code'] && \T_DO === $this->tokens[ $stackPtr ]['code'] ) { |
|
524 | + if ( \T_WHILE === $this->tokens[ $trailingContent ][ 'code' ] && \T_DO === $this->tokens[ $stackPtr ][ 'code' ] ) { |
|
525 | 525 | // DO with WHILE. |
526 | 526 | return; |
527 | 527 | } |
528 | 528 | |
529 | - if ( \T_CLOSE_TAG === $this->tokens[ $trailingContent ]['code'] ) { |
|
529 | + if ( \T_CLOSE_TAG === $this->tokens[ $trailingContent ][ 'code' ] ) { |
|
530 | 530 | // At the end of the script or embedded code. |
531 | 531 | return; |
532 | 532 | } |
533 | 533 | |
534 | - if ( isset( $this->tokens[ $trailingContent ]['scope_condition'] ) |
|
535 | - && \T_CLOSE_CURLY_BRACKET === $this->tokens[ $trailingContent ]['code'] |
|
534 | + if ( isset( $this->tokens[ $trailingContent ][ 'scope_condition' ] ) |
|
535 | + && \T_CLOSE_CURLY_BRACKET === $this->tokens[ $trailingContent ][ 'code' ] |
|
536 | 536 | ) { |
537 | 537 | // Another control structure's closing brace. |
538 | - $owner = $this->tokens[ $trailingContent ]['scope_condition']; |
|
539 | - if ( \in_array( $this->tokens[ $owner ]['code'], array( \T_FUNCTION, \T_CLOSURE, \T_CLASS, \T_ANON_CLASS, \T_INTERFACE, \T_TRAIT ), true ) ) { |
|
538 | + $owner = $this->tokens[ $trailingContent ][ 'scope_condition' ]; |
|
539 | + if ( \in_array( $this->tokens[ $owner ][ 'code' ], array( \T_FUNCTION, \T_CLOSURE, \T_CLASS, \T_ANON_CLASS, \T_INTERFACE, \T_TRAIT ), true ) ) { |
|
540 | 540 | // The next content is the closing brace of a function, class, interface or trait |
541 | 541 | // so normal function/class rules apply and we can ignore it. |
542 | 542 | return; |
543 | 543 | } |
544 | 544 | |
545 | - if ( ( $this->tokens[ $scopeCloser ]['line'] + 1 ) !== $this->tokens[ $trailingContent ]['line'] ) { |
|
545 | + if ( ( $this->tokens[ $scopeCloser ][ 'line' ] + 1 ) !== $this->tokens[ $trailingContent ][ 'line' ] ) { |
|
546 | 546 | // TODO: Won't cover following case: "} echo 'OK';". |
547 | 547 | $error = 'Blank line found after control structure'; |
548 | 548 | $fix = $this->phpcsFile->addFixableError( $error, $scopeCloser, 'BlankLineAfterEnd' ); |
@@ -551,14 +551,14 @@ discard block |
||
551 | 551 | $this->phpcsFile->fixer->beginChangeset(); |
552 | 552 | |
553 | 553 | $i = ( $scopeCloser + 1 ); |
554 | - while ( $this->tokens[ $i ]['line'] !== $this->tokens[ $trailingContent ]['line'] ) { |
|
554 | + while ( $this->tokens[ $i ][ 'line' ] !== $this->tokens[ $trailingContent ][ 'line' ] ) { |
|
555 | 555 | $this->phpcsFile->fixer->replaceToken( $i, '' ); |
556 | 556 | $i++; |
557 | 557 | } |
558 | 558 | |
559 | 559 | // TODO: Instead a separate error should be triggered when content comes right after closing brace. |
560 | - if ( \T_COMMENT !== $this->tokens[ $scopeCloser ]['code'] |
|
561 | - && isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $scopeCloser ]['code'] ] ) === false |
|
560 | + if ( \T_COMMENT !== $this->tokens[ $scopeCloser ][ 'code' ] |
|
561 | + && isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $scopeCloser ][ 'code' ] ] ) === false |
|
562 | 562 | ) { |
563 | 563 | $this->phpcsFile->fixer->addNewlineBefore( $trailingContent ); |
564 | 564 | } |