@@ -118,8 +118,8 @@ discard block |
||
118 | 118 | $token = $this->tokens[ $stackPtr ]; |
119 | 119 | $classname = ''; |
120 | 120 | |
121 | - if ( \in_array( $token['code'], array( \T_NEW, \T_EXTENDS, \T_IMPLEMENTS ), true ) ) { |
|
122 | - if ( \T_NEW === $token['code'] ) { |
|
121 | + if ( \in_array( $token[ 'code' ], array( \T_NEW, \T_EXTENDS, \T_IMPLEMENTS ), true ) ) { |
|
122 | + if ( \T_NEW === $token[ 'code' ] ) { |
|
123 | 123 | $nameEnd = ( $this->phpcsFile->findNext( array( \T_OPEN_PARENTHESIS, \T_WHITESPACE, \T_SEMICOLON, \T_OBJECT_OPERATOR ), ( $stackPtr + 2 ) ) - 1 ); |
124 | 124 | } else { |
125 | 125 | $nameEnd = ( $this->phpcsFile->findNext( array( \T_CLOSE_CURLY_BRACKET, \T_WHITESPACE ), ( $stackPtr + 2 ) ) - 1 ); |
@@ -128,18 +128,18 @@ discard block |
||
128 | 128 | $length = ( $nameEnd - ( $stackPtr + 1 ) ); |
129 | 129 | $classname = $this->phpcsFile->getTokensAsString( ( $stackPtr + 2 ), $length ); |
130 | 130 | |
131 | - if ( \T_NS_SEPARATOR !== $this->tokens[ ( $stackPtr + 2 ) ]['code'] ) { |
|
131 | + if ( \T_NS_SEPARATOR !== $this->tokens[ ( $stackPtr + 2 ) ][ 'code' ] ) { |
|
132 | 132 | $classname = $this->get_namespaced_classname( $classname, ( $stackPtr - 1 ) ); |
133 | 133 | } |
134 | 134 | } |
135 | 135 | |
136 | - if ( \T_DOUBLE_COLON === $token['code'] ) { |
|
136 | + if ( \T_DOUBLE_COLON === $token[ 'code' ] ) { |
|
137 | 137 | $nameEnd = $this->phpcsFile->findPrevious( \T_STRING, ( $stackPtr - 1 ) ); |
138 | 138 | $nameStart = ( $this->phpcsFile->findPrevious( array( \T_STRING, \T_NS_SEPARATOR, \T_NAMESPACE ), ( $nameEnd - 1 ), null, true, null, true ) + 1 ); |
139 | 139 | $length = ( $nameEnd - ( $nameStart - 1 ) ); |
140 | 140 | $classname = $this->phpcsFile->getTokensAsString( $nameStart, $length ); |
141 | 141 | |
142 | - if ( \T_NS_SEPARATOR !== $this->tokens[ $nameStart ]['code'] ) { |
|
142 | + if ( \T_NS_SEPARATOR !== $this->tokens[ $nameStart ][ 'code' ] ) { |
|
143 | 143 | $classname = $this->get_namespaced_classname( $classname, ( $nameStart - 1 ) ); |
144 | 144 | } |
145 | 145 | } |
@@ -177,8 +177,8 @@ discard block |
||
177 | 177 | continue; |
178 | 178 | } |
179 | 179 | |
180 | - if ( preg_match( $group['regex'], $this->classname ) === 1 ) { |
|
181 | - $skip_to[] = $this->process_matched_token( $stackPtr, $groupName, $this->classname ); |
|
180 | + if ( preg_match( $group[ 'regex' ], $this->classname ) === 1 ) { |
|
181 | + $skip_to[ ] = $this->process_matched_token( $stackPtr, $groupName, $this->classname ); |
|
182 | 182 | } |
183 | 183 | } |
184 | 184 | |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | */ |
216 | 216 | protected function get_namespaced_classname( $classname, $search_from ) { |
217 | 217 | // Don't do anything if this is already a fully qualified classname. |
218 | - if ( empty( $classname ) || '\\' === $classname[0] ) { |
|
218 | + if ( empty( $classname ) || '\\' === $classname[ 0 ] ) { |
|
219 | 219 | return $classname; |
220 | 220 | } |
221 | 221 |
@@ -153,10 +153,10 @@ discard block |
||
153 | 153 | unset( $this->groups[ $groupName ] ); |
154 | 154 | } else { |
155 | 155 | $items = array_map( array( $this, 'prepare_name_for_regex' ), $group[ $key ] ); |
156 | - $all_items[] = $items; |
|
156 | + $all_items[ ] = $items; |
|
157 | 157 | $items = implode( '|', $items ); |
158 | 158 | |
159 | - $this->groups[ $groupName ]['regex'] = sprintf( $this->regex_pattern, $items ); |
|
159 | + $this->groups[ $groupName ][ 'regex' ] = sprintf( $this->regex_pattern, $items ); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | // Preliminary check. If the content of the T_STRING is not one of the functions we're |
193 | 193 | // looking for, we can bow out before doing the heavy lifting of checking whether |
194 | 194 | // this is a function call. |
195 | - if ( preg_match( $this->prelim_check_regex, $this->tokens[ $stackPtr ]['content'] ) !== 1 ) { |
|
195 | + if ( preg_match( $this->prelim_check_regex, $this->tokens[ $stackPtr ][ 'content' ] ) !== 1 ) { |
|
196 | 196 | return; |
197 | 197 | } |
198 | 198 | |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | public function is_targetted_token( $stackPtr ) { |
214 | 214 | |
215 | 215 | // Exclude function definitions, class methods, and namespaced calls. |
216 | - if ( \T_STRING === $this->tokens[ $stackPtr ]['code'] ) { |
|
216 | + if ( \T_STRING === $this->tokens[ $stackPtr ][ 'code' ] ) { |
|
217 | 217 | if ( $this->is_class_object_call( $stackPtr ) === true ) { |
218 | 218 | return false; |
219 | 219 | } |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | \T_AS => \T_AS, // Use declaration alias. |
233 | 233 | ); |
234 | 234 | |
235 | - if ( isset( $skipped[ $this->tokens[ $prev ]['code'] ] ) ) { |
|
235 | + if ( isset( $skipped[ $this->tokens[ $prev ][ 'code' ] ] ) ) { |
|
236 | 236 | return false; |
237 | 237 | } |
238 | 238 | } |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | * normal file processing. |
255 | 255 | */ |
256 | 256 | public function check_for_matches( $stackPtr ) { |
257 | - $token_content = strtolower( $this->tokens[ $stackPtr ]['content'] ); |
|
257 | + $token_content = strtolower( $this->tokens[ $stackPtr ][ 'content' ] ); |
|
258 | 258 | $skip_to = array(); |
259 | 259 | |
260 | 260 | foreach ( $this->groups as $groupName => $group ) { |
@@ -263,12 +263,12 @@ discard block |
||
263 | 263 | continue; |
264 | 264 | } |
265 | 265 | |
266 | - if ( isset( $group['whitelist'][ $token_content ] ) ) { |
|
266 | + if ( isset( $group[ 'whitelist' ][ $token_content ] ) ) { |
|
267 | 267 | continue; |
268 | 268 | } |
269 | 269 | |
270 | - if ( preg_match( $group['regex'], $token_content ) === 1 ) { |
|
271 | - $skip_to[] = $this->process_matched_token( $stackPtr, $groupName, $token_content ); |
|
270 | + if ( preg_match( $group[ 'regex' ], $token_content ) === 1 ) { |
|
271 | + $skip_to[ ] = $this->process_matched_token( $stackPtr, $groupName, $token_content ); |
|
272 | 272 | } |
273 | 273 | } |
274 | 274 | |
@@ -294,9 +294,9 @@ discard block |
||
294 | 294 | public function process_matched_token( $stackPtr, $group_name, $matched_content ) { |
295 | 295 | |
296 | 296 | $this->addMessage( |
297 | - $this->groups[ $group_name ]['message'], |
|
297 | + $this->groups[ $group_name ][ 'message' ], |
|
298 | 298 | $stackPtr, |
299 | - ( 'error' === $this->groups[ $group_name ]['type'] ), |
|
299 | + ( 'error' === $this->groups[ $group_name ][ 'type' ] ), |
|
300 | 300 | $this->string_to_errorcode( $group_name . '_' . $matched_content ), |
301 | 301 | array( $matched_content ) |
302 | 302 | ); |
@@ -48,7 +48,7 @@ |
||
48 | 48 | public function process_token( $stackPtr ) { |
49 | 49 | |
50 | 50 | if ( ! $this->has_whitelist_comment( 'loose comparison', $stackPtr ) ) { |
51 | - $error = 'Found: ' . $this->tokens[ $stackPtr ]['content'] . '. Use strict comparisons (=== or !==).'; |
|
51 | + $error = 'Found: ' . $this->tokens[ $stackPtr ][ 'content' ] . '. Use strict comparisons (=== or !==).'; |
|
52 | 52 | $this->phpcsFile->addWarning( $error, $stackPtr, 'LooseComparison' ); |
53 | 53 | } |
54 | 54 | } |
@@ -29,7 +29,7 @@ |
||
29 | 29 | /** |
30 | 30 | * Returns an array of tokens this test wants to listen for. |
31 | 31 | * |
32 | - * @return array |
|
32 | + * @return integer[] |
|
33 | 33 | */ |
34 | 34 | public function register() { |
35 | 35 | return array( |
@@ -77,20 +77,20 @@ discard block |
||
77 | 77 | for ( $i = $stackPtr; $i > $start; $i-- ) { |
78 | 78 | |
79 | 79 | // Ignore whitespace. |
80 | - if ( isset( Tokens::$emptyTokens[ $this->tokens[ $i ]['code'] ] ) ) { |
|
80 | + if ( isset( Tokens::$emptyTokens[ $this->tokens[ $i ][ 'code' ] ] ) ) { |
|
81 | 81 | continue; |
82 | 82 | } |
83 | 83 | |
84 | 84 | // If this is a variable or array, we've seen all we need to see. |
85 | - if ( \T_VARIABLE === $this->tokens[ $i ]['code'] |
|
86 | - || \T_CLOSE_SQUARE_BRACKET === $this->tokens[ $i ]['code'] |
|
85 | + if ( \T_VARIABLE === $this->tokens[ $i ][ 'code' ] |
|
86 | + || \T_CLOSE_SQUARE_BRACKET === $this->tokens[ $i ][ 'code' ] |
|
87 | 87 | ) { |
88 | 88 | $needs_yoda = true; |
89 | 89 | break; |
90 | 90 | } |
91 | 91 | |
92 | 92 | // If this is a function call or something, we are OK. |
93 | - if ( \T_CLOSE_PARENTHESIS === $this->tokens[ $i ]['code'] ) { |
|
93 | + if ( \T_CLOSE_PARENTHESIS === $this->tokens[ $i ][ 'code' ] ) { |
|
94 | 94 | return; |
95 | 95 | } |
96 | 96 | } |
@@ -102,11 +102,11 @@ discard block |
||
102 | 102 | // Check if this is a var to var comparison, e.g.: if ( $var1 == $var2 ). |
103 | 103 | $next_non_empty = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); |
104 | 104 | |
105 | - if ( isset( Tokens::$castTokens[ $this->tokens[ $next_non_empty ]['code'] ] ) ) { |
|
105 | + if ( isset( Tokens::$castTokens[ $this->tokens[ $next_non_empty ][ 'code' ] ] ) ) { |
|
106 | 106 | $next_non_empty = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $next_non_empty + 1 ), null, true ); |
107 | 107 | } |
108 | 108 | |
109 | - if ( \in_array( $this->tokens[ $next_non_empty ]['code'], array( \T_SELF, \T_PARENT, \T_STATIC ), true ) ) { |
|
109 | + if ( \in_array( $this->tokens[ $next_non_empty ][ 'code' ], array( \T_SELF, \T_PARENT, \T_STATIC ), true ) ) { |
|
110 | 110 | $next_non_empty = $this->phpcsFile->findNext( |
111 | 111 | array_merge( Tokens::$emptyTokens, array( \T_DOUBLE_COLON ) ), |
112 | 112 | ( $next_non_empty + 1 ), |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | ); |
116 | 116 | } |
117 | 117 | |
118 | - if ( \T_VARIABLE === $this->tokens[ $next_non_empty ]['code'] ) { |
|
118 | + if ( \T_VARIABLE === $this->tokens[ $next_non_empty ][ 'code' ] ) { |
|
119 | 119 | return; |
120 | 120 | } |
121 | 121 |
@@ -165,7 +165,7 @@ |
||
165 | 165 | /** |
166 | 166 | * Returns an array of tokens this test wants to listen for. |
167 | 167 | * |
168 | - * @return array |
|
168 | + * @return integer[] |
|
169 | 169 | */ |
170 | 170 | public function register() { |
171 | 171 |
@@ -52,8 +52,8 @@ |
||
52 | 52 | */ |
53 | 53 | public function process_token( $stackPtr ) { |
54 | 54 | |
55 | - $token_code = $this->tokens[ $stackPtr ]['code']; |
|
56 | - $typecast = str_replace( ' ', '', $this->tokens[ $stackPtr ]['content'] ); |
|
55 | + $token_code = $this->tokens[ $stackPtr ][ 'code' ]; |
|
56 | + $typecast = str_replace( ' ', '', $this->tokens[ $stackPtr ][ 'content' ] ); |
|
57 | 57 | $typecast_lc = strtolower( $typecast ); |
58 | 58 | |
59 | 59 | switch ( $token_code ) { |
@@ -136,27 +136,27 @@ discard block |
||
136 | 136 | * @return void |
137 | 137 | */ |
138 | 138 | public function process_parameters( $stackPtr, $group_name, $matched_content, $parameters ) { |
139 | - $option_name = $this->strip_quotes( $parameters[1]['raw'] ); |
|
140 | - $option_value = $this->strip_quotes( $parameters[2]['raw'] ); |
|
139 | + $option_name = $this->strip_quotes( $parameters[ 1 ][ 'raw' ] ); |
|
140 | + $option_value = $this->strip_quotes( $parameters[ 2 ][ 'raw' ] ); |
|
141 | 141 | if ( isset( $this->whitelisted_options[ $option_name ] ) ) { |
142 | 142 | $whitelisted_option = $this->whitelisted_options[ $option_name ]; |
143 | - if ( ! isset( $whitelisted_option['valid_values'] ) || in_array( strtolower( $option_value ), $whitelisted_option['valid_values'], true ) ) { |
|
143 | + if ( ! isset( $whitelisted_option[ 'valid_values' ] ) || in_array( strtolower( $option_value ), $whitelisted_option[ 'valid_values' ], true ) ) { |
|
144 | 144 | return; |
145 | 145 | } |
146 | 146 | } |
147 | 147 | |
148 | 148 | if ( isset( $this->blacklisted_options[ $option_name ] ) ) { |
149 | 149 | $blacklisted_option = $this->blacklisted_options[ $option_name ]; |
150 | - if ( ! isset( $blacklisted_option['invalid_values'] ) || in_array( strtolower( $option_value ), $blacklisted_option['invalid_values'], true ) ) { |
|
150 | + if ( ! isset( $blacklisted_option[ 'invalid_values' ] ) || in_array( strtolower( $option_value ), $blacklisted_option[ 'invalid_values' ], true ) ) { |
|
151 | 151 | $this->phpcsFile->addError( |
152 | 152 | '%s(%s, %s) found. %s', |
153 | 153 | $stackPtr, |
154 | 154 | $this->string_to_errorcode( $option_name . '_Blacklisted' ), |
155 | 155 | array( |
156 | 156 | $matched_content, |
157 | - $parameters[1]['raw'], |
|
158 | - $parameters[2]['raw'], |
|
159 | - $blacklisted_option['message'], |
|
157 | + $parameters[ 1 ][ 'raw' ], |
|
158 | + $parameters[ 2 ][ 'raw' ], |
|
159 | + $blacklisted_option[ 'message' ], |
|
160 | 160 | ) |
161 | 161 | ); |
162 | 162 | return; |
@@ -169,8 +169,8 @@ discard block |
||
169 | 169 | 'Risky', |
170 | 170 | array( |
171 | 171 | $matched_content, |
172 | - $parameters[1]['raw'], |
|
173 | - $parameters[2]['raw'], |
|
172 | + $parameters[ 1 ][ 'raw' ], |
|
173 | + $parameters[ 2 ][ 'raw' ], |
|
174 | 174 | ) |
175 | 175 | ); |
176 | 176 | } |
@@ -81,20 +81,20 @@ |
||
81 | 81 | } |
82 | 82 | |
83 | 83 | // We're only interested in the third parameter. |
84 | - if ( false === isset( $parameters[3] ) || 'true' !== strtolower( $parameters[3]['raw'] ) ) { |
|
84 | + if ( false === isset( $parameters[ 3 ] ) || 'true' !== strtolower( $parameters[ 3 ][ 'raw' ] ) ) { |
|
85 | 85 | $errorcode = 'MissingTrueStrict'; |
86 | 86 | |
87 | 87 | /* |
88 | 88 | * Use a different error code when `false` is found to allow for excluding |
89 | 89 | * the warning as this will be a conscious choice made by the dev. |
90 | 90 | */ |
91 | - if ( isset( $parameters[3] ) && 'false' === strtolower( $parameters[3]['raw'] ) ) { |
|
91 | + if ( isset( $parameters[ 3 ] ) && 'false' === strtolower( $parameters[ 3 ][ 'raw' ] ) ) { |
|
92 | 92 | $errorcode = 'FoundNonStrictFalse'; |
93 | 93 | } |
94 | 94 | |
95 | 95 | $this->phpcsFile->addWarning( |
96 | 96 | 'Not using strict comparison for %s; supply true for third argument.', |
97 | - ( isset( $parameters[3]['start'] ) ? $parameters[3]['start'] : $parameters[1]['start'] ), |
|
97 | + ( isset( $parameters[ 3 ][ 'start' ] ) ? $parameters[ 3 ][ 'start' ] : $parameters[ 1 ][ 'start' ] ), |
|
98 | 98 | $errorcode, |
99 | 99 | array( $matched_content ) |
100 | 100 | ); |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | public function process_token( $stackPtr ) { |
115 | 115 | |
116 | 116 | // Check for $wpdb variable. |
117 | - if ( '$wpdb' !== $this->tokens[ $stackPtr ]['content'] ) { |
|
117 | + if ( '$wpdb' !== $this->tokens[ $stackPtr ][ 'content' ] ) { |
|
118 | 118 | return; |
119 | 119 | } |
120 | 120 | |
@@ -124,11 +124,11 @@ discard block |
||
124 | 124 | } |
125 | 125 | |
126 | 126 | $methodPtr = $this->phpcsFile->findNext( array( \T_WHITESPACE ), ( $is_object_call + 1 ), null, true, null, true ); |
127 | - $method = $this->tokens[ $methodPtr ]['content']; |
|
127 | + $method = $this->tokens[ $methodPtr ][ 'content' ]; |
|
128 | 128 | |
129 | 129 | $this->mergeFunctionLists(); |
130 | 130 | |
131 | - if ( ! isset( $this->methods['all'][ $method ] ) ) { |
|
131 | + if ( ! isset( $this->methods[ 'all' ][ $method ] ) ) { |
|
132 | 132 | return; |
133 | 133 | } |
134 | 134 | |
@@ -136,12 +136,12 @@ discard block |
||
136 | 136 | $endOfLineComment = ''; |
137 | 137 | for ( $i = ( $endOfStatement + 1 ); $i < $this->phpcsFile->numTokens; $i++ ) { |
138 | 138 | |
139 | - if ( $this->tokens[ $i ]['line'] !== $this->tokens[ $endOfStatement ]['line'] ) { |
|
139 | + if ( $this->tokens[ $i ][ 'line' ] !== $this->tokens[ $endOfStatement ][ 'line' ] ) { |
|
140 | 140 | break; |
141 | 141 | } |
142 | 142 | |
143 | - if ( \T_COMMENT === $this->tokens[ $i ]['code'] ) { |
|
144 | - $endOfLineComment .= $this->tokens[ $i ]['content']; |
|
143 | + if ( \T_COMMENT === $this->tokens[ $i ][ 'code' ] ) { |
|
144 | + $endOfLineComment .= $this->tokens[ $i ][ 'content' ]; |
|
145 | 145 | } |
146 | 146 | } |
147 | 147 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | break; |
158 | 158 | } |
159 | 159 | |
160 | - if ( preg_match( '#\b(?:ALTER|CREATE|DROP)\b#i', $this->tokens[ $_pos ]['content'] ) > 0 ) { |
|
160 | + if ( preg_match( '#\b(?:ALTER|CREATE|DROP)\b#i', $this->tokens[ $_pos ][ 'content' ] ) > 0 ) { |
|
161 | 161 | $this->phpcsFile->addWarning( 'Attempting a database schema change is discouraged.', $_pos, 'SchemaChange' ); |
162 | 162 | } |
163 | 163 | } |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | $this->phpcsFile->addWarning( 'Usage of a direct database call is discouraged.', $stackPtr, 'DirectQuery' ); |
168 | 168 | } |
169 | 169 | |
170 | - if ( ! isset( $this->methods['cachable'][ $method ] ) ) { |
|
170 | + if ( ! isset( $this->methods[ 'cachable' ][ $method ] ) ) { |
|
171 | 171 | return $endOfStatement; |
172 | 172 | } |
173 | 173 | |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | if ( preg_match( '/cache\s+(?:ok|pass|clear|whitelist)/i', $endOfLineComment ) ) { |
178 | 178 | $whitelisted_cache = true; |
179 | 179 | } |
180 | - if ( ! $whitelisted_cache && ! empty( $this->tokens[ $stackPtr ]['conditions'] ) ) { |
|
180 | + if ( ! $whitelisted_cache && ! empty( $this->tokens[ $stackPtr ][ 'conditions' ] ) ) { |
|
181 | 181 | $scope_function = $this->phpcsFile->getCondition( $stackPtr, \T_FUNCTION ); |
182 | 182 | |
183 | 183 | if ( false === $scope_function ) { |
@@ -185,23 +185,23 @@ discard block |
||
185 | 185 | } |
186 | 186 | |
187 | 187 | if ( false !== $scope_function ) { |
188 | - $scopeStart = $this->tokens[ $scope_function ]['scope_opener']; |
|
189 | - $scopeEnd = $this->tokens[ $scope_function ]['scope_closer']; |
|
188 | + $scopeStart = $this->tokens[ $scope_function ][ 'scope_opener' ]; |
|
189 | + $scopeEnd = $this->tokens[ $scope_function ][ 'scope_closer' ]; |
|
190 | 190 | |
191 | 191 | for ( $i = ( $scopeStart + 1 ); $i < $scopeEnd; $i++ ) { |
192 | - if ( \T_STRING === $this->tokens[ $i ]['code'] ) { |
|
192 | + if ( \T_STRING === $this->tokens[ $i ][ 'code' ] ) { |
|
193 | 193 | |
194 | - if ( isset( $this->cacheDeleteFunctions[ $this->tokens[ $i ]['content'] ] ) ) { |
|
194 | + if ( isset( $this->cacheDeleteFunctions[ $this->tokens[ $i ][ 'content' ] ] ) ) { |
|
195 | 195 | |
196 | 196 | if ( \in_array( $method, array( 'query', 'update', 'replace', 'delete' ), true ) ) { |
197 | 197 | $cached = true; |
198 | 198 | break; |
199 | 199 | } |
200 | - } elseif ( isset( $this->cacheGetFunctions[ $this->tokens[ $i ]['content'] ] ) ) { |
|
200 | + } elseif ( isset( $this->cacheGetFunctions[ $this->tokens[ $i ][ 'content' ] ] ) ) { |
|
201 | 201 | |
202 | 202 | $wp_cache_get = true; |
203 | 203 | |
204 | - } elseif ( isset( $this->cacheSetFunctions[ $this->tokens[ $i ]['content'] ] ) ) { |
|
204 | + } elseif ( isset( $this->cacheSetFunctions[ $this->tokens[ $i ][ 'content' ] ] ) ) { |
|
205 | 205 | |
206 | 206 | if ( $wp_cache_get ) { |
207 | 207 | $cached = true; |
@@ -229,35 +229,35 @@ discard block |
||
229 | 229 | * @return void |
230 | 230 | */ |
231 | 231 | protected function mergeFunctionLists() { |
232 | - if ( ! isset( $this->methods['all'] ) ) { |
|
233 | - $this->methods['all'] = array_merge( $this->methods['cachable'], $this->methods['noncachable'] ); |
|
232 | + if ( ! isset( $this->methods[ 'all' ] ) ) { |
|
233 | + $this->methods[ 'all' ] = array_merge( $this->methods[ 'cachable' ], $this->methods[ 'noncachable' ] ); |
|
234 | 234 | } |
235 | 235 | |
236 | - if ( $this->customCacheGetFunctions !== $this->addedCustomFunctions['cacheget'] ) { |
|
236 | + if ( $this->customCacheGetFunctions !== $this->addedCustomFunctions[ 'cacheget' ] ) { |
|
237 | 237 | $this->cacheGetFunctions = $this->merge_custom_array( |
238 | 238 | $this->customCacheGetFunctions, |
239 | 239 | $this->cacheGetFunctions |
240 | 240 | ); |
241 | 241 | |
242 | - $this->addedCustomFunctions['cacheget'] = $this->customCacheGetFunctions; |
|
242 | + $this->addedCustomFunctions[ 'cacheget' ] = $this->customCacheGetFunctions; |
|
243 | 243 | } |
244 | 244 | |
245 | - if ( $this->customCacheSetFunctions !== $this->addedCustomFunctions['cacheset'] ) { |
|
245 | + if ( $this->customCacheSetFunctions !== $this->addedCustomFunctions[ 'cacheset' ] ) { |
|
246 | 246 | $this->cacheSetFunctions = $this->merge_custom_array( |
247 | 247 | $this->customCacheSetFunctions, |
248 | 248 | $this->cacheSetFunctions |
249 | 249 | ); |
250 | 250 | |
251 | - $this->addedCustomFunctions['cacheset'] = $this->customCacheSetFunctions; |
|
251 | + $this->addedCustomFunctions[ 'cacheset' ] = $this->customCacheSetFunctions; |
|
252 | 252 | } |
253 | 253 | |
254 | - if ( $this->customCacheDeleteFunctions !== $this->addedCustomFunctions['cachedelete'] ) { |
|
254 | + if ( $this->customCacheDeleteFunctions !== $this->addedCustomFunctions[ 'cachedelete' ] ) { |
|
255 | 255 | $this->cacheDeleteFunctions = $this->merge_custom_array( |
256 | 256 | $this->customCacheDeleteFunctions, |
257 | 257 | $this->cacheDeleteFunctions |
258 | 258 | ); |
259 | 259 | |
260 | - $this->addedCustomFunctions['cachedelete'] = $this->customCacheDeleteFunctions; |
|
260 | + $this->addedCustomFunctions[ 'cachedelete' ] = $this->customCacheDeleteFunctions; |
|
261 | 261 | } |
262 | 262 | } |
263 | 263 |
@@ -29,7 +29,7 @@ |
||
29 | 29 | /** |
30 | 30 | * Returns an array of tokens this test wants to listen for. |
31 | 31 | * |
32 | - * @return array |
|
32 | + * @return integer[] |
|
33 | 33 | */ |
34 | 34 | public function register() { |
35 | 35 | return array( |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | return; |
180 | 180 | } |
181 | 181 | |
182 | - $query = $parameters[1]; |
|
182 | + $query = $parameters[ 1 ]; |
|
183 | 183 | $text_string_tokens_found = false; |
184 | 184 | $variable_found = false; |
185 | 185 | $sql_wildcard_found = false; |
@@ -191,51 +191,51 @@ discard block |
||
191 | 191 | 'adjustment_count' => 0, |
192 | 192 | ); |
193 | 193 | |
194 | - for ( $i = $query['start']; $i <= $query['end']; $i++ ) { |
|
194 | + for ( $i = $query[ 'start' ]; $i <= $query[ 'end' ]; $i++ ) { |
|
195 | 195 | // Skip over groups of tokens if they are part of an inline function call. |
196 | 196 | if ( isset( $skip_from, $skip_to ) && $i >= $skip_from && $i < $skip_to ) { |
197 | 197 | $i = $skip_to; |
198 | 198 | continue; |
199 | 199 | } |
200 | 200 | |
201 | - if ( ! isset( Tokens::$textStringTokens[ $this->tokens[ $i ]['code'] ] ) ) { |
|
202 | - if ( \T_VARIABLE === $this->tokens[ $i ]['code'] ) { |
|
203 | - if ( '$wpdb' !== $this->tokens[ $i ]['content'] ) { |
|
201 | + if ( ! isset( Tokens::$textStringTokens[ $this->tokens[ $i ][ 'code' ] ] ) ) { |
|
202 | + if ( \T_VARIABLE === $this->tokens[ $i ][ 'code' ] ) { |
|
203 | + if ( '$wpdb' !== $this->tokens[ $i ][ 'content' ] ) { |
|
204 | 204 | $variable_found = true; |
205 | 205 | } |
206 | 206 | continue; |
207 | 207 | } |
208 | 208 | |
209 | 209 | // Detect a specific pattern for variable replacements in combination with `IN`. |
210 | - if ( \T_STRING === $this->tokens[ $i ]['code'] ) { |
|
210 | + if ( \T_STRING === $this->tokens[ $i ][ 'code' ] ) { |
|
211 | 211 | |
212 | - if ( 'sprintf' === strtolower( $this->tokens[ $i ]['content'] ) ) { |
|
212 | + if ( 'sprintf' === strtolower( $this->tokens[ $i ][ 'content' ] ) ) { |
|
213 | 213 | $sprintf_parameters = $this->get_function_call_parameters( $i ); |
214 | 214 | |
215 | 215 | if ( ! empty( $sprintf_parameters ) ) { |
216 | - $skip_from = ( $sprintf_parameters[1]['end'] + 1 ); |
|
216 | + $skip_from = ( $sprintf_parameters[ 1 ][ 'end' ] + 1 ); |
|
217 | 217 | $last_param = end( $sprintf_parameters ); |
218 | - $skip_to = ( $last_param['end'] + 1 ); |
|
218 | + $skip_to = ( $last_param[ 'end' ] + 1 ); |
|
219 | 219 | |
220 | - $valid_in_clauses['implode_fill'] += $this->analyse_sprintf( $sprintf_parameters ); |
|
221 | - $valid_in_clauses['adjustment_count'] += ( \count( $sprintf_parameters ) - 1 ); |
|
220 | + $valid_in_clauses[ 'implode_fill' ] += $this->analyse_sprintf( $sprintf_parameters ); |
|
221 | + $valid_in_clauses[ 'adjustment_count' ] += ( \count( $sprintf_parameters ) - 1 ); |
|
222 | 222 | } |
223 | 223 | unset( $sprintf_parameters, $last_param ); |
224 | 224 | |
225 | - } elseif ( 'implode' === strtolower( $this->tokens[ $i ]['content'] ) ) { |
|
225 | + } elseif ( 'implode' === strtolower( $this->tokens[ $i ][ 'content' ] ) ) { |
|
226 | 226 | $prev = $this->phpcsFile->findPrevious( |
227 | 227 | Tokens::$textStringTokens, |
228 | 228 | ( $i - 1 ), |
229 | - $query['start'] |
|
229 | + $query[ 'start' ] |
|
230 | 230 | ); |
231 | 231 | |
232 | - $prev_content = $this->strip_quotes( $this->tokens[ $prev ]['content'] ); |
|
233 | - $regex_quote = $this->get_regex_quote_snippet( $prev_content, $this->tokens[ $prev ]['content'] ); |
|
232 | + $prev_content = $this->strip_quotes( $this->tokens[ $prev ][ 'content' ] ); |
|
233 | + $regex_quote = $this->get_regex_quote_snippet( $prev_content, $this->tokens[ $prev ][ 'content' ] ); |
|
234 | 234 | |
235 | 235 | // Only examine the implode if preceded by an ` IN (`. |
236 | 236 | if ( preg_match( '`\s+IN\s*\(\s*(' . $regex_quote . ')?$`i', $prev_content, $match ) > 0 ) { |
237 | 237 | |
238 | - if ( isset( $match[1] ) && $regex_quote !== $this->regex_quote ) { |
|
238 | + if ( isset( $match[ 1 ] ) && $regex_quote !== $this->regex_quote ) { |
|
239 | 239 | $this->phpcsFile->addError( |
240 | 240 | 'Dynamic placeholder generation should not have surrounding quotes.', |
241 | 241 | $i, |
@@ -244,15 +244,15 @@ discard block |
||
244 | 244 | } |
245 | 245 | |
246 | 246 | if ( $this->analyse_implode( $i ) === true ) { |
247 | - ++$valid_in_clauses['uses_in']; |
|
248 | - ++$valid_in_clauses['implode_fill']; |
|
247 | + ++$valid_in_clauses[ 'uses_in' ]; |
|
248 | + ++$valid_in_clauses[ 'implode_fill' ]; |
|
249 | 249 | |
250 | 250 | $next = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $i + 1 ), null, true ); |
251 | - if ( \T_OPEN_PARENTHESIS === $this->tokens[ $next ]['code'] |
|
252 | - && isset( $this->tokens[ $next ]['parenthesis_closer'] ) |
|
251 | + if ( \T_OPEN_PARENTHESIS === $this->tokens[ $next ][ 'code' ] |
|
252 | + && isset( $this->tokens[ $next ][ 'parenthesis_closer' ] ) |
|
253 | 253 | ) { |
254 | 254 | $skip_from = ( $i + 1 ); |
255 | - $skip_to = ( $this->tokens[ $next ]['parenthesis_closer'] + 1 ); |
|
255 | + $skip_to = ( $this->tokens[ $next ][ 'parenthesis_closer' ] + 1 ); |
|
256 | 256 | } |
257 | 257 | } |
258 | 258 | } |
@@ -264,16 +264,16 @@ discard block |
||
264 | 264 | } |
265 | 265 | |
266 | 266 | $text_string_tokens_found = true; |
267 | - $content = $this->tokens[ $i ]['content']; |
|
267 | + $content = $this->tokens[ $i ][ 'content' ]; |
|
268 | 268 | |
269 | 269 | $regex_quote = $this->regex_quote; |
270 | - if ( isset( Tokens::$stringTokens[ $this->tokens[ $i ]['code'] ] ) ) { |
|
270 | + if ( isset( Tokens::$stringTokens[ $this->tokens[ $i ][ 'code' ] ] ) ) { |
|
271 | 271 | $content = $this->strip_quotes( $content ); |
272 | - $regex_quote = $this->get_regex_quote_snippet( $content, $this->tokens[ $i ]['content'] ); |
|
272 | + $regex_quote = $this->get_regex_quote_snippet( $content, $this->tokens[ $i ][ 'content' ] ); |
|
273 | 273 | } |
274 | 274 | |
275 | - if ( \T_DOUBLE_QUOTED_STRING === $this->tokens[ $i ]['code'] |
|
276 | - || \T_HEREDOC === $this->tokens[ $i ]['code'] |
|
275 | + if ( \T_DOUBLE_QUOTED_STRING === $this->tokens[ $i ][ 'code' ] |
|
276 | + || \T_HEREDOC === $this->tokens[ $i ][ 'code' ] |
|
277 | 277 | ) { |
278 | 278 | // Only interested in actual query text, so strip out variables. |
279 | 279 | $stripped_content = $this->strip_interpolated_variables( $content ); |
@@ -305,23 +305,23 @@ discard block |
||
305 | 305 | $regex = '`\s+LIKE\s*(?:(' . $regex_quote . ')(?!%s(?:\1|$))(?P<content>.*?)(?:\1|$)|(?:concat\((?![^\)]*%s[^\)]*\))(?P<concat>[^\)]*))\))`i'; |
306 | 306 | if ( preg_match_all( $regex, $content, $matches ) > 0 ) { |
307 | 307 | $walk = array(); |
308 | - if ( ! empty( $matches['content'] ) ) { |
|
309 | - $matches['content'] = array_filter( $matches['content'] ); |
|
310 | - if ( ! empty( $matches['content'] ) ) { |
|
311 | - $walk[] = 'content'; |
|
308 | + if ( ! empty( $matches[ 'content' ] ) ) { |
|
309 | + $matches[ 'content' ] = array_filter( $matches[ 'content' ] ); |
|
310 | + if ( ! empty( $matches[ 'content' ] ) ) { |
|
311 | + $walk[ ] = 'content'; |
|
312 | 312 | } |
313 | 313 | } |
314 | - if ( ! empty( $matches['concat'] ) ) { |
|
315 | - $matches['concat'] = array_filter( $matches['concat'] ); |
|
316 | - if ( ! empty( $matches['concat'] ) ) { |
|
317 | - $walk[] = 'concat'; |
|
314 | + if ( ! empty( $matches[ 'concat' ] ) ) { |
|
315 | + $matches[ 'concat' ] = array_filter( $matches[ 'concat' ] ); |
|
316 | + if ( ! empty( $matches[ 'concat' ] ) ) { |
|
317 | + $walk[ ] = 'concat'; |
|
318 | 318 | } |
319 | 319 | } |
320 | 320 | |
321 | 321 | if ( ! empty( $walk ) ) { |
322 | 322 | foreach ( $walk as $match_key ) { |
323 | 323 | foreach ( $matches[ $match_key ] as $index => $match ) { |
324 | - $data = array( $matches[0][ $index ] ); |
|
324 | + $data = array( $matches[ 0 ][ $index ] ); |
|
325 | 325 | |
326 | 326 | // Both a `%` as well as a `_` are wildcards in SQL. |
327 | 327 | if ( strpos( $match, '%' ) === false && strpos( $match, '_' ) === false ) { |
@@ -370,8 +370,8 @@ discard block |
||
370 | 370 | * Analyse the query for unsupported placeholders. |
371 | 371 | */ |
372 | 372 | if ( preg_match_all( self::UNSUPPORTED_PLACEHOLDER_REGEX, $content, $matches ) > 0 ) { |
373 | - if ( ! empty( $matches[0] ) ) { |
|
374 | - foreach ( $matches[0] as $match ) { |
|
373 | + if ( ! empty( $matches[ 0 ] ) ) { |
|
374 | + foreach ( $matches[ 0 ] as $match ) { |
|
375 | 375 | if ( '%' === $match ) { |
376 | 376 | $this->phpcsFile->addError( |
377 | 377 | 'Found unescaped literal "%%" character.', |
@@ -397,8 +397,8 @@ discard block |
||
397 | 397 | */ |
398 | 398 | $regex = '`(' . $regex_quote . ')%[dfFs]\1`'; |
399 | 399 | if ( preg_match_all( $regex, $content, $matches ) > 0 ) { |
400 | - if ( ! empty( $matches[0] ) ) { |
|
401 | - foreach ( $matches[0] as $match ) { |
|
400 | + if ( ! empty( $matches[ 0 ] ) ) { |
|
401 | + foreach ( $matches[ 0 ] as $match ) { |
|
402 | 402 | $this->phpcsFile->addError( |
403 | 403 | 'Simple placeholders should not be quoted in the query string in $wpdb->prepare(). Found: %s.', |
404 | 404 | $i, |
@@ -415,8 +415,8 @@ discard block |
||
415 | 415 | */ |
416 | 416 | $regex = '`(?<!' . $regex_quote . ')' . self::PREPARE_PLACEHOLDER_REGEX . '(?!' . $regex_quote . ')`x'; |
417 | 417 | if ( preg_match_all( $regex, $content, $matches ) > 0 ) { |
418 | - if ( ! empty( $matches[0] ) ) { |
|
419 | - foreach ( $matches[0] as $match ) { |
|
418 | + if ( ! empty( $matches[ 0 ] ) ) { |
|
419 | + foreach ( $matches[ 0 ] as $match ) { |
|
420 | 420 | if ( preg_match( '`%[dfFs]`', $match ) !== 1 ) { |
421 | 421 | $this->phpcsFile->addWarning( |
422 | 422 | 'Complex placeholders used for values in the query string in $wpdb->prepare() will NOT be quoted automagically. Found: %s.', |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | */ |
436 | 436 | $found_in = preg_match_all( '`\s+IN\s*\(\s*%s\s*\)`i', $content, $matches ); |
437 | 437 | if ( $found_in > 0 ) { |
438 | - $valid_in_clauses['uses_in'] += $found_in; |
|
438 | + $valid_in_clauses[ 'uses_in' ] += $found_in; |
|
439 | 439 | } |
440 | 440 | unset( $found_in ); |
441 | 441 | } |
@@ -465,7 +465,7 @@ discard block |
||
465 | 465 | 'UnnecessaryPrepare' |
466 | 466 | ); |
467 | 467 | } |
468 | - } elseif ( false === $count_diff_whitelisted && 0 === $valid_in_clauses['uses_in'] ) { |
|
468 | + } elseif ( false === $count_diff_whitelisted && 0 === $valid_in_clauses[ 'uses_in' ] ) { |
|
469 | 469 | $this->phpcsFile->addWarning( |
470 | 470 | 'Replacement variables found, but no valid placeholders found in the query.', |
471 | 471 | $i, |
@@ -494,28 +494,28 @@ discard block |
||
494 | 494 | array_shift( $replacements ); // Remove the query. |
495 | 495 | |
496 | 496 | // The parameters may have been passed as an array in parameter 2. |
497 | - if ( isset( $parameters[2] ) && 2 === $total_parameters ) { |
|
497 | + if ( isset( $parameters[ 2 ] ) && 2 === $total_parameters ) { |
|
498 | 498 | $next = $this->phpcsFile->findNext( |
499 | 499 | Tokens::$emptyTokens, |
500 | - $parameters[2]['start'], |
|
501 | - ( $parameters[2]['end'] + 1 ), |
|
500 | + $parameters[ 2 ][ 'start' ], |
|
501 | + ( $parameters[ 2 ][ 'end' ] + 1 ), |
|
502 | 502 | true |
503 | 503 | ); |
504 | 504 | |
505 | 505 | if ( false !== $next |
506 | - && ( \T_ARRAY === $this->tokens[ $next ]['code'] |
|
507 | - || \T_OPEN_SHORT_ARRAY === $this->tokens[ $next ]['code'] ) |
|
506 | + && ( \T_ARRAY === $this->tokens[ $next ][ 'code' ] |
|
507 | + || \T_OPEN_SHORT_ARRAY === $this->tokens[ $next ][ 'code' ] ) |
|
508 | 508 | ) { |
509 | 509 | $replacements = $this->get_function_call_parameters( $next ); |
510 | 510 | } |
511 | 511 | } |
512 | 512 | |
513 | 513 | $total_replacements = \count( $replacements ); |
514 | - $total_placeholders -= $valid_in_clauses['adjustment_count']; |
|
514 | + $total_placeholders -= $valid_in_clauses[ 'adjustment_count' ]; |
|
515 | 515 | |
516 | 516 | // Bow out when `IN` clauses have been used which appear to be correct. |
517 | - if ( $valid_in_clauses['uses_in'] > 0 |
|
518 | - && $valid_in_clauses['uses_in'] === $valid_in_clauses['implode_fill'] |
|
517 | + if ( $valid_in_clauses[ 'uses_in' ] > 0 |
|
518 | + && $valid_in_clauses[ 'uses_in' ] === $valid_in_clauses[ 'implode_fill' ] |
|
519 | 519 | && 1 === $total_replacements |
520 | 520 | ) { |
521 | 521 | return; |
@@ -553,7 +553,7 @@ discard block |
||
553 | 553 | $regex_quote = $this->regex_quote; |
554 | 554 | |
555 | 555 | if ( $original_content !== $stripped_content ) { |
556 | - $quote_style = $original_content[0]; |
|
556 | + $quote_style = $original_content[ 0 ]; |
|
557 | 557 | |
558 | 558 | if ( '"' === $quote_style ) { |
559 | 559 | $regex_quote = '\\\\"|\''; |
@@ -581,21 +581,21 @@ discard block |
||
581 | 581 | protected function analyse_sprintf( $sprintf_params ) { |
582 | 582 | $found = 0; |
583 | 583 | |
584 | - unset( $sprintf_params[1] ); |
|
584 | + unset( $sprintf_params[ 1 ] ); |
|
585 | 585 | |
586 | 586 | foreach ( $sprintf_params as $sprintf_param ) { |
587 | - if ( strpos( strtolower( $sprintf_param['raw'] ), 'implode' ) === false ) { |
|
587 | + if ( strpos( strtolower( $sprintf_param[ 'raw' ] ), 'implode' ) === false ) { |
|
588 | 588 | continue; |
589 | 589 | } |
590 | 590 | |
591 | 591 | $implode = $this->phpcsFile->findNext( |
592 | 592 | Tokens::$emptyTokens, |
593 | - $sprintf_param['start'], |
|
594 | - $sprintf_param['end'], |
|
593 | + $sprintf_param[ 'start' ], |
|
594 | + $sprintf_param[ 'end' ], |
|
595 | 595 | true |
596 | 596 | ); |
597 | - if ( \T_STRING === $this->tokens[ $implode ]['code'] |
|
598 | - && 'implode' === strtolower( $this->tokens[ $implode ]['content'] ) |
|
597 | + if ( \T_STRING === $this->tokens[ $implode ][ 'code' ] |
|
598 | + && 'implode' === strtolower( $this->tokens[ $implode ][ 'content' ] ) |
|
599 | 599 | ) { |
600 | 600 | if ( $this->analyse_implode( $implode ) === true ) { |
601 | 601 | ++$found; |
@@ -628,23 +628,23 @@ discard block |
||
628 | 628 | return false; |
629 | 629 | } |
630 | 630 | |
631 | - if ( preg_match( '`^(["\']), ?\1$`', $implode_params[1]['raw'] ) !== 1 ) { |
|
631 | + if ( preg_match( '`^(["\']), ?\1$`', $implode_params[ 1 ][ 'raw' ] ) !== 1 ) { |
|
632 | 632 | return false; |
633 | 633 | } |
634 | 634 | |
635 | - if ( strpos( strtolower( $implode_params[2]['raw'] ), 'array_fill' ) === false ) { |
|
635 | + if ( strpos( strtolower( $implode_params[ 2 ][ 'raw' ] ), 'array_fill' ) === false ) { |
|
636 | 636 | return false; |
637 | 637 | } |
638 | 638 | |
639 | 639 | $array_fill = $this->phpcsFile->findNext( |
640 | 640 | Tokens::$emptyTokens, |
641 | - $implode_params[2]['start'], |
|
642 | - $implode_params[2]['end'], |
|
641 | + $implode_params[ 2 ][ 'start' ], |
|
642 | + $implode_params[ 2 ][ 'end' ], |
|
643 | 643 | true |
644 | 644 | ); |
645 | 645 | |
646 | - if ( \T_STRING !== $this->tokens[ $array_fill ]['code'] |
|
647 | - || 'array_fill' !== strtolower( $this->tokens[ $array_fill ]['content'] ) |
|
646 | + if ( \T_STRING !== $this->tokens[ $array_fill ][ 'code' ] |
|
647 | + || 'array_fill' !== strtolower( $this->tokens[ $array_fill ][ 'content' ] ) |
|
648 | 648 | ) { |
649 | 649 | return false; |
650 | 650 | } |
@@ -655,7 +655,7 @@ discard block |
||
655 | 655 | return false; |
656 | 656 | } |
657 | 657 | |
658 | - return (bool) preg_match( '`^(["\'])%[dfFs]\1$`', $array_fill_params[3]['raw'] ); |
|
658 | + return (bool)preg_match( '`^(["\'])%[dfFs]\1$`', $array_fill_params[ 3 ][ 'raw' ] ); |
|
659 | 659 | } |
660 | 660 | |
661 | 661 | } |
@@ -150,7 +150,7 @@ |
||
150 | 150 | * |
151 | 151 | * @since 0.14.0 |
152 | 152 | * |
153 | - * @return array |
|
153 | + * @return integer[] |
|
154 | 154 | */ |
155 | 155 | public function register() { |
156 | 156 | return array( |