@@ -59,7 +59,7 @@ |
||
| 59 | 59 | /** |
| 60 | 60 | * Returns an array of tokens this test wants to listen for. |
| 61 | 61 | * |
| 62 | - * @return array |
|
| 62 | + * @return integer[] |
|
| 63 | 63 | */ |
| 64 | 64 | public function register() { |
| 65 | 65 | |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | , $this->warnForSuperGlobals |
| 99 | 99 | ); |
| 100 | 100 | |
| 101 | - if ( ! in_array( $instance['content'], $superglobals, true ) ) { |
|
| 101 | + if ( ! in_array( $instance[ 'content' ], $superglobals, true ) ) { |
|
| 102 | 102 | return; |
| 103 | 103 | } |
| 104 | 104 | |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | // If we're still here, no nonce-verification function was found. |
| 122 | - $severity = ( in_array( $instance['content'], $this->errorForSuperGlobals, true ) ) ? 0 : 'warning'; |
|
| 122 | + $severity = ( in_array( $instance[ 'content' ], $this->errorForSuperGlobals, true ) ) ? 0 : 'warning'; |
|
| 123 | 123 | |
| 124 | 124 | $phpcsFile->addError( |
| 125 | 125 | 'Processing form data without nonce verification.' |
@@ -62,7 +62,7 @@ |
||
| 62 | 62 | * |
| 63 | 63 | * Prepares the punctuation regex and returns an array of tokens this test wants to listen for. |
| 64 | 64 | * |
| 65 | - * @return array |
|
| 65 | + * @return integer[] |
|
| 66 | 66 | */ |
| 67 | 67 | public function register() { |
| 68 | 68 | return array( |
@@ -86,12 +86,12 @@ discard block |
||
| 86 | 86 | $regex = $this->prepare_regex(); |
| 87 | 87 | |
| 88 | 88 | // Check if one of the hook functions was found. |
| 89 | - if ( ! isset( WordPress_Sniff::$hookInvokeFunctions[ $tokens[ $stackPtr ]['content'] ] ) ) { |
|
| 89 | + if ( ! isset( WordPress_Sniff::$hookInvokeFunctions[ $tokens[ $stackPtr ][ 'content' ] ] ) ) { |
|
| 90 | 90 | return; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | // Ignore deprecated hook names. |
| 94 | - if ( strpos( $tokens[ $stackPtr ]['content'], '_deprecated' ) > 0 ) { |
|
| 94 | + if ( strpos( $tokens[ $stackPtr ][ 'content' ], '_deprecated' ) > 0 ) { |
|
| 95 | 95 | return; |
| 96 | 96 | } |
| 97 | 97 | |
@@ -99,13 +99,13 @@ discard block |
||
| 99 | 99 | |
| 100 | 100 | if ( false !== $prev ) { |
| 101 | 101 | // Skip sniffing if calling a same-named method, or on function definitions. |
| 102 | - if ( in_array( $tokens[ $prev ]['code'], array( T_FUNCTION, T_DOUBLE_COLON, T_OBJECT_OPERATOR ), true ) ) { |
|
| 102 | + if ( in_array( $tokens[ $prev ][ 'code' ], array( T_FUNCTION, T_DOUBLE_COLON, T_OBJECT_OPERATOR ), true ) ) { |
|
| 103 | 103 | return; |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | 106 | // Skip namespaced functions, ie: \foo\bar() not \bar(). |
| 107 | 107 | $pprev = $phpcsFile->findPrevious( T_WHITESPACE, ( $prev - 1 ), null, true ); |
| 108 | - if ( false !== $pprev && T_NS_SEPARATOR === $tokens[ $prev ]['code'] && T_STRING === $tokens[ $pprev ]['code'] ) { |
|
| 108 | + if ( false !== $pprev && T_NS_SEPARATOR === $tokens[ $prev ][ 'code' ] && T_STRING === $tokens[ $pprev ][ 'code' ] ) { |
|
| 109 | 109 | return; |
| 110 | 110 | } |
| 111 | 111 | } |
@@ -118,10 +118,10 @@ discard block |
||
| 118 | 118 | $start = $phpcsFile->findNext( array( T_WHITESPACE, T_OPEN_PARENTHESIS ), ( $stackPtr + 1 ), null, true, null, true ); |
| 119 | 119 | $open = $phpcsFile->findNext( T_OPEN_PARENTHESIS, ( $stackPtr + 1 ), null, false, null, true ); |
| 120 | 120 | $end = $phpcsFile->findNext( T_COMMA, ( $start + 1 ), null, false, null, true ); |
| 121 | - if ( false === $end || $end > $tokens[ $open ]['parenthesis_closer'] ) { |
|
| 122 | - $end = $tokens[ $open ]['parenthesis_closer']; |
|
| 121 | + if ( false === $end || $end > $tokens[ $open ][ 'parenthesis_closer' ] ) { |
|
| 122 | + $end = $tokens[ $open ][ 'parenthesis_closer' ]; |
|
| 123 | 123 | } |
| 124 | - if ( T_WHITESPACE === $tokens[ ( $end - 1 ) ]['code'] ) { |
|
| 124 | + if ( T_WHITESPACE === $tokens[ ( $end - 1 ) ][ 'code' ] ) { |
|
| 125 | 125 | $end--; |
| 126 | 126 | } |
| 127 | 127 | |
@@ -131,21 +131,21 @@ discard block |
||
| 131 | 131 | $expected = array(); |
| 132 | 132 | |
| 133 | 133 | for ( $i = $start; $i < $end; $i++ ) { |
| 134 | - $content[ $i ] = $tokens[ $i ]['content']; |
|
| 135 | - $expected[ $i ] = $tokens[ $i ]['content']; |
|
| 134 | + $content[ $i ] = $tokens[ $i ][ 'content' ]; |
|
| 135 | + $expected[ $i ] = $tokens[ $i ][ 'content' ]; |
|
| 136 | 136 | |
| 137 | - if ( in_array( $tokens[ $i ]['code'], array( T_CONSTANT_ENCAPSED_STRING, T_DOUBLE_QUOTED_STRING ), true ) ) { |
|
| 137 | + if ( in_array( $tokens[ $i ][ 'code' ], array( T_CONSTANT_ENCAPSED_STRING, T_DOUBLE_QUOTED_STRING ), true ) ) { |
|
| 138 | 138 | /* |
| 139 | 139 | Here be dragons - a double quoted string can contain extrapolated variables |
| 140 | 140 | which don't have to comply with these rules. |
| 141 | 141 | */ |
| 142 | - if ( T_DOUBLE_QUOTED_STRING === $tokens[ $i ]['code'] ) { |
|
| 143 | - $string = trim( $tokens[ $i ]['content'], '"' ); |
|
| 142 | + if ( T_DOUBLE_QUOTED_STRING === $tokens[ $i ][ 'code' ] ) { |
|
| 143 | + $string = trim( $tokens[ $i ][ 'content' ], '"' ); |
|
| 144 | 144 | $transform = $this->transform_complex_string( $string, $regex ); |
| 145 | 145 | $case_transform = $this->transform_complex_string( $string, $regex, 'case' ); |
| 146 | 146 | $punct_transform = $this->transform_complex_string( $string, $regex, 'punctuation' ); |
| 147 | 147 | } else { |
| 148 | - $string = trim( $tokens[ $i ]['content'], '\'"' ); |
|
| 148 | + $string = trim( $tokens[ $i ][ 'content' ], '\'"' ); |
|
| 149 | 149 | $transform = $this->transform( $string, $regex ); |
| 150 | 150 | $case_transform = $this->transform( $string, $regex, 'case' ); |
| 151 | 151 | $punct_transform = $this->transform( $string, $regex, 'punctuation' ); |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | continue; |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | - if ( T_DOUBLE_QUOTED_STRING === $tokens[ $i ]['code'] ) { |
|
| 158 | + if ( T_DOUBLE_QUOTED_STRING === $tokens[ $i ][ 'code' ] ) { |
|
| 159 | 159 | $expected[ $i ] = '"' . $transform . '"'; |
| 160 | 160 | } else { |
| 161 | 161 | $expected[ $i ] = '\'' . $transform . '\''; |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | /** |
| 25 | 25 | * Returns an array of tokens this test wants to listen for. |
| 26 | 26 | * |
| 27 | - * @return array |
|
| 27 | + * @return integer[] |
|
| 28 | 28 | */ |
| 29 | 29 | public function register() { |
| 30 | 30 | return array( |
@@ -47,7 +47,7 @@ |
||
| 47 | 47 | $this->init( $phpcsFile ); |
| 48 | 48 | |
| 49 | 49 | if ( ! $this->has_whitelist_comment( 'loose comparison', $stackPtr ) ) { |
| 50 | - $error = 'Found: ' . $this->tokens[ $stackPtr ]['content'] . '. Use strict comparisons (=== or !==).'; |
|
| 50 | + $error = 'Found: ' . $this->tokens[ $stackPtr ][ 'content' ] . '. Use strict comparisons (=== or !==).'; |
|
| 51 | 51 | $phpcsFile->addWarning( $error, $stackPtr, 'LooseComparison' ); |
| 52 | 52 | } |
| 53 | 53 | |
@@ -46,7 +46,7 @@ |
||
| 46 | 46 | /** |
| 47 | 47 | * Returns an array of tokens this test wants to listen for. |
| 48 | 48 | * |
| 49 | - * @return array |
|
| 49 | + * @return integer[] |
|
| 50 | 50 | */ |
| 51 | 51 | public function register() { |
| 52 | 52 | return array( |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | */ |
| 66 | 66 | public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { |
| 67 | 67 | $tokens = $phpcsFile->getTokens(); |
| 68 | - $token = strtolower( $tokens[ $stackPtr ]['content'] ); |
|
| 68 | + $token = strtolower( $tokens[ $stackPtr ][ 'content' ] ); |
|
| 69 | 69 | |
| 70 | 70 | // Bail out if not one of the targetted functions. |
| 71 | 71 | if ( ! isset( $this->array_functions[ $token ] ) ) { |
@@ -80,13 +80,13 @@ discard block |
||
| 80 | 80 | |
| 81 | 81 | if ( false !== $prev ) { |
| 82 | 82 | // Skip sniffing if calling a same-named method, or on function definitions. |
| 83 | - if ( in_array( $tokens[ $prev ]['code'], array( T_FUNCTION, T_DOUBLE_COLON, T_OBJECT_OPERATOR ), true ) ) { |
|
| 83 | + if ( in_array( $tokens[ $prev ][ 'code' ], array( T_FUNCTION, T_DOUBLE_COLON, T_OBJECT_OPERATOR ), true ) ) { |
|
| 84 | 84 | return; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | // Skip namespaced functions, ie: \foo\bar() not \bar(). |
| 88 | 88 | $pprev = $phpcsFile->findPrevious( PHP_CodeSniffer_Tokens::$emptyTokens, ( $prev - 1 ), null, true ); |
| 89 | - if ( false !== $pprev && T_NS_SEPARATOR === $tokens[ $prev ]['code'] && T_STRING === $tokens[ $pprev ]['code'] ) { |
|
| 89 | + if ( false !== $pprev && T_NS_SEPARATOR === $tokens[ $prev ][ 'code' ] && T_STRING === $tokens[ $pprev ][ 'code' ] ) { |
|
| 90 | 90 | return; |
| 91 | 91 | } |
| 92 | 92 | } |
@@ -99,19 +99,19 @@ discard block |
||
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | // Gracefully handle syntax error. |
| 102 | - if ( ! isset( $tokens[ $openParenthesis ]['parenthesis_closer'] ) ) { |
|
| 102 | + if ( ! isset( $tokens[ $openParenthesis ][ 'parenthesis_closer' ] ) ) { |
|
| 103 | 103 | $phpcsFile->addError( 'Missing closing parenthesis for in_array().', $openParenthesis, 'MissingClosingParenthesis' ); |
| 104 | 104 | return; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | // Get last token in the function call. |
| 108 | - $closeParenthesis = $tokens[ $openParenthesis ]['parenthesis_closer']; |
|
| 108 | + $closeParenthesis = $tokens[ $openParenthesis ][ 'parenthesis_closer' ]; |
|
| 109 | 109 | $lastToken = $phpcsFile->findPrevious( PHP_CodeSniffer_Tokens::$emptyTokens, ( $closeParenthesis - 1 ), ( $openParenthesis + 1 ), true ); |
| 110 | 110 | |
| 111 | 111 | // Check if the strict check is actually needed. |
| 112 | 112 | if ( false === $this->array_functions[ $token ] ) { |
| 113 | 113 | $hasComma = $phpcsFile->findPrevious( T_COMMA, ( $closeParenthesis - 1 ), ( $openParenthesis + 1 ) ); |
| 114 | - if ( false === $hasComma || end( $tokens[ $hasComma ]['nested_parenthesis'] ) !== $closeParenthesis ) { |
|
| 114 | + if ( false === $hasComma || end( $tokens[ $hasComma ][ 'nested_parenthesis' ] ) !== $closeParenthesis ) { |
|
| 115 | 115 | return; |
| 116 | 116 | } |
| 117 | 117 | } |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | return; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - if ( T_TRUE !== $tokens[ $lastToken ]['code'] ) { |
|
| 126 | + if ( T_TRUE !== $tokens[ $lastToken ][ 'code' ] ) { |
|
| 127 | 127 | $phpcsFile->addWarning( 'Not using strict comparison for %s; supply true for third argument.', $lastToken, 'MissingTrueStrict', $errorData ); |
| 128 | 128 | return; |
| 129 | 129 | } |
@@ -21,7 +21,7 @@ |
||
| 21 | 21 | /** |
| 22 | 22 | * Returns an array of tokens this test wants to listen for. |
| 23 | 23 | * |
| 24 | - * @return array |
|
| 24 | + * @return integer[] |
|
| 25 | 25 | */ |
| 26 | 26 | public function register() { |
| 27 | 27 | return array( |
@@ -58,18 +58,18 @@ discard block |
||
| 58 | 58 | for ( $i = $stackPtr; $i > $beginning; $i-- ) { |
| 59 | 59 | |
| 60 | 60 | // Ignore whitespace. |
| 61 | - if ( in_array( $tokens[ $i ]['code'], PHP_CodeSniffer_Tokens::$emptyTokens, true ) ) { |
|
| 61 | + if ( in_array( $tokens[ $i ][ 'code' ], PHP_CodeSniffer_Tokens::$emptyTokens, true ) ) { |
|
| 62 | 62 | continue; |
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | // If this is a variable or array, we've seen all we need to see. |
| 66 | - if ( T_VARIABLE === $tokens[ $i ]['code'] || T_CLOSE_SQUARE_BRACKET === $tokens[ $i ]['code'] ) { |
|
| 66 | + if ( T_VARIABLE === $tokens[ $i ][ 'code' ] || T_CLOSE_SQUARE_BRACKET === $tokens[ $i ][ 'code' ] ) { |
|
| 67 | 67 | $needs_yoda = true; |
| 68 | 68 | break; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | // If this is a function call or something, we are OK. |
| 72 | - if ( in_array( $tokens[ $i ]['code'], array( T_CONSTANT_ENCAPSED_STRING, T_CLOSE_PARENTHESIS, T_OPEN_PARENTHESIS, T_RETURN ), true ) ) { |
|
| 72 | + if ( in_array( $tokens[ $i ][ 'code' ], array( T_CONSTANT_ENCAPSED_STRING, T_CLOSE_PARENTHESIS, T_OPEN_PARENTHESIS, T_RETURN ), true ) ) { |
|
| 73 | 73 | return; |
| 74 | 74 | } |
| 75 | 75 | } |
@@ -81,11 +81,11 @@ discard block |
||
| 81 | 81 | // Check if this is a var to var comparison, e.g.: if ( $var1 == $var2 ). |
| 82 | 82 | $next_non_empty = $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); |
| 83 | 83 | |
| 84 | - if ( in_array( $tokens[ $next_non_empty ]['code'], PHP_CodeSniffer_Tokens::$castTokens, true ) ) { |
|
| 84 | + if ( in_array( $tokens[ $next_non_empty ][ 'code' ], PHP_CodeSniffer_Tokens::$castTokens, true ) ) { |
|
| 85 | 85 | $next_non_empty = $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $next_non_empty + 1 ), null, true ); |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - if ( in_array( $tokens[ $next_non_empty ]['code'], array( T_SELF, T_PARENT, T_STATIC ), true ) ) { |
|
| 88 | + if ( in_array( $tokens[ $next_non_empty ][ 'code' ], array( T_SELF, T_PARENT, T_STATIC ), true ) ) { |
|
| 89 | 89 | $next_non_empty = $phpcsFile->findNext( |
| 90 | 90 | array_merge( PHP_CodeSniffer_Tokens::$emptyTokens, array( T_DOUBLE_COLON ) ) |
| 91 | 91 | , ( $next_non_empty + 1 ) |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | ); |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - if ( T_VARIABLE === $tokens[ $next_non_empty ]['code'] ) { |
|
| 97 | + if ( T_VARIABLE === $tokens[ $next_non_empty ][ 'code' ] ) { |
|
| 98 | 98 | return; |
| 99 | 99 | } |
| 100 | 100 | |
@@ -268,7 +268,7 @@ |
||
| 268 | 268 | /** |
| 269 | 269 | * Returns an array of tokens this test wants to listen for. |
| 270 | 270 | * |
| 271 | - * @return array |
|
| 271 | + * @return integer[] |
|
| 272 | 272 | */ |
| 273 | 273 | public function register() { |
| 274 | 274 | return array( |
@@ -292,23 +292,23 @@ discard block |
||
| 292 | 292 | |
| 293 | 293 | $search = array(); // Array of globals to watch for. |
| 294 | 294 | |
| 295 | - if ( T_VARIABLE === $token['code'] && '$GLOBALS' === $token['content'] ) { |
|
| 295 | + if ( T_VARIABLE === $token[ 'code' ] && '$GLOBALS' === $token[ 'content' ] ) { |
|
| 296 | 296 | $bracketPtr = $phpcsFile->findNext( array( T_WHITESPACE ), ( $stackPtr + 1 ), null, true ); |
| 297 | 297 | |
| 298 | - if ( T_OPEN_SQUARE_BRACKET !== $this->tokens[ $bracketPtr ]['code'] ) { |
|
| 298 | + if ( T_OPEN_SQUARE_BRACKET !== $this->tokens[ $bracketPtr ][ 'code' ] ) { |
|
| 299 | 299 | return; |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | - $varPtr = $phpcsFile->findNext( T_WHITESPACE, ( $bracketPtr + 1 ), $this->tokens[ $bracketPtr ]['bracket_closer'], true ); |
|
| 302 | + $varPtr = $phpcsFile->findNext( T_WHITESPACE, ( $bracketPtr + 1 ), $this->tokens[ $bracketPtr ][ 'bracket_closer' ], true ); |
|
| 303 | 303 | $varToken = $this->tokens[ $varPtr ]; |
| 304 | 304 | |
| 305 | - if ( ! in_array( trim( $varToken['content'], '\'"' ), $this->globals, true ) ) { |
|
| 305 | + if ( ! in_array( trim( $varToken[ 'content' ], '\'"' ), $this->globals, true ) ) { |
|
| 306 | 306 | return; |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | - $assignment = $phpcsFile->findNext( T_WHITESPACE, ( $this->tokens[ $bracketPtr ]['bracket_closer'] + 1 ), null, true ); |
|
| 309 | + $assignment = $phpcsFile->findNext( T_WHITESPACE, ( $this->tokens[ $bracketPtr ][ 'bracket_closer' ] + 1 ), null, true ); |
|
| 310 | 310 | |
| 311 | - if ( $assignment && T_EQUAL === $this->tokens[ $assignment ]['code'] ) { |
|
| 311 | + if ( $assignment && T_EQUAL === $this->tokens[ $assignment ][ 'code' ] ) { |
|
| 312 | 312 | if ( ! $this->has_whitelist_comment( 'override', $assignment ) ) { |
| 313 | 313 | $phpcsFile->addError( 'Overriding WordPress globals is prohibited', $stackPtr, 'OverrideProhibited' ); |
| 314 | 314 | return; |
@@ -317,19 +317,19 @@ discard block |
||
| 317 | 317 | |
| 318 | 318 | return; |
| 319 | 319 | |
| 320 | - } elseif ( T_GLOBAL === $token['code'] ) { |
|
| 320 | + } elseif ( T_GLOBAL === $token[ 'code' ] ) { |
|
| 321 | 321 | $ptr = ( $stackPtr + 1 ); |
| 322 | 322 | while ( $ptr ) { |
| 323 | 323 | $ptr++; |
| 324 | 324 | $var = $this->tokens[ $ptr ]; |
| 325 | - if ( T_VARIABLE === $var['code'] ) { |
|
| 326 | - $varname = substr( $var['content'], 1 ); |
|
| 325 | + if ( T_VARIABLE === $var[ 'code' ] ) { |
|
| 326 | + $varname = substr( $var[ 'content' ], 1 ); |
|
| 327 | 327 | if ( in_array( $varname, $this->globals, true ) ) { |
| 328 | - $search[] = $varname; |
|
| 328 | + $search[ ] = $varname; |
|
| 329 | 329 | } |
| 330 | 330 | } |
| 331 | 331 | // Halt the loop. |
| 332 | - if ( T_SEMICOLON === $var['code'] ) { |
|
| 332 | + if ( T_SEMICOLON === $var[ 'code' ] ) { |
|
| 333 | 333 | $ptr = false; |
| 334 | 334 | } |
| 335 | 335 | } |
@@ -339,9 +339,9 @@ discard block |
||
| 339 | 339 | |
| 340 | 340 | // Check for assignments to collected global vars. |
| 341 | 341 | foreach ( $this->tokens as $ptr => $token ) { |
| 342 | - if ( T_VARIABLE === $token['code'] && in_array( substr( $token['content'], 1 ), $search, true ) ) { |
|
| 342 | + if ( T_VARIABLE === $token[ 'code' ] && in_array( substr( $token[ 'content' ], 1 ), $search, true ) ) { |
|
| 343 | 343 | $next = $phpcsFile->findNext( PHP_CodeSniffer_Tokens::$emptyTokens, ( $ptr + 1 ), null, true, null, true ); |
| 344 | - if ( T_EQUAL === $this->tokens[ $next ]['code'] ) { |
|
| 344 | + if ( T_EQUAL === $this->tokens[ $next ][ 'code' ] ) { |
|
| 345 | 345 | if ( ! $this->has_whitelist_comment( 'override', $next ) ) { |
| 346 | 346 | $phpcsFile->addError( 'Overriding WordPress globals is prohibited', $ptr, 'OverrideProhibited' ); |
| 347 | 347 | } |
@@ -73,7 +73,7 @@ |
||
| 73 | 73 | /** |
| 74 | 74 | * Returns an array of tokens this test wants to listen for. |
| 75 | 75 | * |
| 76 | - * @return array |
|
| 76 | + * @return integer[] |
|
| 77 | 77 | */ |
| 78 | 78 | public function register() { |
| 79 | 79 | return array( |
@@ -92,8 +92,8 @@ discard block |
||
| 92 | 92 | * @return int|void |
| 93 | 93 | */ |
| 94 | 94 | public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr ) { |
| 95 | - if ( ! isset( self::$methods['all'] ) ) { |
|
| 96 | - self::$methods['all'] = array_merge( self::$methods['cachable'], self::$methods['noncachable'] ); |
|
| 95 | + if ( ! isset( self::$methods[ 'all' ] ) ) { |
|
| 96 | + self::$methods[ 'all' ] = array_merge( self::$methods[ 'cachable' ], self::$methods[ 'noncachable' ] ); |
|
| 97 | 97 | |
| 98 | 98 | WordPress_Sniff::$cacheGetFunctions = array_merge( |
| 99 | 99 | WordPress_Sniff::$cacheGetFunctions, |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | $tokens = $phpcsFile->getTokens(); |
| 115 | 115 | |
| 116 | 116 | // Check for $wpdb variable. |
| 117 | - if ( '$wpdb' !== $tokens[ $stackPtr ]['content'] ) { |
|
| 117 | + if ( '$wpdb' !== $tokens[ $stackPtr ][ 'content' ] ) { |
|
| 118 | 118 | return; |
| 119 | 119 | } |
| 120 | 120 | |
@@ -124,9 +124,9 @@ discard block |
||
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | $methodPtr = $phpcsFile->findNext( array( T_WHITESPACE ), ( $is_object_call + 1 ), null, true, null, true ); |
| 127 | - $method = $tokens[ $methodPtr ]['content']; |
|
| 127 | + $method = $tokens[ $methodPtr ][ 'content' ]; |
|
| 128 | 128 | |
| 129 | - if ( ! isset( self::$methods['all'][ $method ] ) ) { |
|
| 129 | + if ( ! isset( self::$methods[ 'all' ][ $method ] ) ) { |
|
| 130 | 130 | return; |
| 131 | 131 | } |
| 132 | 132 | |
@@ -135,12 +135,12 @@ discard block |
||
| 135 | 135 | $tokenCount = count( $tokens ); |
| 136 | 136 | for ( $i = ( $endOfStatement + 1 ); $i < $tokenCount; $i++ ) { |
| 137 | 137 | |
| 138 | - if ( $tokens[ $i ]['line'] !== $tokens[ $endOfStatement ]['line'] ) { |
|
| 138 | + if ( $tokens[ $i ][ 'line' ] !== $tokens[ $endOfStatement ][ 'line' ] ) { |
|
| 139 | 139 | break; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - if ( T_COMMENT === $tokens[ $i ]['code'] ) { |
|
| 143 | - $endOfLineComment .= $tokens[ $i ]['content']; |
|
| 142 | + if ( T_COMMENT === $tokens[ $i ][ 'code' ] ) { |
|
| 143 | + $endOfLineComment .= $tokens[ $i ][ 'content' ]; |
|
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | 146 | |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | // Check for Database Schema Changes. |
| 153 | 153 | $_pos = $stackPtr; |
| 154 | 154 | while ( $_pos = $phpcsFile->findNext( array( T_CONSTANT_ENCAPSED_STRING, T_DOUBLE_QUOTED_STRING ), ( $_pos + 1 ), $endOfStatement, null, null, true ) ) { |
| 155 | - if ( preg_match( '#\b(?:ALTER|CREATE|DROP)\b#i', $tokens[ $_pos ]['content'] ) > 0 ) { |
|
| 155 | + if ( preg_match( '#\b(?:ALTER|CREATE|DROP)\b#i', $tokens[ $_pos ][ 'content' ] ) > 0 ) { |
|
| 156 | 156 | $phpcsFile->addError( 'Attempting a database schema change is highly discouraged.', $_pos, 'SchemaChange' ); |
| 157 | 157 | } |
| 158 | 158 | } |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | $phpcsFile->addWarning( 'Usage of a direct database call is discouraged.', $stackPtr, 'DirectQuery' ); |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - if ( ! isset( self::$methods['cachable'][ $method ] ) ) { |
|
| 165 | + if ( ! isset( self::$methods[ 'cachable' ][ $method ] ) ) { |
|
| 166 | 166 | return $endOfStatement; |
| 167 | 167 | } |
| 168 | 168 | |
@@ -171,27 +171,27 @@ discard block |
||
| 171 | 171 | if ( preg_match( '/cache\s+(?:ok|pass|clear|whitelist)/i', $endOfLineComment ) ) { |
| 172 | 172 | $whitelisted_cache = true; |
| 173 | 173 | } |
| 174 | - if ( ! $whitelisted_cache && ! empty( $tokens[ $stackPtr ]['conditions'] ) ) { |
|
| 174 | + if ( ! $whitelisted_cache && ! empty( $tokens[ $stackPtr ][ 'conditions' ] ) ) { |
|
| 175 | 175 | $scope_function = $phpcsFile->getCondition( $stackPtr, T_FUNCTION ); |
| 176 | 176 | |
| 177 | 177 | if ( $scope_function ) { |
| 178 | - $scopeStart = $tokens[ $scope_function ]['scope_opener']; |
|
| 179 | - $scopeEnd = $tokens[ $scope_function ]['scope_closer']; |
|
| 178 | + $scopeStart = $tokens[ $scope_function ][ 'scope_opener' ]; |
|
| 179 | + $scopeEnd = $tokens[ $scope_function ][ 'scope_closer' ]; |
|
| 180 | 180 | |
| 181 | 181 | for ( $i = ( $scopeStart + 1 ); $i < $scopeEnd; $i++ ) { |
| 182 | - if ( T_STRING === $tokens[ $i ]['code'] ) { |
|
| 182 | + if ( T_STRING === $tokens[ $i ][ 'code' ] ) { |
|
| 183 | 183 | |
| 184 | - if ( isset( WordPress_Sniff::$cacheDeleteFunctions[ $tokens[ $i ]['content'] ] ) ) { |
|
| 184 | + if ( isset( WordPress_Sniff::$cacheDeleteFunctions[ $tokens[ $i ][ 'content' ] ] ) ) { |
|
| 185 | 185 | |
| 186 | 186 | if ( in_array( $method, array( 'query', 'update', 'replace', 'delete' ), true ) ) { |
| 187 | 187 | $cached = true; |
| 188 | 188 | break; |
| 189 | 189 | } |
| 190 | - } elseif ( isset( WordPress_Sniff::$cacheGetFunctions[ $tokens[ $i ]['content'] ] ) ) { |
|
| 190 | + } elseif ( isset( WordPress_Sniff::$cacheGetFunctions[ $tokens[ $i ][ 'content' ] ] ) ) { |
|
| 191 | 191 | |
| 192 | 192 | $wp_cache_get = true; |
| 193 | 193 | |
| 194 | - } elseif ( isset( WordPress_Sniff::$cacheSetFunctions[ $tokens[ $i ]['content'] ] ) ) { |
|
| 194 | + } elseif ( isset( WordPress_Sniff::$cacheSetFunctions[ $tokens[ $i ][ 'content' ] ] ) ) { |
|
| 195 | 195 | |
| 196 | 196 | if ( $wp_cache_get ) { |
| 197 | 197 | $cached = true; |
@@ -44,7 +44,7 @@ |
||
| 44 | 44 | /** |
| 45 | 45 | * Returns an array of tokens this test wants to listen for. |
| 46 | 46 | * |
| 47 | - * @return array |
|
| 47 | + * @return integer[] |
|
| 48 | 48 | */ |
| 49 | 49 | public function register() { |
| 50 | 50 | return array( |
@@ -66,12 +66,12 @@ |
||
| 66 | 66 | $tokens = $phpcsFile->getTokens(); |
| 67 | 67 | $token = $tokens[ $stackPtr ]; |
| 68 | 68 | |
| 69 | - if ( ! in_array( $token['content'], $this->add_menu_functions, true ) ) { |
|
| 69 | + if ( ! in_array( $token[ 'content' ], $this->add_menu_functions, true ) ) { |
|
| 70 | 70 | return; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | $opening = $phpcsFile->findNext( T_OPEN_PARENTHESIS, $stackPtr ); |
| 74 | - $closing = $tokens[ $opening ]['parenthesis_closer']; |
|
| 74 | + $closing = $tokens[ $opening ][ 'parenthesis_closer' ]; |
|
| 75 | 75 | |
| 76 | 76 | $string = $phpcsFile->findNext( T_FILE, $opening, $closing, null, '__FILE__', true ); |
| 77 | 77 | |
@@ -79,7 +79,7 @@ |
||
| 79 | 79 | * @param mixed $val Assigned value. |
| 80 | 80 | * @param int $line Token line. |
| 81 | 81 | * @param array $group Group definition. |
| 82 | - * @return mixed FALSE if no match, TRUE if matches, STRING if matches |
|
| 82 | + * @return boolean FALSE if no match, TRUE if matches, STRING if matches |
|
| 83 | 83 | * with custom error message passed to ->process(). |
| 84 | 84 | */ |
| 85 | 85 | public function callback( $key, $val, $line, $group ) { |