@@ -270,7 +270,7 @@ |
||
270 | 270 | /** |
271 | 271 | * Retrieve a list of misspellings based on an array of matched variations on the target word. |
272 | 272 | * |
273 | - * @param array $match_stack Array of matched variations of the target word. |
|
273 | + * @param string[] $match_stack Array of matched variations of the target word. |
|
274 | 274 | * @return array Array containing only the misspelled variants. |
275 | 275 | */ |
276 | 276 | protected function retrieve_misspellings( $match_stack ) { |
@@ -126,24 +126,24 @@ discard block |
||
126 | 126 | * The return values skip to the end of the array. |
127 | 127 | * This prevents the sniff "hanging" on very long configuration arrays. |
128 | 128 | */ |
129 | - if ( \T_OPEN_SHORT_ARRAY === $this->tokens[ $stackPtr ]['code'] && isset( $this->tokens[ $stackPtr ]['bracket_closer'] ) ) { |
|
130 | - return $this->tokens[ $stackPtr ]['bracket_closer']; |
|
131 | - } elseif ( \T_ARRAY === $this->tokens[ $stackPtr ]['code'] && isset( $this->tokens[ $stackPtr ]['parenthesis_closer'] ) ) { |
|
132 | - return $this->tokens[ $stackPtr ]['parenthesis_closer']; |
|
129 | + if ( \T_OPEN_SHORT_ARRAY === $this->tokens[ $stackPtr ][ 'code' ] && isset( $this->tokens[ $stackPtr ][ 'bracket_closer' ] ) ) { |
|
130 | + return $this->tokens[ $stackPtr ][ 'bracket_closer' ]; |
|
131 | + } elseif ( \T_ARRAY === $this->tokens[ $stackPtr ][ 'code' ] && isset( $this->tokens[ $stackPtr ][ 'parenthesis_closer' ] ) ) { |
|
132 | + return $this->tokens[ $stackPtr ][ 'parenthesis_closer' ]; |
|
133 | 133 | } |
134 | 134 | |
135 | 135 | /* |
136 | 136 | * Deal with misspellings in class/interface/trait names. |
137 | 137 | * These are not auto-fixable, but need the attention of a developer. |
138 | 138 | */ |
139 | - if ( isset( Tokens::$ooScopeTokens[ $this->tokens[ $stackPtr ]['code'] ] ) ) { |
|
139 | + if ( isset( Tokens::$ooScopeTokens[ $this->tokens[ $stackPtr ][ 'code' ] ] ) ) { |
|
140 | 140 | $classname = $this->phpcsFile->getDeclarationName( $stackPtr ); |
141 | 141 | if ( empty( $classname ) ) { |
142 | 142 | return; |
143 | 143 | } |
144 | 144 | |
145 | 145 | if ( preg_match_all( self::WP_CLASSNAME_REGEX, $classname, $matches, \PREG_PATTERN_ORDER ) > 0 ) { |
146 | - $mispelled = $this->retrieve_misspellings( $matches[1] ); |
|
146 | + $mispelled = $this->retrieve_misspellings( $matches[ 1 ] ); |
|
147 | 147 | |
148 | 148 | if ( ! empty( $mispelled ) ) { |
149 | 149 | $this->phpcsFile->addWarning( |
@@ -163,14 +163,14 @@ discard block |
||
163 | 163 | */ |
164 | 164 | |
165 | 165 | // Ignore content of docblock @link tags. |
166 | - if ( \T_DOC_COMMENT_STRING === $this->tokens[ $stackPtr ]['code'] |
|
167 | - || \T_DOC_COMMENT === $this->tokens[ $stackPtr ]['code'] |
|
166 | + if ( \T_DOC_COMMENT_STRING === $this->tokens[ $stackPtr ][ 'code' ] |
|
167 | + || \T_DOC_COMMENT === $this->tokens[ $stackPtr ][ 'code' ] |
|
168 | 168 | ) { |
169 | 169 | |
170 | 170 | $comment_start = $this->phpcsFile->findPrevious( \T_DOC_COMMENT_OPEN_TAG, ( $stackPtr - 1 ) ); |
171 | 171 | if ( false !== $comment_start ) { |
172 | 172 | $comment_tag = $this->phpcsFile->findPrevious( \T_DOC_COMMENT_TAG, ( $stackPtr - 1 ), $comment_start ); |
173 | - if ( false !== $comment_tag && '@link' === $this->tokens[ $comment_tag ]['content'] ) { |
|
173 | + if ( false !== $comment_tag && '@link' === $this->tokens[ $comment_tag ][ 'content' ] ) { |
|
174 | 174 | // @link tag, so ignore. |
175 | 175 | return; |
176 | 176 | } |
@@ -178,11 +178,11 @@ discard block |
||
178 | 178 | } |
179 | 179 | |
180 | 180 | // Ignore any text strings which are array keys `$var['key']` as this is a false positive in 80% of all cases. |
181 | - if ( \T_CONSTANT_ENCAPSED_STRING === $this->tokens[ $stackPtr ]['code'] ) { |
|
181 | + if ( \T_CONSTANT_ENCAPSED_STRING === $this->tokens[ $stackPtr ][ 'code' ] ) { |
|
182 | 182 | $prevToken = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true, null, true ); |
183 | - if ( false !== $prevToken && \T_OPEN_SQUARE_BRACKET === $this->tokens[ $prevToken ]['code'] ) { |
|
183 | + if ( false !== $prevToken && \T_OPEN_SQUARE_BRACKET === $this->tokens[ $prevToken ][ 'code' ] ) { |
|
184 | 184 | $nextToken = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true ); |
185 | - if ( false !== $nextToken && \T_CLOSE_SQUARE_BRACKET === $this->tokens[ $nextToken ]['code'] ) { |
|
185 | + if ( false !== $nextToken && \T_CLOSE_SQUARE_BRACKET === $this->tokens[ $nextToken ][ 'code' ] ) { |
|
186 | 186 | return; |
187 | 187 | } |
188 | 188 | } |
@@ -202,44 +202,44 @@ discard block |
||
202 | 202 | \T_OPEN_CURLY_BRACKET, |
203 | 203 | ); |
204 | 204 | $maybe_const = $this->phpcsFile->findPrevious( $stop_points, ( $stackPtr - 1 ) ); |
205 | - if ( false !== $maybe_const && \T_CONST === $this->tokens[ $maybe_const ]['code'] ) { |
|
205 | + if ( false !== $maybe_const && \T_CONST === $this->tokens[ $maybe_const ][ 'code' ] ) { |
|
206 | 206 | return; |
207 | 207 | } |
208 | 208 | |
209 | - $content = $this->tokens[ $stackPtr ]['content']; |
|
209 | + $content = $this->tokens[ $stackPtr ][ 'content' ]; |
|
210 | 210 | |
211 | 211 | if ( preg_match_all( self::WP_REGEX, $content, $matches, ( \PREG_PATTERN_ORDER | \PREG_OFFSET_CAPTURE ) ) > 0 ) { |
212 | 212 | /* |
213 | 213 | * Prevent some typical false positives. |
214 | 214 | */ |
215 | - if ( isset( $this->text_and_comment_tokens[ $this->tokens[ $stackPtr ]['code'] ] ) ) { |
|
215 | + if ( isset( $this->text_and_comment_tokens[ $this->tokens[ $stackPtr ][ 'code' ] ] ) ) { |
|
216 | 216 | $offset = 0; |
217 | - foreach ( $matches[1] as $key => $match_data ) { |
|
218 | - $next_offset = ( $match_data[1] + \strlen( $match_data[0] ) ); |
|
217 | + foreach ( $matches[ 1 ] as $key => $match_data ) { |
|
218 | + $next_offset = ( $match_data[ 1 ] + \strlen( $match_data[ 0 ] ) ); |
|
219 | 219 | |
220 | 220 | // Prevent matches on part of a URL. |
221 | - if ( preg_match( '`http[s]?://[^\s<>\'"()]*' . preg_quote( $match_data[0], '`' ) . '`', $content, $discard, 0, $offset ) === 1 ) { |
|
222 | - unset( $matches[1][ $key ] ); |
|
223 | - } elseif ( preg_match( '`[a-z]+=(["\'])' . preg_quote( $match_data[0], '`' ) . '\1`', $content, $discard, 0, $offset ) === 1 ) { |
|
221 | + if ( preg_match( '`http[s]?://[^\s<>\'"()]*' . preg_quote( $match_data[ 0 ], '`' ) . '`', $content, $discard, 0, $offset ) === 1 ) { |
|
222 | + unset( $matches[ 1 ][ $key ] ); |
|
223 | + } elseif ( preg_match( '`[a-z]+=(["\'])' . preg_quote( $match_data[ 0 ], '`' ) . '\1`', $content, $discard, 0, $offset ) === 1 ) { |
|
224 | 224 | // Prevent matches on html attributes like: `value="wordpress"`. |
225 | - unset( $matches[1][ $key ] ); |
|
226 | - } elseif ( preg_match( '`\\\\\'' . preg_quote( $match_data[0], '`' ) . '\\\\\'`', $content, $discard, 0, $offset ) === 1 ) { |
|
225 | + unset( $matches[ 1 ][ $key ] ); |
|
226 | + } elseif ( preg_match( '`\\\\\'' . preg_quote( $match_data[ 0 ], '`' ) . '\\\\\'`', $content, $discard, 0, $offset ) === 1 ) { |
|
227 | 227 | // Prevent matches on xpath queries and such: `\'wordpress\'`. |
228 | - unset( $matches[1][ $key ] ); |
|
229 | - } elseif ( preg_match( '`(?:\?|&|&)[a-z0-9_]+=' . preg_quote( $match_data[0], '`' ) . '(?:&|$)`', $content, $discard, 0, $offset ) === 1 ) { |
|
228 | + unset( $matches[ 1 ][ $key ] ); |
|
229 | + } elseif ( preg_match( '`(?:\?|&|&)[a-z0-9_]+=' . preg_quote( $match_data[ 0 ], '`' ) . '(?:&|$)`', $content, $discard, 0, $offset ) === 1 ) { |
|
230 | 230 | // Prevent matches on url query strings: `?something=wordpress`. |
231 | - unset( $matches[1][ $key ] ); |
|
231 | + unset( $matches[ 1 ][ $key ] ); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | $offset = $next_offset; |
235 | 235 | } |
236 | 236 | |
237 | - if ( empty( $matches[1] ) ) { |
|
237 | + if ( empty( $matches[ 1 ] ) ) { |
|
238 | 238 | return; |
239 | 239 | } |
240 | 240 | } |
241 | 241 | |
242 | - $mispelled = $this->retrieve_misspellings( $matches[1] ); |
|
242 | + $mispelled = $this->retrieve_misspellings( $matches[ 1 ] ); |
|
243 | 243 | |
244 | 244 | if ( empty( $mispelled ) ) { |
245 | 245 | return; |
@@ -258,8 +258,8 @@ discard block |
||
258 | 258 | if ( true === $fix ) { |
259 | 259 | // Apply fixes based on offset to ensure we don't replace false positives. |
260 | 260 | $replacement = $content; |
261 | - foreach ( $matches[1] as $match ) { |
|
262 | - $replacement = substr_replace( $replacement, 'WordPress', $match[1], \strlen( $match[0] ) ); |
|
261 | + foreach ( $matches[ 1 ] as $match ) { |
|
262 | + $replacement = substr_replace( $replacement, 'WordPress', $match[ 1 ], \strlen( $match[ 0 ] ) ); |
|
263 | 263 | } |
264 | 264 | |
265 | 265 | $this->phpcsFile->fixer->replaceToken( $stackPtr, $replacement ); |
@@ -278,11 +278,11 @@ discard block |
||
278 | 278 | foreach ( $match_stack as $match ) { |
279 | 279 | // Deal with multi-dimensional arrays when capturing offset. |
280 | 280 | if ( \is_array( $match ) ) { |
281 | - $match = $match[0]; |
|
281 | + $match = $match[ 0 ]; |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | if ( 'WordPress' !== $match ) { |
285 | - $mispelled[] = $match; |
|
285 | + $mispelled[ ] = $match; |
|
286 | 286 | } |
287 | 287 | } |
288 | 288 |
@@ -28,7 +28,7 @@ |
||
28 | 28 | /** |
29 | 29 | * Returns an array of tokens this test wants to listen for. |
30 | 30 | * |
31 | - * @return array |
|
31 | + * @return string[] |
|
32 | 32 | */ |
33 | 33 | public function register() { |
34 | 34 | return array( |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | public function process_token( $stackPtr ) { |
47 | 47 | |
48 | 48 | $token = $this->tokens[ $stackPtr ]; |
49 | - if ( ! isset( $token['bracket_closer'] ) ) { |
|
49 | + if ( ! isset( $token[ 'bracket_closer' ] ) ) { |
|
50 | 50 | $this->phpcsFile->addWarning( 'Missing bracket closer.', $stackPtr, 'MissingBracketCloser' ); |
51 | 51 | return; |
52 | 52 | } |
@@ -54,12 +54,12 @@ discard block |
||
54 | 54 | $need_spaces = $this->phpcsFile->findNext( |
55 | 55 | array( \T_CONSTANT_ENCAPSED_STRING, \T_LNUMBER, \T_WHITESPACE, \T_MINUS ), |
56 | 56 | ( $stackPtr + 1 ), |
57 | - $token['bracket_closer'], |
|
57 | + $token[ 'bracket_closer' ], |
|
58 | 58 | true |
59 | 59 | ); |
60 | 60 | |
61 | - $spaced1 = ( \T_WHITESPACE === $this->tokens[ ( $stackPtr + 1 ) ]['code'] ); |
|
62 | - $spaced2 = ( \T_WHITESPACE === $this->tokens[ ( $token['bracket_closer'] - 1 ) ]['code'] ); |
|
61 | + $spaced1 = ( \T_WHITESPACE === $this->tokens[ ( $stackPtr + 1 ) ][ 'code' ] ); |
|
62 | + $spaced2 = ( \T_WHITESPACE === $this->tokens[ ( $token[ 'bracket_closer' ] - 1 ) ][ 'code' ] ); |
|
63 | 63 | |
64 | 64 | // It should have spaces unless if it only has strings or numbers as the key. |
65 | 65 | if ( false !== $need_spaces && ! ( $spaced1 && $spaced2 ) ) { |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | $this->phpcsFile->fixer->addContentBefore( ( $stackPtr + 1 ), ' ' ); |
71 | 71 | } |
72 | 72 | if ( ! $spaced2 ) { |
73 | - $this->phpcsFile->fixer->addContentBefore( $token['bracket_closer'], ' ' ); |
|
73 | + $this->phpcsFile->fixer->addContentBefore( $token[ 'bracket_closer' ], ' ' ); |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 | } elseif ( false === $need_spaces && ( $spaced1 || $spaced2 ) ) { |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | $this->phpcsFile->fixer->replaceToken( ( $stackPtr + 1 ), '' ); |
82 | 82 | } |
83 | 83 | if ( $spaced2 ) { |
84 | - $this->phpcsFile->fixer->replaceToken( ( $token['bracket_closer'] - 1 ), '' ); |
|
84 | + $this->phpcsFile->fixer->replaceToken( ( $token[ 'bracket_closer' ] - 1 ), '' ); |
|
85 | 85 | } |
86 | 86 | } |
87 | 87 | } |
@@ -51,7 +51,7 @@ |
||
51 | 51 | /** |
52 | 52 | * Returns an array of tokens this test wants to listen for. |
53 | 53 | * |
54 | - * @return array |
|
54 | + * @return integer[] |
|
55 | 55 | */ |
56 | 56 | public function register() { |
57 | 57 | /* |
@@ -91,10 +91,10 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function process_token( $stackPtr ) { |
93 | 93 | // Make sure we have the right token, JS vs PHP. |
94 | - if ( ( 'PHP' === $this->phpcsFile->tokenizerType && \T_NEW !== $this->tokens[ $stackPtr ]['code'] ) |
|
94 | + if ( ( 'PHP' === $this->phpcsFile->tokenizerType && \T_NEW !== $this->tokens[ $stackPtr ][ 'code' ] ) |
|
95 | 95 | || ( 'JS' === $this->phpcsFile->tokenizerType |
96 | - && ( \T_STRING !== $this->tokens[ $stackPtr ]['code'] |
|
97 | - || 'new' !== strtolower( $this->tokens[ $stackPtr ]['content'] ) ) ) |
|
96 | + && ( \T_STRING !== $this->tokens[ $stackPtr ][ 'code' ] |
|
97 | + || 'new' !== strtolower( $this->tokens[ $stackPtr ][ 'content' ] ) ) ) |
|
98 | 98 | ) { |
99 | 99 | return; |
100 | 100 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | true |
111 | 111 | ); |
112 | 112 | |
113 | - if ( false !== $prev_non_empty && 'T_BITWISE_AND' === $this->tokens[ $prev_non_empty ]['type'] ) { |
|
113 | + if ( false !== $prev_non_empty && 'T_BITWISE_AND' === $this->tokens[ $prev_non_empty ][ 'type' ] ) { |
|
114 | 114 | $this->phpcsFile->recordMetric( $stackPtr, 'Assigning new by reference', 'yes' ); |
115 | 115 | |
116 | 116 | $this->phpcsFile->addError( |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | // Walk back to the last part of the class name. |
144 | 144 | $has_comment = false; |
145 | 145 | for ( $classname_ptr = ( $next_non_empty_after_class_name - 1 ); $classname_ptr >= $stackPtr; $classname_ptr-- ) { |
146 | - if ( ! isset( Tokens::$emptyTokens[ $this->tokens[ $classname_ptr ]['code'] ] ) ) { |
|
146 | + if ( ! isset( Tokens::$emptyTokens[ $this->tokens[ $classname_ptr ][ 'code' ] ] ) ) { |
|
147 | 147 | // Prevent a false positive on variable variables, disregard them for now. |
148 | 148 | if ( $stackPtr === $classname_ptr ) { |
149 | 149 | return; |
@@ -152,12 +152,12 @@ discard block |
||
152 | 152 | break; |
153 | 153 | } |
154 | 154 | |
155 | - if ( \T_WHITESPACE !== $this->tokens[ $classname_ptr ]['code'] ) { |
|
155 | + if ( \T_WHITESPACE !== $this->tokens[ $classname_ptr ][ 'code' ] ) { |
|
156 | 156 | $has_comment = true; |
157 | 157 | } |
158 | 158 | } |
159 | 159 | |
160 | - if ( \T_OPEN_PARENTHESIS !== $this->tokens[ $next_non_empty_after_class_name ]['code'] ) { |
|
160 | + if ( \T_OPEN_PARENTHESIS !== $this->tokens[ $next_non_empty_after_class_name ][ 'code' ] ) { |
|
161 | 161 | $this->phpcsFile->recordMetric( $stackPtr, 'Object instantiation with parenthesis', 'no' ); |
162 | 162 | |
163 | 163 | $fix = $this->phpcsFile->addFixableError( |
@@ -115,7 +115,7 @@ |
||
115 | 115 | /** |
116 | 116 | * Returns an array of tokens this test wants to listen for. |
117 | 117 | * |
118 | - * @return array |
|
118 | + * @return integer[] |
|
119 | 119 | */ |
120 | 120 | public function register() { |
121 | 121 | if ( \defined( '\PHP_CODESNIFFER_IN_TESTS' ) ) { |
@@ -148,18 +148,18 @@ discard block |
||
148 | 148 | if ( \defined( '\T_PHPCS_DISABLE' ) && \defined( '\T_PHPCS_ENABLE' ) ) { |
149 | 149 | $i = -1; |
150 | 150 | while ( $i = $this->phpcsFile->findNext( \T_PHPCS_DISABLE, ( $i + 1 ) ) ) { |
151 | - if ( empty( $this->tokens[ $i ]['sniffCodes'] ) |
|
152 | - || isset( $this->tokens[ $i ]['sniffCodes']['WordPress'] ) |
|
153 | - || isset( $this->tokens[ $i ]['sniffCodes']['WordPress.Files'] ) |
|
154 | - || isset( $this->tokens[ $i ]['sniffCodes']['WordPress.Files.FileName'] ) |
|
151 | + if ( empty( $this->tokens[ $i ][ 'sniffCodes' ] ) |
|
152 | + || isset( $this->tokens[ $i ][ 'sniffCodes' ][ 'WordPress' ] ) |
|
153 | + || isset( $this->tokens[ $i ][ 'sniffCodes' ][ 'WordPress.Files' ] ) |
|
154 | + || isset( $this->tokens[ $i ][ 'sniffCodes' ][ 'WordPress.Files.FileName' ] ) |
|
155 | 155 | ) { |
156 | 156 | do { |
157 | 157 | $i = $this->phpcsFile->findNext( \T_PHPCS_ENABLE, ( $i + 1 ) ); |
158 | 158 | } while ( false !== $i |
159 | - && ! empty( $this->tokens[ $i ]['sniffCodes'] ) |
|
160 | - && ! isset( $this->tokens[ $i ]['sniffCodes']['WordPress'] ) |
|
161 | - && ! isset( $this->tokens[ $i ]['sniffCodes']['WordPress.Files'] ) |
|
162 | - && ! isset( $this->tokens[ $i ]['sniffCodes']['WordPress.Files.FileName'] ) ); |
|
159 | + && ! empty( $this->tokens[ $i ][ 'sniffCodes' ] ) |
|
160 | + && ! isset( $this->tokens[ $i ][ 'sniffCodes' ][ 'WordPress' ] ) |
|
161 | + && ! isset( $this->tokens[ $i ][ 'sniffCodes' ][ 'WordPress.Files' ] ) |
|
162 | + && ! isset( $this->tokens[ $i ][ 'sniffCodes' ][ 'WordPress.Files.FileName' ] ) ); |
|
163 | 163 | |
164 | 164 | if ( false === $i ) { |
165 | 165 | // The entire (rest of the) file is disabled. |
@@ -221,8 +221,8 @@ discard block |
||
221 | 221 | $fileName_end = substr( $fileName, -13 ); |
222 | 222 | $has_class = $this->phpcsFile->findNext( \T_CLASS, $stackPtr ); |
223 | 223 | |
224 | - if ( ( 'Template' === trim( $this->tokens[ $subpackage ]['content'] ) |
|
225 | - && $this->tokens[ $subpackage_tag ]['line'] === $this->tokens[ $subpackage ]['line'] ) |
|
224 | + if ( ( 'Template' === trim( $this->tokens[ $subpackage ][ 'content' ] ) |
|
225 | + && $this->tokens[ $subpackage_tag ][ 'line' ] === $this->tokens[ $subpackage ][ 'line' ] ) |
|
226 | 226 | && ( ( ! \defined( '\PHP_CODESNIFFER_IN_TESTS' ) && '-template.php' !== $fileName_end ) |
227 | 227 | || ( \defined( '\PHP_CODESNIFFER_IN_TESTS' ) && '-template.inc' !== $fileName_end ) ) |
228 | 228 | && false === $has_class |
@@ -155,7 +155,7 @@ |
||
155 | 155 | * |
156 | 156 | * @since 1.1.0 |
157 | 157 | * |
158 | - * @return array |
|
158 | + * @return string[] |
|
159 | 159 | */ |
160 | 160 | public function register() { |
161 | 161 | $this->empty_tokens = Tokens::$emptyTokens; |
@@ -184,10 +184,10 @@ discard block |
||
184 | 184 | * Check if the error silencing is done for one of the whitelisted functions. |
185 | 185 | */ |
186 | 186 | $next_non_empty = $this->phpcsFile->findNext( $this->empty_tokens, ( $stackPtr + 1 ), null, true, null, true ); |
187 | - if ( false !== $next_non_empty && \T_STRING === $this->tokens[ $next_non_empty ]['code'] ) { |
|
187 | + if ( false !== $next_non_empty && \T_STRING === $this->tokens[ $next_non_empty ][ 'code' ] ) { |
|
188 | 188 | $has_parenthesis = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $next_non_empty + 1 ), null, true, null, true ); |
189 | - if ( false !== $has_parenthesis && \T_OPEN_PARENTHESIS === $this->tokens[ $has_parenthesis ]['code'] ) { |
|
190 | - $function_name = strtolower( $this->tokens[ $next_non_empty ]['content'] ); |
|
189 | + if ( false !== $has_parenthesis && \T_OPEN_PARENTHESIS === $this->tokens[ $has_parenthesis ][ 'code' ] ) { |
|
190 | + $function_name = strtolower( $this->tokens[ $next_non_empty ][ 'content' ] ); |
|
191 | 191 | if ( ( true === $this->use_default_whitelist |
192 | 192 | && isset( $this->function_whitelist[ $function_name ] ) === true ) |
193 | 193 | || in_array( $function_name, $this->custom_whitelist, true ) === true |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | } |
200 | 200 | } |
201 | 201 | |
202 | - $this->context_length = (int) $this->context_length; |
|
202 | + $this->context_length = (int)$this->context_length; |
|
203 | 203 | $context_length = $this->context_length; |
204 | 204 | if ( $this->context_length <= 0 ) { |
205 | 205 | $context_length = 2; |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | $data = array(); |
218 | 218 | if ( $this->context_length > 0 ) { |
219 | 219 | $error_msg .= ' Found: %s'; |
220 | - $data[] = $found; |
|
220 | + $data[ ] = $found; |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | $this->phpcsFile->addWarning( |
@@ -62,7 +62,7 @@ |
||
62 | 62 | * @param mixed $val Assigned value. |
63 | 63 | * @param int $line Token line. |
64 | 64 | * @param array $group Group definition. |
65 | - * @return mixed FALSE if no match, TRUE if matches, STRING if matches |
|
65 | + * @return string|false FALSE if no match, TRUE if matches, STRING if matches |
|
66 | 66 | * with custom error message passed to ->process(). |
67 | 67 | */ |
68 | 68 | public function callback( $key, $val, $line, $group ) { |
@@ -66,7 +66,7 @@ |
||
66 | 66 | * with custom error message passed to ->process(). |
67 | 67 | */ |
68 | 68 | public function callback( $key, $val, $line, $group ) { |
69 | - $this->posts_per_page = (int) $this->posts_per_page; |
|
69 | + $this->posts_per_page = (int)$this->posts_per_page; |
|
70 | 70 | |
71 | 71 | if ( $val > $this->posts_per_page ) { |
72 | 72 | return 'Detected high pagination limit, `%s` is set to `%s`'; |
@@ -505,8 +505,8 @@ discard block |
||
505 | 505 | */ |
506 | 506 | private function get_php_version() { |
507 | 507 | |
508 | - return ! empty( $GLOBALS['GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE'] ) ? |
|
509 | - $GLOBALS['GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE'] : phpversion(); |
|
508 | + return ! empty( $GLOBALS[ 'GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE' ] ) ? |
|
509 | + $GLOBALS[ 'GRAVITYVIEW_TESTS_PHP_VERSION_OVERRIDE' ] : phpversion(); |
|
510 | 510 | } |
511 | 511 | |
512 | 512 | /** |
@@ -518,8 +518,8 @@ discard block |
||
518 | 518 | */ |
519 | 519 | private function get_wordpress_version() { |
520 | 520 | |
521 | - return ! empty( $GLOBALS['GRAVITYVIEW_TESTS_WP_VERSION_OVERRIDE'] ) ? |
|
522 | - $GLOBALS['GRAVITYVIEW_TESTS_WP_VERSION_OVERRIDE'] : $GLOBALS['wp_version']; |
|
521 | + return ! empty( $GLOBALS[ 'GRAVITYVIEW_TESTS_WP_VERSION_OVERRIDE' ] ) ? |
|
522 | + $GLOBALS[ 'GRAVITYVIEW_TESTS_WP_VERSION_OVERRIDE' ] : $GLOBALS[ 'wp_version' ]; |
|
523 | 523 | } |
524 | 524 | |
525 | 525 | /** |
@@ -531,14 +531,14 @@ discard block |
||
531 | 531 | */ |
532 | 532 | private function get_gravityforms_version() { |
533 | 533 | |
534 | - if ( ! class_exists( '\GFCommon' ) || ! empty( $GLOBALS['GRAVITYVIEW_TESTS_GF_INACTIVE_OVERRIDE'] ) ) { |
|
534 | + if ( ! class_exists( '\GFCommon' ) || ! empty( $GLOBALS[ 'GRAVITYVIEW_TESTS_GF_INACTIVE_OVERRIDE' ] ) ) { |
|
535 | 535 | gravityview()->log->error( 'Gravity Forms is inactive or not installed.' ); |
536 | 536 | |
537 | 537 | return null; |
538 | 538 | } |
539 | 539 | |
540 | - return ! empty( $GLOBALS['GRAVITYVIEW_TESTS_GF_VERSION_OVERRIDE'] ) ? |
|
541 | - $GLOBALS['GRAVITYVIEW_TESTS_GF_VERSION_OVERRIDE'] : \GFCommon::$version; |
|
540 | + return ! empty( $GLOBALS[ 'GRAVITYVIEW_TESTS_GF_VERSION_OVERRIDE' ] ) ? |
|
541 | + $GLOBALS[ 'GRAVITYVIEW_TESTS_GF_VERSION_OVERRIDE' ] : \GFCommon::$version; |
|
542 | 542 | } |
543 | 543 | |
544 | 544 | /** |
@@ -584,7 +584,7 @@ discard block |
||
584 | 584 | $items = get_posts( array( |
585 | 585 | 'post_type' => 'gravityview', |
586 | 586 | 'post_status' => 'any', |
587 | - 'numberposts' => - 1, |
|
587 | + 'numberposts' => -1, |
|
588 | 588 | 'fields' => 'ids', |
589 | 589 | ) ); |
590 | 590 | |
@@ -598,9 +598,9 @@ discard block |
||
598 | 598 | $tables = array(); |
599 | 599 | |
600 | 600 | if ( version_compare( \GravityView_GFFormsModel::get_database_version(), '2.3-dev-1', '>=' ) ) { |
601 | - $tables [] = \GFFormsModel::get_entry_meta_table_name(); |
|
601 | + $tables [ ] = \GFFormsModel::get_entry_meta_table_name(); |
|
602 | 602 | } elseif ( ! $this->is_GF_25() ) { |
603 | - $tables [] = \GFFormsModel::get_lead_meta_table_name(); |
|
603 | + $tables [ ] = \GFFormsModel::get_lead_meta_table_name(); |
|
604 | 604 | } |
605 | 605 | |
606 | 606 | foreach ( $tables as $meta_table ) { |
@@ -619,9 +619,9 @@ discard block |
||
619 | 619 | $tables = array(); |
620 | 620 | |
621 | 621 | if ( version_compare( \GravityView_GFFormsModel::get_database_version(), '2.3-dev-1', '>=' ) && method_exists( 'GFFormsModel', 'get_entry_notes_table_name' ) ) { |
622 | - $tables[] = \GFFormsModel::get_entry_notes_table_name(); |
|
622 | + $tables[ ] = \GFFormsModel::get_entry_notes_table_name(); |
|
623 | 623 | } elseif ( ! $this->is_GF_25() ) { |
624 | - $tables[] = \GFFormsModel::get_lead_notes_table_name(); |
|
624 | + $tables[ ] = \GFFormsModel::get_lead_notes_table_name(); |
|
625 | 625 | } |
626 | 626 | |
627 | 627 | $disapproved = __( 'Disapproved the Entry for GravityView', 'gravityview' ); |
@@ -1105,10 +1105,10 @@ discard block |
||
1105 | 1105 | protected function get_last_ptr_on_line( $stackPtr ) { |
1106 | 1106 | |
1107 | 1107 | $tokens = $this->tokens; |
1108 | - $currentLine = $tokens[ $stackPtr ]['line']; |
|
1108 | + $currentLine = $tokens[ $stackPtr ][ 'line' ]; |
|
1109 | 1109 | $nextPtr = ( $stackPtr + 1 ); |
1110 | 1110 | |
1111 | - while ( isset( $tokens[ $nextPtr ] ) && $tokens[ $nextPtr ]['line'] === $currentLine ) { |
|
1111 | + while ( isset( $tokens[ $nextPtr ] ) && $tokens[ $nextPtr ][ 'line' ] === $currentLine ) { |
|
1112 | 1112 | $nextPtr++; |
1113 | 1113 | // Do nothing, we just want the last token of the line. |
1114 | 1114 | } |
@@ -1186,27 +1186,27 @@ discard block |
||
1186 | 1186 | |
1187 | 1187 | if ( false !== $end_of_statement ) { |
1188 | 1188 | // If the statement was ended by a semicolon, check if there is a whitelist comment directly after it. |
1189 | - if ( \T_SEMICOLON === $this->tokens[ $end_of_statement ]['code'] ) { |
|
1189 | + if ( \T_SEMICOLON === $this->tokens[ $end_of_statement ][ 'code' ] ) { |
|
1190 | 1190 | $lastPtr = $this->phpcsFile->findNext( \T_WHITESPACE, ( $end_of_statement + 1 ), null, true ); |
1191 | - } elseif ( \T_CLOSE_TAG === $this->tokens[ $end_of_statement ]['code'] ) { |
|
1191 | + } elseif ( \T_CLOSE_TAG === $this->tokens[ $end_of_statement ][ 'code' ] ) { |
|
1192 | 1192 | // If the semicolon was left out and it was terminated by an ending tag, we need to look backwards. |
1193 | 1193 | $lastPtr = $this->phpcsFile->findPrevious( \T_WHITESPACE, ( $end_of_statement - 1 ), null, true ); |
1194 | 1194 | } |
1195 | 1195 | |
1196 | - if ( ( \T_COMMENT === $this->tokens[ $lastPtr ]['code'] |
|
1197 | - || ( isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $lastPtr ]['code'] ] ) |
|
1198 | - && \T_PHPCS_SET !== $this->tokens[ $lastPtr ]['code'] ) ) |
|
1199 | - && $this->tokens[ $lastPtr ]['line'] === $this->tokens[ $end_of_statement ]['line'] |
|
1200 | - && preg_match( $regex, $this->tokens[ $lastPtr ]['content'] ) === 1 |
|
1196 | + if ( ( \T_COMMENT === $this->tokens[ $lastPtr ][ 'code' ] |
|
1197 | + || ( isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $lastPtr ][ 'code' ] ] ) |
|
1198 | + && \T_PHPCS_SET !== $this->tokens[ $lastPtr ][ 'code' ] ) ) |
|
1199 | + && $this->tokens[ $lastPtr ][ 'line' ] === $this->tokens[ $end_of_statement ][ 'line' ] |
|
1200 | + && preg_match( $regex, $this->tokens[ $lastPtr ][ 'content' ] ) === 1 |
|
1201 | 1201 | ) { |
1202 | 1202 | if ( isset( $thrown_notices[ $filename ][ $lastPtr ] ) === false |
1203 | - && isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $lastPtr ]['code'] ] ) === false |
|
1203 | + && isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $lastPtr ][ 'code' ] ] ) === false |
|
1204 | 1204 | ) { |
1205 | 1205 | $this->phpcsFile->addWarning( |
1206 | 1206 | $deprecation_notice, |
1207 | 1207 | $lastPtr, |
1208 | 1208 | $deprecation_code, |
1209 | - array( $this->tokens[ $lastPtr ]['content'] ) |
|
1209 | + array( $this->tokens[ $lastPtr ][ 'content' ] ) |
|
1210 | 1210 | ); |
1211 | 1211 | |
1212 | 1212 | $thrown_notices[ $filename ][ $lastPtr ] = true; |
@@ -1221,20 +1221,20 @@ discard block |
||
1221 | 1221 | $end_of_line = $this->get_last_ptr_on_line( $stackPtr ); |
1222 | 1222 | $lastPtr = $this->phpcsFile->findPrevious( \T_WHITESPACE, $end_of_line, null, true ); |
1223 | 1223 | |
1224 | - if ( ( \T_COMMENT === $this->tokens[ $lastPtr ]['code'] |
|
1225 | - || ( isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $lastPtr ]['code'] ] ) |
|
1226 | - && \T_PHPCS_SET !== $this->tokens[ $lastPtr ]['code'] ) ) |
|
1227 | - && $this->tokens[ $lastPtr ]['line'] === $this->tokens[ $stackPtr ]['line'] |
|
1228 | - && preg_match( $regex, $this->tokens[ $lastPtr ]['content'] ) === 1 |
|
1224 | + if ( ( \T_COMMENT === $this->tokens[ $lastPtr ][ 'code' ] |
|
1225 | + || ( isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $lastPtr ][ 'code' ] ] ) |
|
1226 | + && \T_PHPCS_SET !== $this->tokens[ $lastPtr ][ 'code' ] ) ) |
|
1227 | + && $this->tokens[ $lastPtr ][ 'line' ] === $this->tokens[ $stackPtr ][ 'line' ] |
|
1228 | + && preg_match( $regex, $this->tokens[ $lastPtr ][ 'content' ] ) === 1 |
|
1229 | 1229 | ) { |
1230 | 1230 | if ( isset( $thrown_notices[ $filename ][ $lastPtr ] ) === false |
1231 | - && isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $lastPtr ]['code'] ] ) === false |
|
1231 | + && isset( Tokens::$phpcsCommentTokens[ $this->tokens[ $lastPtr ][ 'code' ] ] ) === false |
|
1232 | 1232 | ) { |
1233 | 1233 | $this->phpcsFile->addWarning( |
1234 | 1234 | $deprecation_notice, |
1235 | 1235 | $lastPtr, |
1236 | 1236 | $deprecation_code, |
1237 | - array( $this->tokens[ $lastPtr ]['content'] ) |
|
1237 | + array( $this->tokens[ $lastPtr ][ 'content' ] ) |
|
1238 | 1238 | ); |
1239 | 1239 | |
1240 | 1240 | $thrown_notices[ $filename ][ $lastPtr ] = true; |
@@ -1268,7 +1268,7 @@ discard block |
||
1268 | 1268 | return false; |
1269 | 1269 | } |
1270 | 1270 | |
1271 | - $conditions = $this->tokens[ $stackPtr ]['conditions']; |
|
1271 | + $conditions = $this->tokens[ $stackPtr ][ 'conditions' ]; |
|
1272 | 1272 | foreach ( $conditions as $token => $condition ) { |
1273 | 1273 | if ( $token === $functionToken ) { |
1274 | 1274 | // Only examine the conditions the function is nested in, not those nested within the function. |
@@ -1303,7 +1303,7 @@ discard block |
||
1303 | 1303 | */ |
1304 | 1304 | protected function is_test_class( $stackPtr ) { |
1305 | 1305 | |
1306 | - if ( isset( $this->tokens[ $stackPtr ], Tokens::$ooScopeTokens[ $this->tokens[ $stackPtr ]['code'] ] ) === false ) { |
|
1306 | + if ( isset( $this->tokens[ $stackPtr ], Tokens::$ooScopeTokens[ $this->tokens[ $stackPtr ][ 'code' ] ] ) === false ) { |
|
1307 | 1307 | return false; |
1308 | 1308 | } |
1309 | 1309 | |
@@ -1334,7 +1334,7 @@ discard block |
||
1334 | 1334 | |
1335 | 1335 | // Does the class/trait extend one of the whitelisted test classes ? |
1336 | 1336 | $extendedClassName = $this->phpcsFile->findExtendedClassName( $stackPtr ); |
1337 | - if ( '\\' === $extendedClassName[0] ) { |
|
1337 | + if ( '\\' === $extendedClassName[ 0 ] ) { |
|
1338 | 1338 | if ( isset( $whitelist[ substr( $extendedClassName, 1 ) ] ) ) { |
1339 | 1339 | return true; |
1340 | 1340 | } |
@@ -1380,7 +1380,7 @@ discard block |
||
1380 | 1380 | ); |
1381 | 1381 | |
1382 | 1382 | // Must be a variable, constant or closing square bracket (see below). |
1383 | - if ( ! isset( $valid[ $this->tokens[ $stackPtr ]['code'] ] ) ) { |
|
1383 | + if ( ! isset( $valid[ $this->tokens[ $stackPtr ][ 'code' ] ] ) ) { |
|
1384 | 1384 | return false; |
1385 | 1385 | } |
1386 | 1386 | |
@@ -1399,15 +1399,15 @@ discard block |
||
1399 | 1399 | } |
1400 | 1400 | |
1401 | 1401 | // If the next token is an assignment, that's all we need to know. |
1402 | - if ( isset( Tokens::$assignmentTokens[ $this->tokens[ $next_non_empty ]['code'] ] ) ) { |
|
1402 | + if ( isset( Tokens::$assignmentTokens[ $this->tokens[ $next_non_empty ][ 'code' ] ] ) ) { |
|
1403 | 1403 | return true; |
1404 | 1404 | } |
1405 | 1405 | |
1406 | 1406 | // Check if this is an array assignment, e.g., `$var['key'] = 'val';` . |
1407 | - if ( \T_OPEN_SQUARE_BRACKET === $this->tokens[ $next_non_empty ]['code'] |
|
1408 | - && isset( $this->tokens[ $next_non_empty ]['bracket_closer'] ) |
|
1407 | + if ( \T_OPEN_SQUARE_BRACKET === $this->tokens[ $next_non_empty ][ 'code' ] |
|
1408 | + && isset( $this->tokens[ $next_non_empty ][ 'bracket_closer' ] ) |
|
1409 | 1409 | ) { |
1410 | - return $this->is_assignment( $this->tokens[ $next_non_empty ]['bracket_closer'] ); |
|
1410 | + return $this->is_assignment( $this->tokens[ $next_non_empty ][ 'bracket_closer' ] ); |
|
1411 | 1411 | } |
1412 | 1412 | |
1413 | 1413 | return false; |
@@ -1444,12 +1444,12 @@ discard block |
||
1444 | 1444 | |
1445 | 1445 | // If we're in a function, only look inside of it. |
1446 | 1446 | // Once PHPCS 3.5.0 comes out this should be changed to the new Conditions::GetLastCondition() method. |
1447 | - if ( isset( $tokens[ $stackPtr ]['conditions'] ) === true ) { |
|
1448 | - $conditions = $tokens[ $stackPtr ]['conditions']; |
|
1447 | + if ( isset( $tokens[ $stackPtr ][ 'conditions' ] ) === true ) { |
|
1448 | + $conditions = $tokens[ $stackPtr ][ 'conditions' ]; |
|
1449 | 1449 | $conditions = array_reverse( $conditions, true ); |
1450 | 1450 | foreach ( $conditions as $tokenPtr => $condition ) { |
1451 | 1451 | if ( \T_FUNCTION === $condition || \T_CLOSURE === $condition ) { |
1452 | - $start = $tokens[ $tokenPtr ]['scope_opener']; |
|
1452 | + $start = $tokens[ $tokenPtr ][ 'scope_opener' ]; |
|
1453 | 1453 | break; |
1454 | 1454 | } |
1455 | 1455 | } |
@@ -1470,23 +1470,23 @@ discard block |
||
1470 | 1470 | // If this superglobal is inside such a check, look for the nonce after it as well, |
1471 | 1471 | // all the way to the end of the scope. |
1472 | 1472 | if ( true === $allow_nonce_after ) { |
1473 | - $end = ( 0 === $start ) ? $this->phpcsFile->numTokens : $tokens[ $start ]['scope_closer']; |
|
1473 | + $end = ( 0 === $start ) ? $this->phpcsFile->numTokens : $tokens[ $start ][ 'scope_closer' ]; |
|
1474 | 1474 | } |
1475 | 1475 | |
1476 | 1476 | // Check if we've looked here before. |
1477 | 1477 | $filename = $this->phpcsFile->getFilename(); |
1478 | 1478 | |
1479 | 1479 | if ( |
1480 | - $filename === $last['file'] |
|
1481 | - && $start === $last['start'] |
|
1480 | + $filename === $last[ 'file' ] |
|
1481 | + && $start === $last[ 'start' ] |
|
1482 | 1482 | ) { |
1483 | 1483 | |
1484 | - if ( false !== $last['nonce_check'] ) { |
|
1484 | + if ( false !== $last[ 'nonce_check' ] ) { |
|
1485 | 1485 | // If we have already found an nonce check in this scope, we just |
1486 | 1486 | // need to check whether it comes before this token. It is OK if the |
1487 | 1487 | // check is after the token though, if this was only a isset() check. |
1488 | - return ( true === $allow_nonce_after || $last['nonce_check'] < $stackPtr ); |
|
1489 | - } elseif ( $end <= $last['end'] ) { |
|
1488 | + return ( true === $allow_nonce_after || $last[ 'nonce_check' ] < $stackPtr ); |
|
1489 | + } elseif ( $end <= $last[ 'end' ] ) { |
|
1490 | 1490 | // If not, we can still go ahead and return false if we've already |
1491 | 1491 | // checked to the end of the search area. |
1492 | 1492 | return false; |
@@ -1494,7 +1494,7 @@ discard block |
||
1494 | 1494 | |
1495 | 1495 | // We haven't checked this far yet, but we can still save work by |
1496 | 1496 | // skipping over the part we've already checked. |
1497 | - $start = $last['end']; |
|
1497 | + $start = $last[ 'end' ]; |
|
1498 | 1498 | } else { |
1499 | 1499 | $last = array( |
1500 | 1500 | 'file' => $filename, |
@@ -1506,23 +1506,23 @@ discard block |
||
1506 | 1506 | // Loop through the tokens looking for nonce verification functions. |
1507 | 1507 | for ( $i = $start; $i < $end; $i++ ) { |
1508 | 1508 | // Skip over nested closed scope constructs. |
1509 | - if ( \T_FUNCTION === $tokens[ $i ]['code'] |
|
1510 | - || \T_CLOSURE === $tokens[ $i ]['code'] |
|
1511 | - || isset( Tokens::$ooScopeTokens[ $tokens[ $i ]['code'] ] ) |
|
1509 | + if ( \T_FUNCTION === $tokens[ $i ][ 'code' ] |
|
1510 | + || \T_CLOSURE === $tokens[ $i ][ 'code' ] |
|
1511 | + || isset( Tokens::$ooScopeTokens[ $tokens[ $i ][ 'code' ] ] ) |
|
1512 | 1512 | ) { |
1513 | - if ( isset( $tokens[ $i ]['scope_closer'] ) ) { |
|
1514 | - $i = $tokens[ $i ]['scope_closer']; |
|
1513 | + if ( isset( $tokens[ $i ][ 'scope_closer' ] ) ) { |
|
1514 | + $i = $tokens[ $i ][ 'scope_closer' ]; |
|
1515 | 1515 | } |
1516 | 1516 | continue; |
1517 | 1517 | } |
1518 | 1518 | |
1519 | 1519 | // If this isn't a function name, skip it. |
1520 | - if ( \T_STRING !== $tokens[ $i ]['code'] ) { |
|
1520 | + if ( \T_STRING !== $tokens[ $i ][ 'code' ] ) { |
|
1521 | 1521 | continue; |
1522 | 1522 | } |
1523 | 1523 | |
1524 | 1524 | // If this is one of the nonce verification functions, we can bail out. |
1525 | - if ( isset( $this->nonceVerificationFunctions[ $tokens[ $i ]['content'] ] ) ) { |
|
1525 | + if ( isset( $this->nonceVerificationFunctions[ $tokens[ $i ][ 'content' ] ] ) ) { |
|
1526 | 1526 | /* |
1527 | 1527 | * Now, make sure it is a call to a global function. |
1528 | 1528 | */ |
@@ -1534,13 +1534,13 @@ discard block |
||
1534 | 1534 | continue; |
1535 | 1535 | } |
1536 | 1536 | |
1537 | - $last['nonce_check'] = $i; |
|
1537 | + $last[ 'nonce_check' ] = $i; |
|
1538 | 1538 | return true; |
1539 | 1539 | } |
1540 | 1540 | } |
1541 | 1541 | |
1542 | 1542 | // We're still here, so no luck. |
1543 | - $last['nonce_check'] = false; |
|
1543 | + $last[ 'nonce_check' ] = false; |
|
1544 | 1544 | |
1545 | 1545 | return false; |
1546 | 1546 | } |
@@ -1558,11 +1558,11 @@ discard block |
||
1558 | 1558 | */ |
1559 | 1559 | protected function is_in_isset_or_empty( $stackPtr ) { |
1560 | 1560 | |
1561 | - if ( ! isset( $this->tokens[ $stackPtr ]['nested_parenthesis'] ) ) { |
|
1561 | + if ( ! isset( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) ) { |
|
1562 | 1562 | return false; |
1563 | 1563 | } |
1564 | 1564 | |
1565 | - $nested_parenthesis = $this->tokens[ $stackPtr ]['nested_parenthesis']; |
|
1565 | + $nested_parenthesis = $this->tokens[ $stackPtr ][ 'nested_parenthesis' ]; |
|
1566 | 1566 | |
1567 | 1567 | end( $nested_parenthesis ); |
1568 | 1568 | $open_parenthesis = key( $nested_parenthesis ); |
@@ -1572,7 +1572,7 @@ discard block |
||
1572 | 1572 | return false; |
1573 | 1573 | } |
1574 | 1574 | |
1575 | - $previous_code = $this->tokens[ $previous_non_empty ]['code']; |
|
1575 | + $previous_code = $this->tokens[ $previous_non_empty ][ 'code' ]; |
|
1576 | 1576 | if ( \T_ISSET === $previous_code || \T_EMPTY === $previous_code ) { |
1577 | 1577 | return true; |
1578 | 1578 | } |
@@ -1585,7 +1585,7 @@ discard block |
||
1585 | 1585 | $functionPtr = $this->is_in_function_call( $stackPtr, $valid_functions ); |
1586 | 1586 | if ( false !== $functionPtr ) { |
1587 | 1587 | $second_param = $this->get_function_call_parameter( $functionPtr, 2 ); |
1588 | - if ( $stackPtr >= $second_param['start'] && $stackPtr <= $second_param['end'] ) { |
|
1588 | + if ( $stackPtr >= $second_param[ 'start' ] && $stackPtr <= $second_param[ 'end' ] ) { |
|
1589 | 1589 | return true; |
1590 | 1590 | } |
1591 | 1591 | } |
@@ -1612,8 +1612,8 @@ discard block |
||
1612 | 1612 | return false; |
1613 | 1613 | } |
1614 | 1614 | |
1615 | - if ( \T_OBJECT_OPERATOR !== $this->tokens[ $before ]['code'] |
|
1616 | - && \T_DOUBLE_COLON !== $this->tokens[ $before ]['code'] |
|
1615 | + if ( \T_OBJECT_OPERATOR !== $this->tokens[ $before ][ 'code' ] |
|
1616 | + && \T_DOUBLE_COLON !== $this->tokens[ $before ][ 'code' ] |
|
1617 | 1617 | ) { |
1618 | 1618 | return false; |
1619 | 1619 | } |
@@ -1640,7 +1640,7 @@ discard block |
||
1640 | 1640 | return false; |
1641 | 1641 | } |
1642 | 1642 | |
1643 | - if ( \T_NS_SEPARATOR !== $this->tokens[ $prev ]['code'] ) { |
|
1643 | + if ( \T_NS_SEPARATOR !== $this->tokens[ $prev ][ 'code' ] ) { |
|
1644 | 1644 | return false; |
1645 | 1645 | } |
1646 | 1646 | |
@@ -1649,8 +1649,8 @@ discard block |
||
1649 | 1649 | return false; |
1650 | 1650 | } |
1651 | 1651 | |
1652 | - if ( \T_STRING !== $this->tokens[ $before_prev ]['code'] |
|
1653 | - && \T_NAMESPACE !== $this->tokens[ $before_prev ]['code'] |
|
1652 | + if ( \T_STRING !== $this->tokens[ $before_prev ][ 'code' ] |
|
1653 | + && \T_NAMESPACE !== $this->tokens[ $before_prev ][ 'code' ] |
|
1654 | 1654 | ) { |
1655 | 1655 | return false; |
1656 | 1656 | } |
@@ -1691,11 +1691,11 @@ discard block |
||
1691 | 1691 | * @return int|bool Stack pointer to the function call T_STRING token or false otherwise. |
1692 | 1692 | */ |
1693 | 1693 | protected function is_in_function_call( $stackPtr, $valid_functions, $global = true, $allow_nested = false ) { |
1694 | - if ( ! isset( $this->tokens[ $stackPtr ]['nested_parenthesis'] ) ) { |
|
1694 | + if ( ! isset( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) ) { |
|
1695 | 1695 | return false; |
1696 | 1696 | } |
1697 | 1697 | |
1698 | - $nested_parenthesis = $this->tokens[ $stackPtr ]['nested_parenthesis']; |
|
1698 | + $nested_parenthesis = $this->tokens[ $stackPtr ][ 'nested_parenthesis' ]; |
|
1699 | 1699 | if ( false === $allow_nested ) { |
1700 | 1700 | $nested_parenthesis = array_reverse( $nested_parenthesis, true ); |
1701 | 1701 | } |
@@ -1703,11 +1703,11 @@ discard block |
||
1703 | 1703 | foreach ( $nested_parenthesis as $open => $close ) { |
1704 | 1704 | |
1705 | 1705 | $prev_non_empty = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $open - 1 ), null, true, null, true ); |
1706 | - if ( false === $prev_non_empty || \T_STRING !== $this->tokens[ $prev_non_empty ]['code'] ) { |
|
1706 | + if ( false === $prev_non_empty || \T_STRING !== $this->tokens[ $prev_non_empty ][ 'code' ] ) { |
|
1707 | 1707 | continue; |
1708 | 1708 | } |
1709 | 1709 | |
1710 | - if ( isset( $valid_functions[ strtolower( $this->tokens[ $prev_non_empty ]['content'] ) ] ) === false ) { |
|
1710 | + if ( isset( $valid_functions[ strtolower( $this->tokens[ $prev_non_empty ][ 'content' ] ) ] ) === false ) { |
|
1711 | 1711 | if ( false === $allow_nested ) { |
1712 | 1712 | // Function call encountered, but not to one of the allowed functions. |
1713 | 1713 | return false; |
@@ -1752,7 +1752,7 @@ discard block |
||
1752 | 1752 | * The return can never be `0` as there will always be a PHP open tag before the |
1753 | 1753 | * function call. |
1754 | 1754 | */ |
1755 | - return (bool) $this->is_in_function_call( $stackPtr, $this->typeTestFunctions ); |
|
1755 | + return (bool)$this->is_in_function_call( $stackPtr, $this->typeTestFunctions ); |
|
1756 | 1756 | } |
1757 | 1757 | |
1758 | 1758 | /** |
@@ -1773,7 +1773,7 @@ discard block |
||
1773 | 1773 | |
1774 | 1774 | // If this isn't set, we know the value must have only been casted, because |
1775 | 1775 | // is_sanitized() would have returned false otherwise. |
1776 | - if ( ! isset( $this->tokens[ $stackPtr ]['nested_parenthesis'] ) ) { |
|
1776 | + if ( ! isset( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) ) { |
|
1777 | 1777 | return true; |
1778 | 1778 | } |
1779 | 1779 | |
@@ -1785,7 +1785,7 @@ discard block |
||
1785 | 1785 | |
1786 | 1786 | // The only parentheses should belong to the sanitizing function. If there's |
1787 | 1787 | // more than one set, this isn't *only* sanitization. |
1788 | - return ( \count( $this->tokens[ $stackPtr ]['nested_parenthesis'] ) === 1 ); |
|
1788 | + return ( \count( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) === 1 ); |
|
1789 | 1789 | } |
1790 | 1790 | |
1791 | 1791 | /** |
@@ -1812,7 +1812,7 @@ discard block |
||
1812 | 1812 | } |
1813 | 1813 | |
1814 | 1814 | // Check if it is a safe cast. |
1815 | - return isset( $this->safe_casts[ $this->tokens[ $prev ]['code'] ] ); |
|
1815 | + return isset( $this->safe_casts[ $this->tokens[ $prev ][ 'code' ] ] ); |
|
1816 | 1816 | } |
1817 | 1817 | |
1818 | 1818 | /** |
@@ -1834,7 +1834,7 @@ discard block |
||
1834 | 1834 | } |
1835 | 1835 | |
1836 | 1836 | // If this isn't within a function call, we know already that it's not safe. |
1837 | - if ( ! isset( $this->tokens[ $stackPtr ]['nested_parenthesis'] ) ) { |
|
1837 | + if ( ! isset( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) ) { |
|
1838 | 1838 | if ( $require_unslash ) { |
1839 | 1839 | $this->add_unslash_error( $stackPtr ); |
1840 | 1840 | } |
@@ -1843,13 +1843,13 @@ discard block |
||
1843 | 1843 | } |
1844 | 1844 | |
1845 | 1845 | // Get the function that it's in. |
1846 | - $nested_parenthesis = $this->tokens[ $stackPtr ]['nested_parenthesis']; |
|
1846 | + $nested_parenthesis = $this->tokens[ $stackPtr ][ 'nested_parenthesis' ]; |
|
1847 | 1847 | $nested_openers = array_keys( $nested_parenthesis ); |
1848 | 1848 | $function_opener = array_pop( $nested_openers ); |
1849 | 1849 | $functionPtr = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $function_opener - 1 ), null, true, null, true ); |
1850 | 1850 | |
1851 | 1851 | // If it is just being unset, the value isn't used at all, so it's safe. |
1852 | - if ( \T_UNSET === $this->tokens[ $functionPtr ]['code'] ) { |
|
1852 | + if ( \T_UNSET === $this->tokens[ $functionPtr ][ 'code' ] ) { |
|
1853 | 1853 | return true; |
1854 | 1854 | } |
1855 | 1855 | |
@@ -1869,7 +1869,7 @@ discard block |
||
1869 | 1869 | return false; |
1870 | 1870 | } |
1871 | 1871 | |
1872 | - $functionName = $this->tokens[ $functionPtr ]['content']; |
|
1872 | + $functionName = $this->tokens[ $functionPtr ][ 'content' ]; |
|
1873 | 1873 | |
1874 | 1874 | // Check if an unslashing function is being used. |
1875 | 1875 | if ( isset( $this->unslashingFunctions[ $functionName ] ) ) { |
@@ -1888,7 +1888,7 @@ discard block |
||
1888 | 1888 | } |
1889 | 1889 | |
1890 | 1890 | $functionPtr = $higherFunctionPtr; |
1891 | - $functionName = $this->tokens[ $functionPtr ]['content']; |
|
1891 | + $functionName = $this->tokens[ $functionPtr ][ 'content' ]; |
|
1892 | 1892 | |
1893 | 1893 | } else { |
1894 | 1894 | $is_unslashed = false; |
@@ -1907,13 +1907,13 @@ discard block |
||
1907 | 1907 | */ |
1908 | 1908 | $first_non_empty = $this->phpcsFile->findNext( |
1909 | 1909 | Tokens::$emptyTokens, |
1910 | - $callback['start'], |
|
1911 | - ( $callback['end'] + 1 ), |
|
1910 | + $callback[ 'start' ], |
|
1911 | + ( $callback[ 'end' ] + 1 ), |
|
1912 | 1912 | true |
1913 | 1913 | ); |
1914 | 1914 | |
1915 | - if ( false !== $first_non_empty && \T_CONSTANT_ENCAPSED_STRING === $this->tokens[ $first_non_empty ]['code'] ) { |
|
1916 | - $functionName = $this->strip_quotes( $this->tokens[ $first_non_empty ]['content'] ); |
|
1915 | + if ( false !== $first_non_empty && \T_CONSTANT_ENCAPSED_STRING === $this->tokens[ $first_non_empty ][ 'code' ] ) { |
|
1916 | + $functionName = $this->strip_quotes( $this->tokens[ $first_non_empty ][ 'content' ] ); |
|
1917 | 1917 | } |
1918 | 1918 | } |
1919 | 1919 | } |
@@ -1944,7 +1944,7 @@ discard block |
||
1944 | 1944 | '%s data not unslashed before sanitization. Use wp_unslash() or similar', |
1945 | 1945 | $stackPtr, |
1946 | 1946 | 'MissingUnslash', |
1947 | - array( $this->tokens[ $stackPtr ]['content'] ) |
|
1947 | + array( $this->tokens[ $stackPtr ][ 'content' ] ) |
|
1948 | 1948 | ); |
1949 | 1949 | } |
1950 | 1950 | |
@@ -1966,7 +1966,7 @@ discard block |
||
1966 | 1966 | |
1967 | 1967 | $keys = array(); |
1968 | 1968 | |
1969 | - if ( \T_VARIABLE !== $this->tokens[ $stackPtr ]['code'] ) { |
|
1969 | + if ( \T_VARIABLE !== $this->tokens[ $stackPtr ][ 'code' ] ) { |
|
1970 | 1970 | return $keys; |
1971 | 1971 | } |
1972 | 1972 | |
@@ -1983,19 +1983,19 @@ discard block |
||
1983 | 1983 | |
1984 | 1984 | // If it isn't a bracket, this isn't an array-access. |
1985 | 1985 | if ( false === $open_bracket |
1986 | - || \T_OPEN_SQUARE_BRACKET !== $this->tokens[ $open_bracket ]['code'] |
|
1987 | - || ! isset( $this->tokens[ $open_bracket ]['bracket_closer'] ) |
|
1986 | + || \T_OPEN_SQUARE_BRACKET !== $this->tokens[ $open_bracket ][ 'code' ] |
|
1987 | + || ! isset( $this->tokens[ $open_bracket ][ 'bracket_closer' ] ) |
|
1988 | 1988 | ) { |
1989 | 1989 | break; |
1990 | 1990 | } |
1991 | 1991 | |
1992 | 1992 | $key = $this->phpcsFile->getTokensAsString( |
1993 | 1993 | ( $open_bracket + 1 ), |
1994 | - ( $this->tokens[ $open_bracket ]['bracket_closer'] - $open_bracket - 1 ) |
|
1994 | + ( $this->tokens[ $open_bracket ][ 'bracket_closer' ] - $open_bracket - 1 ) |
|
1995 | 1995 | ); |
1996 | 1996 | |
1997 | - $keys[] = trim( $key ); |
|
1998 | - $current = $this->tokens[ $open_bracket ]['bracket_closer']; |
|
1997 | + $keys[ ] = trim( $key ); |
|
1998 | + $current = $this->tokens[ $open_bracket ][ 'bracket_closer' ]; |
|
1999 | 1999 | } while ( isset( $this->tokens[ $current ] ) && true === $all ); |
2000 | 2000 | |
2001 | 2001 | return $keys; |
@@ -2017,8 +2017,8 @@ discard block |
||
2017 | 2017 | |
2018 | 2018 | $keys = $this->get_array_access_keys( $stackPtr, false ); |
2019 | 2019 | |
2020 | - if ( isset( $keys[0] ) ) { |
|
2021 | - return $keys[0]; |
|
2020 | + if ( isset( $keys[ 0 ] ) ) { |
|
2021 | + return $keys[ 0 ]; |
|
2022 | 2022 | } |
2023 | 2023 | |
2024 | 2024 | return false; |
@@ -2072,22 +2072,22 @@ discard block |
||
2072 | 2072 | */ |
2073 | 2073 | |
2074 | 2074 | // If there are no conditions, there's no validation. |
2075 | - if ( empty( $this->tokens[ $stackPtr ]['conditions'] ) ) { |
|
2075 | + if ( empty( $this->tokens[ $stackPtr ][ 'conditions' ] ) ) { |
|
2076 | 2076 | return false; |
2077 | 2077 | } |
2078 | 2078 | |
2079 | - $conditions = $this->tokens[ $stackPtr ]['conditions']; |
|
2079 | + $conditions = $this->tokens[ $stackPtr ][ 'conditions' ]; |
|
2080 | 2080 | end( $conditions ); // Get closest condition. |
2081 | 2081 | $conditionPtr = key( $conditions ); |
2082 | 2082 | $condition = $this->tokens[ $conditionPtr ]; |
2083 | 2083 | |
2084 | - if ( ! isset( $condition['parenthesis_opener'] ) ) { |
|
2084 | + if ( ! isset( $condition[ 'parenthesis_opener' ] ) ) { |
|
2085 | 2085 | // Live coding or parse error. |
2086 | 2086 | return false; |
2087 | 2087 | } |
2088 | 2088 | |
2089 | - $scope_start = $condition['parenthesis_opener']; |
|
2090 | - $scope_end = $condition['parenthesis_closer']; |
|
2089 | + $scope_start = $condition[ 'parenthesis_opener' ]; |
|
2090 | + $scope_end = $condition[ 'parenthesis_closer' ]; |
|
2091 | 2091 | |
2092 | 2092 | } else { |
2093 | 2093 | /* |
@@ -2102,14 +2102,14 @@ discard block |
||
2102 | 2102 | |
2103 | 2103 | // If so, we check only within the function, otherwise the whole file. |
2104 | 2104 | if ( false !== $function ) { |
2105 | - $scope_start = $this->tokens[ $function ]['scope_opener']; |
|
2105 | + $scope_start = $this->tokens[ $function ][ 'scope_opener' ]; |
|
2106 | 2106 | } else { |
2107 | 2107 | // Check if we are in a closure. |
2108 | 2108 | $closure = $this->phpcsFile->getCondition( $stackPtr, \T_CLOSURE ); |
2109 | 2109 | |
2110 | 2110 | // If so, we check only within the closure. |
2111 | 2111 | if ( false !== $closure ) { |
2112 | - $scope_start = $this->tokens[ $closure ]['scope_opener']; |
|
2112 | + $scope_start = $this->tokens[ $closure ][ 'scope_opener' ]; |
|
2113 | 2113 | } |
2114 | 2114 | } |
2115 | 2115 | |
@@ -2117,7 +2117,7 @@ discard block |
||
2117 | 2117 | } |
2118 | 2118 | |
2119 | 2119 | if ( ! empty( $array_keys ) && ! is_array( $array_keys ) ) { |
2120 | - $array_keys = (array) $array_keys; |
|
2120 | + $array_keys = (array)$array_keys; |
|
2121 | 2121 | } |
2122 | 2122 | |
2123 | 2123 | $bare_array_keys = array_map( array( $this, 'strip_quotes' ), $array_keys ); |
@@ -2133,28 +2133,28 @@ discard block |
||
2133 | 2133 | // phpcs:ignore Generic.CodeAnalysis.JumbledIncrementer.Found -- On purpose, see below. |
2134 | 2134 | for ( $i = ( $scope_start + 1 ); $i < $scope_end; $i++ ) { |
2135 | 2135 | |
2136 | - if ( isset( $targets[ $this->tokens[ $i ]['code'] ] ) === false ) { |
|
2136 | + if ( isset( $targets[ $this->tokens[ $i ][ 'code' ] ] ) === false ) { |
|
2137 | 2137 | continue; |
2138 | 2138 | } |
2139 | 2139 | |
2140 | - switch ( $targets[ $this->tokens[ $i ]['code'] ] ) { |
|
2140 | + switch ( $targets[ $this->tokens[ $i ][ 'code' ] ] ) { |
|
2141 | 2141 | case 'construct': |
2142 | 2142 | $issetOpener = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $i + 1 ), null, true, null, true ); |
2143 | - if ( false === $issetOpener || \T_OPEN_PARENTHESIS !== $this->tokens[ $issetOpener ]['code'] ) { |
|
2143 | + if ( false === $issetOpener || \T_OPEN_PARENTHESIS !== $this->tokens[ $issetOpener ][ 'code' ] ) { |
|
2144 | 2144 | // Parse error or live coding. |
2145 | 2145 | continue 2; |
2146 | 2146 | } |
2147 | 2147 | |
2148 | - $issetCloser = $this->tokens[ $issetOpener ]['parenthesis_closer']; |
|
2148 | + $issetCloser = $this->tokens[ $issetOpener ][ 'parenthesis_closer' ]; |
|
2149 | 2149 | |
2150 | 2150 | // Look for this variable. We purposely stomp $i from the parent loop. |
2151 | 2151 | for ( $i = ( $issetOpener + 1 ); $i < $issetCloser; $i++ ) { |
2152 | 2152 | |
2153 | - if ( \T_VARIABLE !== $this->tokens[ $i ]['code'] ) { |
|
2153 | + if ( \T_VARIABLE !== $this->tokens[ $i ][ 'code' ] ) { |
|
2154 | 2154 | continue; |
2155 | 2155 | } |
2156 | 2156 | |
2157 | - if ( $this->tokens[ $stackPtr ]['content'] !== $this->tokens[ $i ]['content'] ) { |
|
2157 | + if ( $this->tokens[ $stackPtr ][ 'content' ] !== $this->tokens[ $i ][ 'content' ] ) { |
|
2158 | 2158 | continue; |
2159 | 2159 | } |
2160 | 2160 | |
@@ -2176,14 +2176,14 @@ discard block |
||
2176 | 2176 | |
2177 | 2177 | case 'function_call': |
2178 | 2178 | // Only check calls to array_key_exists() and key_exists(). |
2179 | - if ( 'array_key_exists' !== $this->tokens[ $i ]['content'] |
|
2180 | - && 'key_exists' !== $this->tokens[ $i ]['content'] |
|
2179 | + if ( 'array_key_exists' !== $this->tokens[ $i ][ 'content' ] |
|
2180 | + && 'key_exists' !== $this->tokens[ $i ][ 'content' ] |
|
2181 | 2181 | ) { |
2182 | 2182 | continue 2; |
2183 | 2183 | } |
2184 | 2184 | |
2185 | 2185 | $next_non_empty = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $i + 1 ), null, true, null, true ); |
2186 | - if ( false === $next_non_empty || \T_OPEN_PARENTHESIS !== $this->tokens[ $next_non_empty ]['code'] ) { |
|
2186 | + if ( false === $next_non_empty || \T_OPEN_PARENTHESIS !== $this->tokens[ $next_non_empty ][ 'code' ] ) { |
|
2187 | 2187 | // Not a function call. |
2188 | 2188 | continue 2; |
2189 | 2189 | } |
@@ -2203,10 +2203,10 @@ discard block |
||
2203 | 2203 | continue 2; |
2204 | 2204 | } |
2205 | 2205 | |
2206 | - $param2_first_token = $this->phpcsFile->findNext( Tokens::$emptyTokens, $params[2]['start'], ( $params[2]['end'] + 1 ), true ); |
|
2206 | + $param2_first_token = $this->phpcsFile->findNext( Tokens::$emptyTokens, $params[ 2 ][ 'start' ], ( $params[ 2 ][ 'end' ] + 1 ), true ); |
|
2207 | 2207 | if ( false === $param2_first_token |
2208 | - || \T_VARIABLE !== $this->tokens[ $param2_first_token ]['code'] |
|
2209 | - || $this->tokens[ $param2_first_token ]['content'] !== $this->tokens[ $stackPtr ]['content'] |
|
2208 | + || \T_VARIABLE !== $this->tokens[ $param2_first_token ][ 'code' ] |
|
2209 | + || $this->tokens[ $param2_first_token ][ 'content' ] !== $this->tokens[ $stackPtr ][ 'content' ] |
|
2210 | 2210 | ) { |
2211 | 2211 | continue 2; |
2212 | 2212 | } |
@@ -2233,7 +2233,7 @@ discard block |
||
2233 | 2233 | |
2234 | 2234 | // If that failed, try getting an exact match for the subset against the |
2235 | 2235 | // second parameter and the last key against the first. |
2236 | - if ( $bare_keys === $found_keys && $this->strip_quotes( $params[1]['raw'] ) === $last_key ) { |
|
2236 | + if ( $bare_keys === $found_keys && $this->strip_quotes( $params[ 1 ][ 'raw' ] ) === $last_key ) { |
|
2237 | 2237 | return true; |
2238 | 2238 | } |
2239 | 2239 | |
@@ -2248,8 +2248,8 @@ discard block |
||
2248 | 2248 | do { |
2249 | 2249 | $prev = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $prev - 1 ), null, true, null, true ); |
2250 | 2250 | // Skip over array keys, like $_GET['key']['subkey']. |
2251 | - if ( \T_CLOSE_SQUARE_BRACKET === $this->tokens[ $prev ]['code'] ) { |
|
2252 | - $prev = $this->tokens[ $prev ]['bracket_opener']; |
|
2251 | + if ( \T_CLOSE_SQUARE_BRACKET === $this->tokens[ $prev ][ 'code' ] ) { |
|
2252 | + $prev = $this->tokens[ $prev ][ 'bracket_opener' ]; |
|
2253 | 2253 | continue; |
2254 | 2254 | } |
2255 | 2255 | |
@@ -2257,11 +2257,11 @@ discard block |
||
2257 | 2257 | } while ( $prev >= ( $scope_start + 1 ) ); |
2258 | 2258 | |
2259 | 2259 | // We should now have reached the variable. |
2260 | - if ( \T_VARIABLE !== $this->tokens[ $prev ]['code'] ) { |
|
2260 | + if ( \T_VARIABLE !== $this->tokens[ $prev ][ 'code' ] ) { |
|
2261 | 2261 | continue 2; |
2262 | 2262 | } |
2263 | 2263 | |
2264 | - if ( $this->tokens[ $prev ]['content'] !== $this->tokens[ $stackPtr ]['content'] ) { |
|
2264 | + if ( $this->tokens[ $prev ][ 'content' ] !== $this->tokens[ $stackPtr ][ 'content' ] ) { |
|
2265 | 2265 | continue 2; |
2266 | 2266 | } |
2267 | 2267 | |
@@ -2310,13 +2310,13 @@ discard block |
||
2310 | 2310 | } |
2311 | 2311 | |
2312 | 2312 | // We first check if this is a switch statement (switch ( $var )). |
2313 | - if ( isset( $this->tokens[ $stackPtr ]['nested_parenthesis'] ) ) { |
|
2314 | - $nested_parenthesis = $this->tokens[ $stackPtr ]['nested_parenthesis']; |
|
2313 | + if ( isset( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) ) { |
|
2314 | + $nested_parenthesis = $this->tokens[ $stackPtr ][ 'nested_parenthesis' ]; |
|
2315 | 2315 | $close_parenthesis = end( $nested_parenthesis ); |
2316 | 2316 | |
2317 | 2317 | if ( |
2318 | - isset( $this->tokens[ $close_parenthesis ]['parenthesis_owner'] ) |
|
2319 | - && \T_SWITCH === $this->tokens[ $this->tokens[ $close_parenthesis ]['parenthesis_owner'] ]['code'] |
|
2318 | + isset( $this->tokens[ $close_parenthesis ][ 'parenthesis_owner' ] ) |
|
2319 | + && \T_SWITCH === $this->tokens[ $this->tokens[ $close_parenthesis ][ 'parenthesis_owner' ] ][ 'code' ] |
|
2320 | 2320 | ) { |
2321 | 2321 | return true; |
2322 | 2322 | } |
@@ -2331,7 +2331,7 @@ discard block |
||
2331 | 2331 | true |
2332 | 2332 | ); |
2333 | 2333 | |
2334 | - if ( isset( $comparisonTokens[ $this->tokens[ $previous_token ]['code'] ] ) ) { |
|
2334 | + if ( isset( $comparisonTokens[ $this->tokens[ $previous_token ][ 'code' ] ] ) ) { |
|
2335 | 2335 | return true; |
2336 | 2336 | } |
2337 | 2337 | |
@@ -2344,17 +2344,17 @@ discard block |
||
2344 | 2344 | ); |
2345 | 2345 | |
2346 | 2346 | // This might be an opening square bracket in the case of arrays ($var['a']). |
2347 | - while ( false !== $next_token && \T_OPEN_SQUARE_BRACKET === $this->tokens[ $next_token ]['code'] ) { |
|
2347 | + while ( false !== $next_token && \T_OPEN_SQUARE_BRACKET === $this->tokens[ $next_token ][ 'code' ] ) { |
|
2348 | 2348 | |
2349 | 2349 | $next_token = $this->phpcsFile->findNext( |
2350 | 2350 | Tokens::$emptyTokens, |
2351 | - ( $this->tokens[ $next_token ]['bracket_closer'] + 1 ), |
|
2351 | + ( $this->tokens[ $next_token ][ 'bracket_closer' ] + 1 ), |
|
2352 | 2352 | null, |
2353 | 2353 | true |
2354 | 2354 | ); |
2355 | 2355 | } |
2356 | 2356 | |
2357 | - if ( false !== $next_token && isset( $comparisonTokens[ $this->tokens[ $next_token ]['code'] ] ) ) { |
|
2357 | + if ( false !== $next_token && isset( $comparisonTokens[ $this->tokens[ $next_token ][ 'code' ] ] ) ) { |
|
2358 | 2358 | return true; |
2359 | 2359 | } |
2360 | 2360 | |
@@ -2377,7 +2377,7 @@ discard block |
||
2377 | 2377 | return false; |
2378 | 2378 | } |
2379 | 2379 | |
2380 | - $function_name = $this->tokens[ $function_ptr ]['content']; |
|
2380 | + $function_name = $this->tokens[ $function_ptr ][ 'content' ]; |
|
2381 | 2381 | if ( true === $this->arrayCompareFunctions[ $function_name ] ) { |
2382 | 2382 | return true; |
2383 | 2383 | } |
@@ -2412,7 +2412,7 @@ discard block |
||
2412 | 2412 | // USE keywords inside closures. |
2413 | 2413 | $next = $this->phpcsFile->findNext( \T_WHITESPACE, ( $stackPtr + 1 ), null, true ); |
2414 | 2414 | |
2415 | - if ( \T_OPEN_PARENTHESIS === $this->tokens[ $next ]['code'] ) { |
|
2415 | + if ( \T_OPEN_PARENTHESIS === $this->tokens[ $next ][ 'code' ] ) { |
|
2416 | 2416 | return 'closure'; |
2417 | 2417 | } |
2418 | 2418 | |
@@ -2445,8 +2445,8 @@ discard block |
||
2445 | 2445 | $variables = array(); |
2446 | 2446 | if ( preg_match_all( '/(?P<backslashes>\\\\*)\$(?P<symbol>\w+)/', $string, $match_sets, \PREG_SET_ORDER ) ) { |
2447 | 2447 | foreach ( $match_sets as $matches ) { |
2448 | - if ( ! isset( $matches['backslashes'] ) || ( \strlen( $matches['backslashes'] ) % 2 ) === 0 ) { |
|
2449 | - $variables[] = $matches['symbol']; |
|
2448 | + if ( ! isset( $matches[ 'backslashes' ] ) || ( \strlen( $matches[ 'backslashes' ] ) % 2 ) === 0 ) { |
|
2449 | + $variables[ ] = $matches[ 'symbol' ]; |
|
2450 | 2450 | } |
2451 | 2451 | } |
2452 | 2452 | } |
@@ -2498,19 +2498,19 @@ discard block |
||
2498 | 2498 | } |
2499 | 2499 | |
2500 | 2500 | // Is this one of the tokens this function handles ? |
2501 | - if ( false === \in_array( $this->tokens[ $stackPtr ]['code'], array( \T_STRING, \T_ARRAY, \T_OPEN_SHORT_ARRAY ), true ) ) { |
|
2501 | + if ( false === \in_array( $this->tokens[ $stackPtr ][ 'code' ], array( \T_STRING, \T_ARRAY, \T_OPEN_SHORT_ARRAY ), true ) ) { |
|
2502 | 2502 | return false; |
2503 | 2503 | } |
2504 | 2504 | |
2505 | 2505 | $next_non_empty = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true ); |
2506 | 2506 | |
2507 | 2507 | // Deal with short array syntax. |
2508 | - if ( 'T_OPEN_SHORT_ARRAY' === $this->tokens[ $stackPtr ]['type'] ) { |
|
2509 | - if ( false === isset( $this->tokens[ $stackPtr ]['bracket_closer'] ) ) { |
|
2508 | + if ( 'T_OPEN_SHORT_ARRAY' === $this->tokens[ $stackPtr ][ 'type' ] ) { |
|
2509 | + if ( false === isset( $this->tokens[ $stackPtr ][ 'bracket_closer' ] ) ) { |
|
2510 | 2510 | return false; |
2511 | 2511 | } |
2512 | 2512 | |
2513 | - if ( $next_non_empty === $this->tokens[ $stackPtr ]['bracket_closer'] ) { |
|
2513 | + if ( $next_non_empty === $this->tokens[ $stackPtr ][ 'bracket_closer' ] ) { |
|
2514 | 2514 | // No parameters. |
2515 | 2515 | return false; |
2516 | 2516 | } else { |
@@ -2520,15 +2520,15 @@ discard block |
||
2520 | 2520 | |
2521 | 2521 | // Deal with function calls & long arrays. |
2522 | 2522 | // Next non-empty token should be the open parenthesis. |
2523 | - if ( false === $next_non_empty && \T_OPEN_PARENTHESIS !== $this->tokens[ $next_non_empty ]['code'] ) { |
|
2523 | + if ( false === $next_non_empty && \T_OPEN_PARENTHESIS !== $this->tokens[ $next_non_empty ][ 'code' ] ) { |
|
2524 | 2524 | return false; |
2525 | 2525 | } |
2526 | 2526 | |
2527 | - if ( false === isset( $this->tokens[ $next_non_empty ]['parenthesis_closer'] ) ) { |
|
2527 | + if ( false === isset( $this->tokens[ $next_non_empty ][ 'parenthesis_closer' ] ) ) { |
|
2528 | 2528 | return false; |
2529 | 2529 | } |
2530 | 2530 | |
2531 | - $close_parenthesis = $this->tokens[ $next_non_empty ]['parenthesis_closer']; |
|
2531 | + $close_parenthesis = $this->tokens[ $next_non_empty ][ 'parenthesis_closer' ]; |
|
2532 | 2532 | $next_next_non_empty = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $next_non_empty + 1 ), ( $close_parenthesis + 1 ), true ); |
2533 | 2533 | |
2534 | 2534 | if ( $next_next_non_empty === $close_parenthesis ) { |
@@ -2599,67 +2599,67 @@ discard block |
||
2599 | 2599 | */ |
2600 | 2600 | |
2601 | 2601 | // Mark the beginning and end tokens. |
2602 | - if ( 'T_OPEN_SHORT_ARRAY' === $this->tokens[ $stackPtr ]['type'] ) { |
|
2602 | + if ( 'T_OPEN_SHORT_ARRAY' === $this->tokens[ $stackPtr ][ 'type' ] ) { |
|
2603 | 2603 | $opener = $stackPtr; |
2604 | - $closer = $this->tokens[ $stackPtr ]['bracket_closer']; |
|
2604 | + $closer = $this->tokens[ $stackPtr ][ 'bracket_closer' ]; |
|
2605 | 2605 | |
2606 | 2606 | $nestedParenthesisCount = 0; |
2607 | 2607 | } else { |
2608 | 2608 | $opener = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true ); |
2609 | - $closer = $this->tokens[ $opener ]['parenthesis_closer']; |
|
2609 | + $closer = $this->tokens[ $opener ][ 'parenthesis_closer' ]; |
|
2610 | 2610 | |
2611 | 2611 | $nestedParenthesisCount = 1; |
2612 | 2612 | } |
2613 | 2613 | |
2614 | 2614 | // Which nesting level is the one we are interested in ? |
2615 | - if ( isset( $this->tokens[ $opener ]['nested_parenthesis'] ) ) { |
|
2616 | - $nestedParenthesisCount += \count( $this->tokens[ $opener ]['nested_parenthesis'] ); |
|
2615 | + if ( isset( $this->tokens[ $opener ][ 'nested_parenthesis' ] ) ) { |
|
2616 | + $nestedParenthesisCount += \count( $this->tokens[ $opener ][ 'nested_parenthesis' ] ); |
|
2617 | 2617 | } |
2618 | 2618 | |
2619 | 2619 | $parameters = array(); |
2620 | 2620 | $next_comma = $opener; |
2621 | 2621 | $param_start = ( $opener + 1 ); |
2622 | 2622 | $cnt = 1; |
2623 | - while ( $next_comma = $this->phpcsFile->findNext( array( \T_COMMA, $this->tokens[ $closer ]['code'], \T_OPEN_SHORT_ARRAY, \T_CLOSURE ), ( $next_comma + 1 ), ( $closer + 1 ) ) ) { |
|
2623 | + while ( $next_comma = $this->phpcsFile->findNext( array( \T_COMMA, $this->tokens[ $closer ][ 'code' ], \T_OPEN_SHORT_ARRAY, \T_CLOSURE ), ( $next_comma + 1 ), ( $closer + 1 ) ) ) { |
|
2624 | 2624 | // Ignore anything within short array definition brackets. |
2625 | - if ( 'T_OPEN_SHORT_ARRAY' === $this->tokens[ $next_comma ]['type'] |
|
2626 | - && ( isset( $this->tokens[ $next_comma ]['bracket_opener'] ) |
|
2627 | - && $this->tokens[ $next_comma ]['bracket_opener'] === $next_comma ) |
|
2628 | - && isset( $this->tokens[ $next_comma ]['bracket_closer'] ) |
|
2625 | + if ( 'T_OPEN_SHORT_ARRAY' === $this->tokens[ $next_comma ][ 'type' ] |
|
2626 | + && ( isset( $this->tokens[ $next_comma ][ 'bracket_opener' ] ) |
|
2627 | + && $this->tokens[ $next_comma ][ 'bracket_opener' ] === $next_comma ) |
|
2628 | + && isset( $this->tokens[ $next_comma ][ 'bracket_closer' ] ) |
|
2629 | 2629 | ) { |
2630 | 2630 | // Skip forward to the end of the short array definition. |
2631 | - $next_comma = $this->tokens[ $next_comma ]['bracket_closer']; |
|
2631 | + $next_comma = $this->tokens[ $next_comma ][ 'bracket_closer' ]; |
|
2632 | 2632 | continue; |
2633 | 2633 | } |
2634 | 2634 | |
2635 | 2635 | // Skip past closures passed as function parameters. |
2636 | - if ( 'T_CLOSURE' === $this->tokens[ $next_comma ]['type'] |
|
2637 | - && ( isset( $this->tokens[ $next_comma ]['scope_condition'] ) |
|
2638 | - && $this->tokens[ $next_comma ]['scope_condition'] === $next_comma ) |
|
2639 | - && isset( $this->tokens[ $next_comma ]['scope_closer'] ) |
|
2636 | + if ( 'T_CLOSURE' === $this->tokens[ $next_comma ][ 'type' ] |
|
2637 | + && ( isset( $this->tokens[ $next_comma ][ 'scope_condition' ] ) |
|
2638 | + && $this->tokens[ $next_comma ][ 'scope_condition' ] === $next_comma ) |
|
2639 | + && isset( $this->tokens[ $next_comma ][ 'scope_closer' ] ) |
|
2640 | 2640 | ) { |
2641 | 2641 | // Skip forward to the end of the closure declaration. |
2642 | - $next_comma = $this->tokens[ $next_comma ]['scope_closer']; |
|
2642 | + $next_comma = $this->tokens[ $next_comma ][ 'scope_closer' ]; |
|
2643 | 2643 | continue; |
2644 | 2644 | } |
2645 | 2645 | |
2646 | 2646 | // Ignore comma's at a lower nesting level. |
2647 | - if ( \T_COMMA === $this->tokens[ $next_comma ]['code'] |
|
2648 | - && isset( $this->tokens[ $next_comma ]['nested_parenthesis'] ) |
|
2649 | - && \count( $this->tokens[ $next_comma ]['nested_parenthesis'] ) !== $nestedParenthesisCount |
|
2647 | + if ( \T_COMMA === $this->tokens[ $next_comma ][ 'code' ] |
|
2648 | + && isset( $this->tokens[ $next_comma ][ 'nested_parenthesis' ] ) |
|
2649 | + && \count( $this->tokens[ $next_comma ][ 'nested_parenthesis' ] ) !== $nestedParenthesisCount |
|
2650 | 2650 | ) { |
2651 | 2651 | continue; |
2652 | 2652 | } |
2653 | 2653 | |
2654 | 2654 | // Ignore closing parenthesis/bracket if not 'ours'. |
2655 | - if ( $this->tokens[ $next_comma ]['type'] === $this->tokens[ $closer ]['type'] && $next_comma !== $closer ) { |
|
2655 | + if ( $this->tokens[ $next_comma ][ 'type' ] === $this->tokens[ $closer ][ 'type' ] && $next_comma !== $closer ) { |
|
2656 | 2656 | continue; |
2657 | 2657 | } |
2658 | 2658 | |
2659 | 2659 | // Ok, we've reached the end of the parameter. |
2660 | - $parameters[ $cnt ]['start'] = $param_start; |
|
2661 | - $parameters[ $cnt ]['end'] = ( $next_comma - 1 ); |
|
2662 | - $parameters[ $cnt ]['raw'] = trim( $this->phpcsFile->getTokensAsString( $param_start, ( $next_comma - $param_start ) ) ); |
|
2660 | + $parameters[ $cnt ][ 'start' ] = $param_start; |
|
2661 | + $parameters[ $cnt ][ 'end' ] = ( $next_comma - 1 ); |
|
2662 | + $parameters[ $cnt ][ 'raw' ] = trim( $this->phpcsFile->getTokensAsString( $param_start, ( $next_comma - $param_start ) ) ); |
|
2663 | 2663 | |
2664 | 2664 | /* |
2665 | 2665 | * Check if there are more tokens before the closing parenthesis. |
@@ -2720,20 +2720,20 @@ discard block |
||
2720 | 2720 | /* |
2721 | 2721 | * Determine the array opener & closer. |
2722 | 2722 | */ |
2723 | - if ( \T_ARRAY === $this->tokens[ $stackPtr ]['code'] ) { |
|
2724 | - if ( isset( $this->tokens[ $stackPtr ]['parenthesis_opener'] ) ) { |
|
2725 | - $opener = $this->tokens[ $stackPtr ]['parenthesis_opener']; |
|
2723 | + if ( \T_ARRAY === $this->tokens[ $stackPtr ][ 'code' ] ) { |
|
2724 | + if ( isset( $this->tokens[ $stackPtr ][ 'parenthesis_opener' ] ) ) { |
|
2725 | + $opener = $this->tokens[ $stackPtr ][ 'parenthesis_opener' ]; |
|
2726 | 2726 | |
2727 | - if ( isset( $this->tokens[ $opener ]['parenthesis_closer'] ) ) { |
|
2728 | - $closer = $this->tokens[ $opener ]['parenthesis_closer']; |
|
2727 | + if ( isset( $this->tokens[ $opener ][ 'parenthesis_closer' ] ) ) { |
|
2728 | + $closer = $this->tokens[ $opener ][ 'parenthesis_closer' ]; |
|
2729 | 2729 | } |
2730 | 2730 | } |
2731 | 2731 | } else { |
2732 | 2732 | // Short array syntax. |
2733 | 2733 | $opener = $stackPtr; |
2734 | 2734 | |
2735 | - if ( isset( $this->tokens[ $stackPtr ]['bracket_closer'] ) ) { |
|
2736 | - $closer = $this->tokens[ $stackPtr ]['bracket_closer']; |
|
2735 | + if ( isset( $this->tokens[ $stackPtr ][ 'bracket_closer' ] ) ) { |
|
2736 | + $closer = $this->tokens[ $stackPtr ][ 'bracket_closer' ]; |
|
2737 | 2737 | } |
2738 | 2738 | } |
2739 | 2739 | |
@@ -2765,7 +2765,7 @@ discard block |
||
2765 | 2765 | } |
2766 | 2766 | |
2767 | 2767 | // Check for scoped namespace {}. |
2768 | - if ( ! empty( $this->tokens[ $stackPtr ]['conditions'] ) ) { |
|
2768 | + if ( ! empty( $this->tokens[ $stackPtr ][ 'conditions' ] ) ) { |
|
2769 | 2769 | $namespacePtr = $this->phpcsFile->getCondition( $stackPtr, \T_NAMESPACE ); |
2770 | 2770 | if ( false !== $namespacePtr ) { |
2771 | 2771 | $namespace = $this->get_declared_namespace_name( $namespacePtr ); |
@@ -2792,8 +2792,8 @@ discard block |
||
2792 | 2792 | $previousNSToken = $this->phpcsFile->findPrevious( \T_NAMESPACE, ( $previousNSToken - 1 ) ); |
2793 | 2793 | |
2794 | 2794 | // Stop if we encounter a scoped namespace declaration as we already know we're not in one. |
2795 | - if ( ! empty( $this->tokens[ $previousNSToken ]['scope_condition'] ) |
|
2796 | - && $this->tokens[ $previousNSToken ]['scope_condition'] === $previousNSToken |
|
2795 | + if ( ! empty( $this->tokens[ $previousNSToken ][ 'scope_condition' ] ) |
|
2796 | + && $this->tokens[ $previousNSToken ][ 'scope_condition' ] === $previousNSToken |
|
2797 | 2797 | ) { |
2798 | 2798 | break; |
2799 | 2799 | } |
@@ -2831,17 +2831,17 @@ discard block |
||
2831 | 2831 | return false; |
2832 | 2832 | } |
2833 | 2833 | |
2834 | - if ( \T_NAMESPACE !== $this->tokens[ $stackPtr ]['code'] ) { |
|
2834 | + if ( \T_NAMESPACE !== $this->tokens[ $stackPtr ][ 'code' ] ) { |
|
2835 | 2835 | return false; |
2836 | 2836 | } |
2837 | 2837 | |
2838 | 2838 | $nextToken = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true ); |
2839 | - if ( \T_NS_SEPARATOR === $this->tokens[ $nextToken ]['code'] ) { |
|
2839 | + if ( \T_NS_SEPARATOR === $this->tokens[ $nextToken ][ 'code' ] ) { |
|
2840 | 2840 | // Not a namespace declaration, but use of, i.e. `namespace\someFunction();`. |
2841 | 2841 | return false; |
2842 | 2842 | } |
2843 | 2843 | |
2844 | - if ( \T_OPEN_CURLY_BRACKET === $this->tokens[ $nextToken ]['code'] ) { |
|
2844 | + if ( \T_OPEN_CURLY_BRACKET === $this->tokens[ $nextToken ][ 'code' ] ) { |
|
2845 | 2845 | // Declaration for global namespace when using multiple namespaces in a file. |
2846 | 2846 | // I.e.: `namespace {}`. |
2847 | 2847 | return ''; |
@@ -2852,12 +2852,12 @@ discard block |
||
2852 | 2852 | \T_STRING => true, |
2853 | 2853 | \T_NS_SEPARATOR => true, |
2854 | 2854 | ); |
2855 | - $validTokens = $acceptedTokens + Tokens::$emptyTokens; |
|
2855 | + $validTokens = $acceptedTokens + Tokens::$emptyTokens; |
|
2856 | 2856 | |
2857 | 2857 | $namespaceName = ''; |
2858 | - while ( isset( $validTokens[ $this->tokens[ $nextToken ]['code'] ] ) ) { |
|
2859 | - if ( isset( $acceptedTokens[ $this->tokens[ $nextToken ]['code'] ] ) ) { |
|
2860 | - $namespaceName .= trim( $this->tokens[ $nextToken ]['content'] ); |
|
2858 | + while ( isset( $validTokens[ $this->tokens[ $nextToken ][ 'code' ] ] ) ) { |
|
2859 | + if ( isset( $acceptedTokens[ $this->tokens[ $nextToken ][ 'code' ] ] ) ) { |
|
2860 | + $namespaceName .= trim( $this->tokens[ $nextToken ][ 'content' ] ); |
|
2861 | 2861 | } |
2862 | 2862 | ++$nextToken; |
2863 | 2863 | } |
@@ -2875,7 +2875,7 @@ discard block |
||
2875 | 2875 | * @return bool |
2876 | 2876 | */ |
2877 | 2877 | public function is_class_constant( $stackPtr ) { |
2878 | - if ( ! isset( $this->tokens[ $stackPtr ] ) || \T_CONST !== $this->tokens[ $stackPtr ]['code'] ) { |
|
2878 | + if ( ! isset( $this->tokens[ $stackPtr ] ) || \T_CONST !== $this->tokens[ $stackPtr ][ 'code' ] ) { |
|
2879 | 2879 | return false; |
2880 | 2880 | } |
2881 | 2881 | |
@@ -2899,7 +2899,7 @@ discard block |
||
2899 | 2899 | * @return bool |
2900 | 2900 | */ |
2901 | 2901 | public function is_class_property( $stackPtr ) { |
2902 | - if ( ! isset( $this->tokens[ $stackPtr ] ) || \T_VARIABLE !== $this->tokens[ $stackPtr ]['code'] ) { |
|
2902 | + if ( ! isset( $this->tokens[ $stackPtr ] ) || \T_VARIABLE !== $this->tokens[ $stackPtr ][ 'code' ] ) { |
|
2903 | 2903 | return false; |
2904 | 2904 | } |
2905 | 2905 | |
@@ -2913,14 +2913,14 @@ discard block |
||
2913 | 2913 | $scopePtr = $this->valid_direct_scope( $stackPtr, $valid_scopes ); |
2914 | 2914 | if ( false !== $scopePtr ) { |
2915 | 2915 | // Make sure it's not a method parameter. |
2916 | - if ( empty( $this->tokens[ $stackPtr ]['nested_parenthesis'] ) ) { |
|
2916 | + if ( empty( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) ) { |
|
2917 | 2917 | return true; |
2918 | 2918 | } else { |
2919 | - $parenthesis = array_keys( $this->tokens[ $stackPtr ]['nested_parenthesis'] ); |
|
2919 | + $parenthesis = array_keys( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ); |
|
2920 | 2920 | $deepest_open = array_pop( $parenthesis ); |
2921 | 2921 | if ( $deepest_open < $scopePtr |
2922 | - || isset( $this->tokens[ $deepest_open ]['parenthesis_owner'] ) === false |
|
2923 | - || \T_FUNCTION !== $this->tokens[ $this->tokens[ $deepest_open ]['parenthesis_owner'] ]['code'] |
|
2922 | + || isset( $this->tokens[ $deepest_open ][ 'parenthesis_owner' ] ) === false |
|
2923 | + || \T_FUNCTION !== $this->tokens[ $this->tokens[ $deepest_open ][ 'parenthesis_owner' ] ][ 'code' ] |
|
2924 | 2924 | ) { |
2925 | 2925 | return true; |
2926 | 2926 | } |
@@ -2947,21 +2947,21 @@ discard block |
||
2947 | 2947 | * @return int|bool StackPtr to the scope if valid, false otherwise. |
2948 | 2948 | */ |
2949 | 2949 | protected function valid_direct_scope( $stackPtr, array $valid_scopes ) { |
2950 | - if ( empty( $this->tokens[ $stackPtr ]['conditions'] ) ) { |
|
2950 | + if ( empty( $this->tokens[ $stackPtr ][ 'conditions' ] ) ) { |
|
2951 | 2951 | return false; |
2952 | 2952 | } |
2953 | 2953 | |
2954 | 2954 | /* |
2955 | 2955 | * Check only the direct wrapping scope of the token. |
2956 | 2956 | */ |
2957 | - $conditions = array_keys( $this->tokens[ $stackPtr ]['conditions'] ); |
|
2957 | + $conditions = array_keys( $this->tokens[ $stackPtr ][ 'conditions' ] ); |
|
2958 | 2958 | $ptr = array_pop( $conditions ); |
2959 | 2959 | |
2960 | 2960 | if ( ! isset( $this->tokens[ $ptr ] ) ) { |
2961 | 2961 | return false; |
2962 | 2962 | } |
2963 | 2963 | |
2964 | - if ( isset( $valid_scopes[ $this->tokens[ $ptr ]['type'] ] ) ) { |
|
2964 | + if ( isset( $valid_scopes[ $this->tokens[ $ptr ][ 'type' ] ] ) ) { |
|
2965 | 2965 | return $ptr; |
2966 | 2966 | } |
2967 | 2967 | |
@@ -2991,8 +2991,8 @@ discard block |
||
2991 | 2991 | protected function is_wpdb_method_call( $stackPtr, $target_methods ) { |
2992 | 2992 | |
2993 | 2993 | // Check for wpdb. |
2994 | - if ( ( \T_VARIABLE === $this->tokens[ $stackPtr ]['code'] && '$wpdb' !== $this->tokens[ $stackPtr ]['content'] ) |
|
2995 | - || ( \T_STRING === $this->tokens[ $stackPtr ]['code'] && 'wpdb' !== $this->tokens[ $stackPtr ]['content'] ) |
|
2994 | + if ( ( \T_VARIABLE === $this->tokens[ $stackPtr ][ 'code' ] && '$wpdb' !== $this->tokens[ $stackPtr ][ 'content' ] ) |
|
2995 | + || ( \T_STRING === $this->tokens[ $stackPtr ][ 'code' ] && 'wpdb' !== $this->tokens[ $stackPtr ][ 'content' ] ) |
|
2996 | 2996 | ) { |
2997 | 2997 | return false; |
2998 | 2998 | } |
@@ -3015,7 +3015,7 @@ discard block |
||
3015 | 3015 | return false; |
3016 | 3016 | } |
3017 | 3017 | |
3018 | - if ( \T_STRING === $this->tokens[ $methodPtr ]['code'] && property_exists( $this, 'methodPtr' ) ) { |
|
3018 | + if ( \T_STRING === $this->tokens[ $methodPtr ][ 'code' ] && property_exists( $this, 'methodPtr' ) ) { |
|
3019 | 3019 | $this->methodPtr = $methodPtr; |
3020 | 3020 | } |
3021 | 3021 | |
@@ -3030,21 +3030,21 @@ discard block |
||
3030 | 3030 | $this->i = $opening_paren; |
3031 | 3031 | } |
3032 | 3032 | |
3033 | - if ( \T_OPEN_PARENTHESIS !== $this->tokens[ $opening_paren ]['code'] |
|
3034 | - || ! isset( $this->tokens[ $opening_paren ]['parenthesis_closer'] ) |
|
3033 | + if ( \T_OPEN_PARENTHESIS !== $this->tokens[ $opening_paren ][ 'code' ] |
|
3034 | + || ! isset( $this->tokens[ $opening_paren ][ 'parenthesis_closer' ] ) |
|
3035 | 3035 | ) { |
3036 | 3036 | return false; |
3037 | 3037 | } |
3038 | 3038 | |
3039 | 3039 | // Check that this is one of the methods that we are interested in. |
3040 | - if ( ! isset( $target_methods[ $this->tokens[ $methodPtr ]['content'] ] ) ) { |
|
3040 | + if ( ! isset( $target_methods[ $this->tokens[ $methodPtr ][ 'content' ] ] ) ) { |
|
3041 | 3041 | return false; |
3042 | 3042 | } |
3043 | 3043 | |
3044 | 3044 | // Find the end of the first parameter. |
3045 | 3045 | $end = $this->phpcsFile->findEndOfStatement( $opening_paren + 1 ); |
3046 | 3046 | |
3047 | - if ( \T_COMMA !== $this->tokens[ $end ]['code'] ) { |
|
3047 | + if ( \T_COMMA !== $this->tokens[ $end ][ 'code' ] ) { |
|
3048 | 3048 | ++$end; |
3049 | 3049 | } |
3050 | 3050 | |
@@ -3071,14 +3071,14 @@ discard block |
||
3071 | 3071 | } |
3072 | 3072 | |
3073 | 3073 | // Is this one of the tokens this function handles ? |
3074 | - if ( \T_STRING !== $this->tokens[ $stackPtr ]['code'] ) { |
|
3074 | + if ( \T_STRING !== $this->tokens[ $stackPtr ][ 'code' ] ) { |
|
3075 | 3075 | return false; |
3076 | 3076 | } |
3077 | 3077 | |
3078 | 3078 | $next = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); |
3079 | 3079 | if ( false !== $next |
3080 | - && ( \T_OPEN_PARENTHESIS === $this->tokens[ $next ]['code'] |
|
3081 | - || \T_DOUBLE_COLON === $this->tokens[ $next ]['code'] ) |
|
3080 | + && ( \T_OPEN_PARENTHESIS === $this->tokens[ $next ][ 'code' ] |
|
3081 | + || \T_DOUBLE_COLON === $this->tokens[ $next ][ 'code' ] ) |
|
3082 | 3082 | ) { |
3083 | 3083 | // Function call or declaration. |
3084 | 3084 | return false; |
@@ -3108,7 +3108,7 @@ discard block |
||
3108 | 3108 | |
3109 | 3109 | $prev = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true ); |
3110 | 3110 | if ( false !== $prev |
3111 | - && isset( $tokens_to_ignore[ $this->tokens[ $prev ]['type'] ] ) |
|
3111 | + && isset( $tokens_to_ignore[ $this->tokens[ $prev ][ 'type' ] ] ) |
|
3112 | 3112 | ) { |
3113 | 3113 | // Not the use of a constant. |
3114 | 3114 | return false; |
@@ -3120,7 +3120,7 @@ discard block |
||
3120 | 3120 | } |
3121 | 3121 | |
3122 | 3122 | if ( false !== $prev |
3123 | - && \T_CONST === $this->tokens[ $prev ]['code'] |
|
3123 | + && \T_CONST === $this->tokens[ $prev ][ 'code' ] |
|
3124 | 3124 | && $this->is_class_constant( $prev ) |
3125 | 3125 | ) { |
3126 | 3126 | // Class constant declaration of the same name. |
@@ -3131,17 +3131,17 @@ discard block |
||
3131 | 3131 | * Deal with a number of variations of use statements. |
3132 | 3132 | */ |
3133 | 3133 | for ( $i = $stackPtr; $i > 0; $i-- ) { |
3134 | - if ( $this->tokens[ $i ]['line'] !== $this->tokens[ $stackPtr ]['line'] ) { |
|
3134 | + if ( $this->tokens[ $i ][ 'line' ] !== $this->tokens[ $stackPtr ][ 'line' ] ) { |
|
3135 | 3135 | break; |
3136 | 3136 | } |
3137 | 3137 | } |
3138 | 3138 | |
3139 | 3139 | $firstOnLine = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $i + 1 ), null, true ); |
3140 | - if ( false !== $firstOnLine && \T_USE === $this->tokens[ $firstOnLine ]['code'] ) { |
|
3140 | + if ( false !== $firstOnLine && \T_USE === $this->tokens[ $firstOnLine ][ 'code' ] ) { |
|
3141 | 3141 | $nextOnLine = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $firstOnLine + 1 ), null, true ); |
3142 | 3142 | if ( false !== $nextOnLine ) { |
3143 | - if ( \T_STRING === $this->tokens[ $nextOnLine ]['code'] |
|
3144 | - && 'const' === $this->tokens[ $nextOnLine ]['content'] |
|
3143 | + if ( \T_STRING === $this->tokens[ $nextOnLine ][ 'code' ] |
|
3144 | + && 'const' === $this->tokens[ $nextOnLine ][ 'content' ] |
|
3145 | 3145 | ) { |
3146 | 3146 | $hasNsSep = $this->phpcsFile->findNext( \T_NS_SEPARATOR, ( $nextOnLine + 1 ), $stackPtr ); |
3147 | 3147 | if ( false !== $hasNsSep ) { |
@@ -3169,18 +3169,18 @@ discard block |
||
3169 | 3169 | * @return bool True if it is. False otherwise. |
3170 | 3170 | */ |
3171 | 3171 | protected function is_foreach_as( $stackPtr ) { |
3172 | - if ( ! isset( $this->tokens[ $stackPtr ]['nested_parenthesis'] ) ) { |
|
3172 | + if ( ! isset( $this->tokens[ $stackPtr ][ 'nested_parenthesis' ] ) ) { |
|
3173 | 3173 | return false; |
3174 | 3174 | } |
3175 | 3175 | |
3176 | - $nested_parenthesis = $this->tokens[ $stackPtr ]['nested_parenthesis']; |
|
3176 | + $nested_parenthesis = $this->tokens[ $stackPtr ][ 'nested_parenthesis' ]; |
|
3177 | 3177 | $close_parenthesis = end( $nested_parenthesis ); |
3178 | 3178 | $open_parenthesis = key( $nested_parenthesis ); |
3179 | - if ( ! isset( $this->tokens[ $close_parenthesis ]['parenthesis_owner'] ) ) { |
|
3179 | + if ( ! isset( $this->tokens[ $close_parenthesis ][ 'parenthesis_owner' ] ) ) { |
|
3180 | 3180 | return false; |
3181 | 3181 | } |
3182 | 3182 | |
3183 | - if ( \T_FOREACH !== $this->tokens[ $this->tokens[ $close_parenthesis ]['parenthesis_owner'] ]['code'] ) { |
|
3183 | + if ( \T_FOREACH !== $this->tokens[ $this->tokens[ $close_parenthesis ][ 'parenthesis_owner' ] ][ 'code' ] ) { |
|
3184 | 3184 | return false; |
3185 | 3185 | } |
3186 | 3186 |
@@ -951,7 +951,7 @@ discard block |
||
951 | 951 | * @param bool $is_error Optional. Whether to report the message as an 'error' or 'warning'. |
952 | 952 | * Defaults to true (error). |
953 | 953 | * @param string $code Optional error code for the message. Defaults to 'Found'. |
954 | - * @param array $data Optional input for the data replacements. |
|
954 | + * @param string[] $data Optional input for the data replacements. |
|
955 | 955 | * @param int $severity Optional. Severity level. Defaults to 0 which will translate to |
956 | 956 | * the PHPCS default severity level. |
957 | 957 | * @return bool |
@@ -970,7 +970,7 @@ discard block |
||
970 | 970 | * @param bool $is_error Optional. Whether to report the message as an 'error' or 'warning'. |
971 | 971 | * Defaults to true (error). |
972 | 972 | * @param string $code Optional error code for the message. Defaults to 'Found'. |
973 | - * @param array $data Optional input for the data replacements. |
|
973 | + * @param string[] $data Optional input for the data replacements. |
|
974 | 974 | * @param int $severity Optional. Severity level. Defaults to 0 which will translate to |
975 | 975 | * the PHPCS default severity level. |
976 | 976 | * @return bool |
@@ -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 |