@@ -141,9 +141,9 @@ discard block |
||
141 | 141 | |
142 | 142 | $token = $this->tokens[ $stackPtr ]; |
143 | 143 | |
144 | - if ( \T_CLOSE_SQUARE_BRACKET === $token['code'] ) { |
|
144 | + if ( \T_CLOSE_SQUARE_BRACKET === $token[ 'code' ] ) { |
|
145 | 145 | $equal = $this->phpcsFile->findNext( \T_WHITESPACE, ( $stackPtr + 1 ), null, true ); |
146 | - if ( \T_EQUAL !== $this->tokens[ $equal ]['code'] ) { |
|
146 | + if ( \T_EQUAL !== $this->tokens[ $equal ][ 'code' ] ) { |
|
147 | 147 | return; // This is not an assignment! |
148 | 148 | } |
149 | 149 | } |
@@ -156,28 +156,28 @@ discard block |
||
156 | 156 | * $foo = array( 'bar' => 'taz' ); |
157 | 157 | * $foo['bar'] = $taz; |
158 | 158 | */ |
159 | - if ( \in_array( $token['code'], array( \T_CLOSE_SQUARE_BRACKET, \T_DOUBLE_ARROW ), true ) ) { |
|
159 | + if ( \in_array( $token[ 'code' ], array( \T_CLOSE_SQUARE_BRACKET, \T_DOUBLE_ARROW ), true ) ) { |
|
160 | 160 | $operator = $stackPtr; // T_DOUBLE_ARROW. |
161 | - if ( \T_CLOSE_SQUARE_BRACKET === $token['code'] ) { |
|
161 | + if ( \T_CLOSE_SQUARE_BRACKET === $token[ 'code' ] ) { |
|
162 | 162 | $operator = $this->phpcsFile->findNext( \T_EQUAL, ( $stackPtr + 1 ) ); |
163 | 163 | } |
164 | 164 | |
165 | 165 | $keyIdx = $this->phpcsFile->findPrevious( array( \T_WHITESPACE, \T_CLOSE_SQUARE_BRACKET ), ( $operator - 1 ), null, true ); |
166 | - if ( ! is_numeric( $this->tokens[ $keyIdx ]['content'] ) ) { |
|
167 | - $key = $this->strip_quotes( $this->tokens[ $keyIdx ]['content'] ); |
|
166 | + if ( ! is_numeric( $this->tokens[ $keyIdx ][ 'content' ] ) ) { |
|
167 | + $key = $this->strip_quotes( $this->tokens[ $keyIdx ][ 'content' ] ); |
|
168 | 168 | $valStart = $this->phpcsFile->findNext( array( \T_WHITESPACE ), ( $operator + 1 ), null, true ); |
169 | 169 | $valEnd = $this->phpcsFile->findNext( array( \T_COMMA, \T_SEMICOLON ), ( $valStart + 1 ), null, false, null, true ); |
170 | 170 | $val = $this->phpcsFile->getTokensAsString( $valStart, ( $valEnd - $valStart ) ); |
171 | 171 | $val = $this->strip_quotes( $val ); |
172 | - $inst[ $key ][] = array( $val, $token['line'] ); |
|
172 | + $inst[ $key ][ ] = array( $val, $token[ 'line' ] ); |
|
173 | 173 | } |
174 | - } elseif ( \in_array( $token['code'], array( \T_CONSTANT_ENCAPSED_STRING, \T_DOUBLE_QUOTED_STRING ), true ) ) { |
|
174 | + } elseif ( \in_array( $token[ 'code' ], array( \T_CONSTANT_ENCAPSED_STRING, \T_DOUBLE_QUOTED_STRING ), true ) ) { |
|
175 | 175 | // $foo = 'bar=taz&other=thing'; |
176 | - if ( preg_match_all( '#(?:^|&)([a-z_]+)=([^&]*)#i', $this->strip_quotes( $token['content'] ), $matches ) <= 0 ) { |
|
176 | + if ( preg_match_all( '#(?:^|&)([a-z_]+)=([^&]*)#i', $this->strip_quotes( $token[ 'content' ] ), $matches ) <= 0 ) { |
|
177 | 177 | return; // No assignments here, nothing to check. |
178 | 178 | } |
179 | - foreach ( $matches[1] as $i => $_k ) { |
|
180 | - $inst[ $_k ][] = array( $matches[2][ $i ], $token['line'] ); |
|
179 | + foreach ( $matches[ 1 ] as $i => $_k ) { |
|
180 | + $inst[ $_k ][ ] = array( $matches[ 2 ][ $i ], $token[ 'line' ] ); |
|
181 | 181 | } |
182 | 182 | } |
183 | 183 | |
@@ -191,13 +191,13 @@ discard block |
||
191 | 191 | continue; |
192 | 192 | } |
193 | 193 | |
194 | - $callback = ( isset( $group['callback'] ) && is_callable( $group['callback'] ) ) ? $group['callback'] : array( $this, 'callback' ); |
|
194 | + $callback = ( isset( $group[ 'callback' ] ) && is_callable( $group[ 'callback' ] ) ) ? $group[ 'callback' ] : array( $this, 'callback' ); |
|
195 | 195 | |
196 | 196 | foreach ( $inst as $key => $assignments ) { |
197 | 197 | foreach ( $assignments as $occurance ) { |
198 | 198 | list( $val, $line ) = $occurance; |
199 | 199 | |
200 | - if ( ! \in_array( $key, $group['keys'], true ) ) { |
|
200 | + if ( ! \in_array( $key, $group[ 'keys' ], true ) ) { |
|
201 | 201 | continue; |
202 | 202 | } |
203 | 203 | |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | if ( ! isset( $output ) || false === $output ) { |
207 | 207 | continue; |
208 | 208 | } elseif ( true === $output ) { |
209 | - $message = $group['message']; |
|
209 | + $message = $group[ 'message' ]; |
|
210 | 210 | } else { |
211 | 211 | $message = $output; |
212 | 212 | } |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | $this->addMessage( |
215 | 215 | $message, |
216 | 216 | $stackPtr, |
217 | - ( 'error' === $group['type'] ), |
|
217 | + ( 'error' === $group[ 'type' ] ), |
|
218 | 218 | $this->string_to_errorcode( $groupName . '_' . $key ), |
219 | 219 | array( $key, $val ) |
220 | 220 | ); |
@@ -109,39 +109,39 @@ discard block |
||
109 | 109 | { |
110 | 110 | static $arrTestVersions = array(); |
111 | 111 | |
112 | - $default = array(null, null); |
|
113 | - $testVersion = trim(PHPCSHelper::getConfigData('testVersion')); |
|
112 | + $default = array( null, null ); |
|
113 | + $testVersion = trim( PHPCSHelper::getConfigData( 'testVersion' ) ); |
|
114 | 114 | |
115 | - if (empty($testVersion) === false && isset($arrTestVersions[$testVersion]) === false) { |
|
115 | + if ( empty( $testVersion ) === false && isset( $arrTestVersions[ $testVersion ] ) === false ) { |
|
116 | 116 | |
117 | - $arrTestVersions[$testVersion] = $default; |
|
117 | + $arrTestVersions[ $testVersion ] = $default; |
|
118 | 118 | |
119 | - if (preg_match('`^\d+\.\d+$`', $testVersion)) { |
|
120 | - $arrTestVersions[$testVersion] = array($testVersion, $testVersion); |
|
121 | - return $arrTestVersions[$testVersion]; |
|
119 | + if ( preg_match( '`^\d+\.\d+$`', $testVersion ) ) { |
|
120 | + $arrTestVersions[ $testVersion ] = array( $testVersion, $testVersion ); |
|
121 | + return $arrTestVersions[ $testVersion ]; |
|
122 | 122 | } |
123 | 123 | |
124 | - if (preg_match('`^(\d+\.\d+)?\s*-\s*(\d+\.\d+)?$`', $testVersion, $matches)) { |
|
125 | - if (empty($matches[1]) === false || empty($matches[2]) === false) { |
|
124 | + if ( preg_match( '`^(\d+\.\d+)?\s*-\s*(\d+\.\d+)?$`', $testVersion, $matches ) ) { |
|
125 | + if ( empty( $matches[ 1 ] ) === false || empty( $matches[ 2 ] ) === false ) { |
|
126 | 126 | // If no lower-limit is set, we set the min version to 4.0. |
127 | 127 | // Whilst development focuses on PHP 5 and above, we also accept |
128 | 128 | // sniffs for PHP 4, so we include that as the minimum. |
129 | 129 | // (It makes no sense to support PHP 3 as this was effectively a |
130 | 130 | // different language). |
131 | - $min = empty($matches[1]) ? '4.0' : $matches[1]; |
|
131 | + $min = empty( $matches[ 1 ] ) ? '4.0' : $matches[ 1 ]; |
|
132 | 132 | |
133 | 133 | // If no upper-limit is set, we set the max version to 99.9. |
134 | - $max = empty($matches[2]) ? '99.9' : $matches[2]; |
|
134 | + $max = empty( $matches[ 2 ] ) ? '99.9' : $matches[ 2 ]; |
|
135 | 135 | |
136 | - if (version_compare($min, $max, '>')) { |
|
136 | + if ( version_compare( $min, $max, '>' ) ) { |
|
137 | 137 | trigger_error( |
138 | 138 | "Invalid range in testVersion setting: '" . $testVersion . "'", |
139 | 139 | \E_USER_WARNING |
140 | 140 | ); |
141 | 141 | return $default; |
142 | 142 | } else { |
143 | - $arrTestVersions[$testVersion] = array($min, $max); |
|
144 | - return $arrTestVersions[$testVersion]; |
|
143 | + $arrTestVersions[ $testVersion ] = array( $min, $max ); |
|
144 | + return $arrTestVersions[ $testVersion ]; |
|
145 | 145 | } |
146 | 146 | } |
147 | 147 | } |
@@ -153,8 +153,8 @@ discard block |
||
153 | 153 | return $default; |
154 | 154 | } |
155 | 155 | |
156 | - if (isset($arrTestVersions[$testVersion])) { |
|
157 | - return $arrTestVersions[$testVersion]; |
|
156 | + if ( isset( $arrTestVersions[ $testVersion ] ) ) { |
|
157 | + return $arrTestVersions[ $testVersion ]; |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | return $default; |
@@ -173,13 +173,13 @@ discard block |
||
173 | 173 | * is equal to or higher than the highest supported PHP version |
174 | 174 | * in testVersion. False otherwise. |
175 | 175 | */ |
176 | - public function supportsAbove($phpVersion) |
|
176 | + public function supportsAbove( $phpVersion ) |
|
177 | 177 | { |
178 | 178 | $testVersion = $this->getTestVersion(); |
179 | - $testVersion = $testVersion[1]; |
|
179 | + $testVersion = $testVersion[ 1 ]; |
|
180 | 180 | |
181 | - if (\is_null($testVersion) |
|
182 | - || version_compare($testVersion, $phpVersion) >= 0 |
|
181 | + if ( \is_null( $testVersion ) |
|
182 | + || version_compare( $testVersion, $phpVersion ) >= 0 |
|
183 | 183 | ) { |
184 | 184 | return true; |
185 | 185 | } else { |
@@ -200,13 +200,13 @@ discard block |
||
200 | 200 | * supported PHP version in testVersion. |
201 | 201 | * False otherwise or if no testVersion is provided. |
202 | 202 | */ |
203 | - public function supportsBelow($phpVersion) |
|
203 | + public function supportsBelow( $phpVersion ) |
|
204 | 204 | { |
205 | 205 | $testVersion = $this->getTestVersion(); |
206 | - $testVersion = $testVersion[0]; |
|
206 | + $testVersion = $testVersion[ 0 ]; |
|
207 | 207 | |
208 | - if (\is_null($testVersion) === false |
|
209 | - && version_compare($testVersion, $phpVersion) <= 0 |
|
208 | + if ( \is_null( $testVersion ) === false |
|
209 | + && version_compare( $testVersion, $phpVersion ) <= 0 |
|
210 | 210 | ) { |
211 | 211 | return true; |
212 | 212 | } else { |
@@ -231,12 +231,12 @@ discard block |
||
231 | 231 | * |
232 | 232 | * @return void |
233 | 233 | */ |
234 | - public function addMessage(File $phpcsFile, $message, $stackPtr, $isError, $code = 'Found', $data = array()) |
|
234 | + public function addMessage( File $phpcsFile, $message, $stackPtr, $isError, $code = 'Found', $data = array() ) |
|
235 | 235 | { |
236 | - if ($isError === true) { |
|
237 | - $phpcsFile->addError($message, $stackPtr, $code, $data); |
|
236 | + if ( $isError === true ) { |
|
237 | + $phpcsFile->addError( $message, $stackPtr, $code, $data ); |
|
238 | 238 | } else { |
239 | - $phpcsFile->addWarning($message, $stackPtr, $code, $data); |
|
239 | + $phpcsFile->addWarning( $message, $stackPtr, $code, $data ); |
|
240 | 240 | } |
241 | 241 | } |
242 | 242 | |
@@ -250,9 +250,9 @@ discard block |
||
250 | 250 | * |
251 | 251 | * @return string |
252 | 252 | */ |
253 | - public function stringToErrorCode($baseString) |
|
253 | + public function stringToErrorCode( $baseString ) |
|
254 | 254 | { |
255 | - return preg_replace('`[^a-z0-9_]`i', '_', strtolower($baseString)); |
|
255 | + return preg_replace( '`[^a-z0-9_]`i', '_', strtolower( $baseString ) ); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | |
@@ -265,9 +265,9 @@ discard block |
||
265 | 265 | * |
266 | 266 | * @return string String without quotes around it. |
267 | 267 | */ |
268 | - public function stripQuotes($string) |
|
268 | + public function stripQuotes( $string ) |
|
269 | 269 | { |
270 | - return preg_replace('`^([\'"])(.*)\1$`Ds', '$2', $string); |
|
270 | + return preg_replace( '`^([\'"])(.*)\1$`Ds', '$2', $string ); |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | |
@@ -280,13 +280,13 @@ discard block |
||
280 | 280 | * |
281 | 281 | * @return string String without variables in it. |
282 | 282 | */ |
283 | - public function stripVariables($string) |
|
283 | + public function stripVariables( $string ) |
|
284 | 284 | { |
285 | - if (strpos($string, '$') === false) { |
|
285 | + if ( strpos( $string, '$' ) === false ) { |
|
286 | 286 | return $string; |
287 | 287 | } |
288 | 288 | |
289 | - return preg_replace(self::REGEX_COMPLEX_VARS, '', $string); |
|
289 | + return preg_replace( self::REGEX_COMPLEX_VARS, '', $string ); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | |
@@ -297,9 +297,9 @@ discard block |
||
297 | 297 | * |
298 | 298 | * @return array Same array, but with all lowercase top level keys. |
299 | 299 | */ |
300 | - public function arrayKeysToLowercase($array) |
|
300 | + public function arrayKeysToLowercase( $array ) |
|
301 | 301 | { |
302 | - return array_change_key_case($array, \CASE_LOWER); |
|
302 | + return array_change_key_case( $array, \CASE_LOWER ); |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | |
@@ -320,29 +320,29 @@ discard block |
||
320 | 320 | * |
321 | 321 | * @return bool |
322 | 322 | */ |
323 | - public function doesFunctionCallHaveParameters(File $phpcsFile, $stackPtr) |
|
323 | + public function doesFunctionCallHaveParameters( File $phpcsFile, $stackPtr ) |
|
324 | 324 | { |
325 | 325 | $tokens = $phpcsFile->getTokens(); |
326 | 326 | |
327 | 327 | // Check for the existence of the token. |
328 | - if (isset($tokens[$stackPtr]) === false) { |
|
328 | + if ( isset( $tokens[ $stackPtr ] ) === false ) { |
|
329 | 329 | return false; |
330 | 330 | } |
331 | 331 | |
332 | 332 | // Is this one of the tokens this function handles ? |
333 | - if (\in_array($tokens[$stackPtr]['code'], array(\T_STRING, \T_ARRAY, \T_OPEN_SHORT_ARRAY, \T_VARIABLE), true) === false) { |
|
333 | + if ( \in_array( $tokens[ $stackPtr ][ 'code' ], array( \T_STRING, \T_ARRAY, \T_OPEN_SHORT_ARRAY, \T_VARIABLE ), true ) === false ) { |
|
334 | 334 | return false; |
335 | 335 | } |
336 | 336 | |
337 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true); |
|
337 | + $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true ); |
|
338 | 338 | |
339 | 339 | // Deal with short array syntax. |
340 | - if ($tokens[$stackPtr]['code'] === \T_OPEN_SHORT_ARRAY) { |
|
341 | - if (isset($tokens[$stackPtr]['bracket_closer']) === false) { |
|
340 | + if ( $tokens[ $stackPtr ][ 'code' ] === \T_OPEN_SHORT_ARRAY ) { |
|
341 | + if ( isset( $tokens[ $stackPtr ][ 'bracket_closer' ] ) === false ) { |
|
342 | 342 | return false; |
343 | 343 | } |
344 | 344 | |
345 | - if ($nextNonEmpty === $tokens[$stackPtr]['bracket_closer']) { |
|
345 | + if ( $nextNonEmpty === $tokens[ $stackPtr ][ 'bracket_closer' ] ) { |
|
346 | 346 | // No parameters. |
347 | 347 | return false; |
348 | 348 | } else { |
@@ -352,18 +352,18 @@ discard block |
||
352 | 352 | |
353 | 353 | // Deal with function calls & long arrays. |
354 | 354 | // Next non-empty token should be the open parenthesis. |
355 | - if ($nextNonEmpty === false && $tokens[$nextNonEmpty]['code'] !== \T_OPEN_PARENTHESIS) { |
|
355 | + if ( $nextNonEmpty === false && $tokens[ $nextNonEmpty ][ 'code' ] !== \T_OPEN_PARENTHESIS ) { |
|
356 | 356 | return false; |
357 | 357 | } |
358 | 358 | |
359 | - if (isset($tokens[$nextNonEmpty]['parenthesis_closer']) === false) { |
|
359 | + if ( isset( $tokens[ $nextNonEmpty ][ 'parenthesis_closer' ] ) === false ) { |
|
360 | 360 | return false; |
361 | 361 | } |
362 | 362 | |
363 | - $closeParenthesis = $tokens[$nextNonEmpty]['parenthesis_closer']; |
|
364 | - $nextNextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, $nextNonEmpty + 1, $closeParenthesis + 1, true); |
|
363 | + $closeParenthesis = $tokens[ $nextNonEmpty ][ 'parenthesis_closer' ]; |
|
364 | + $nextNextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, $nextNonEmpty + 1, $closeParenthesis + 1, true ); |
|
365 | 365 | |
366 | - if ($nextNextNonEmpty === $closeParenthesis) { |
|
366 | + if ( $nextNextNonEmpty === $closeParenthesis ) { |
|
367 | 367 | // No parameters. |
368 | 368 | return false; |
369 | 369 | } |
@@ -390,13 +390,13 @@ discard block |
||
390 | 390 | * |
391 | 391 | * @return int |
392 | 392 | */ |
393 | - public function getFunctionCallParameterCount(File $phpcsFile, $stackPtr) |
|
393 | + public function getFunctionCallParameterCount( File $phpcsFile, $stackPtr ) |
|
394 | 394 | { |
395 | - if ($this->doesFunctionCallHaveParameters($phpcsFile, $stackPtr) === false) { |
|
395 | + if ( $this->doesFunctionCallHaveParameters( $phpcsFile, $stackPtr ) === false ) { |
|
396 | 396 | return 0; |
397 | 397 | } |
398 | 398 | |
399 | - return \count($this->getFunctionCallParameters($phpcsFile, $stackPtr)); |
|
399 | + return \count( $this->getFunctionCallParameters( $phpcsFile, $stackPtr ) ); |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | |
@@ -418,9 +418,9 @@ discard block |
||
418 | 418 | * |
419 | 419 | * @return array |
420 | 420 | */ |
421 | - public function getFunctionCallParameters(File $phpcsFile, $stackPtr) |
|
421 | + public function getFunctionCallParameters( File $phpcsFile, $stackPtr ) |
|
422 | 422 | { |
423 | - if ($this->doesFunctionCallHaveParameters($phpcsFile, $stackPtr) === false) { |
|
423 | + if ( $this->doesFunctionCallHaveParameters( $phpcsFile, $stackPtr ) === false ) { |
|
424 | 424 | return array(); |
425 | 425 | } |
426 | 426 | |
@@ -429,74 +429,74 @@ discard block |
||
429 | 429 | $tokens = $phpcsFile->getTokens(); |
430 | 430 | |
431 | 431 | // Mark the beginning and end tokens. |
432 | - if ($tokens[$stackPtr]['code'] === \T_OPEN_SHORT_ARRAY) { |
|
432 | + if ( $tokens[ $stackPtr ][ 'code' ] === \T_OPEN_SHORT_ARRAY ) { |
|
433 | 433 | $opener = $stackPtr; |
434 | - $closer = $tokens[$stackPtr]['bracket_closer']; |
|
434 | + $closer = $tokens[ $stackPtr ][ 'bracket_closer' ]; |
|
435 | 435 | |
436 | 436 | $nestedParenthesisCount = 0; |
437 | 437 | |
438 | 438 | } else { |
439 | - $opener = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true); |
|
440 | - $closer = $tokens[$opener]['parenthesis_closer']; |
|
439 | + $opener = $phpcsFile->findNext( Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true ); |
|
440 | + $closer = $tokens[ $opener ][ 'parenthesis_closer' ]; |
|
441 | 441 | |
442 | 442 | $nestedParenthesisCount = 1; |
443 | 443 | } |
444 | 444 | |
445 | 445 | // Which nesting level is the one we are interested in ? |
446 | - if (isset($tokens[$opener]['nested_parenthesis'])) { |
|
447 | - $nestedParenthesisCount += \count($tokens[$opener]['nested_parenthesis']); |
|
446 | + if ( isset( $tokens[ $opener ][ 'nested_parenthesis' ] ) ) { |
|
447 | + $nestedParenthesisCount += \count( $tokens[ $opener ][ 'nested_parenthesis' ] ); |
|
448 | 448 | } |
449 | 449 | |
450 | 450 | $parameters = array(); |
451 | 451 | $nextComma = $opener; |
452 | 452 | $paramStart = $opener + 1; |
453 | 453 | $cnt = 1; |
454 | - while (($nextComma = $phpcsFile->findNext(array(\T_COMMA, $tokens[$closer]['code'], \T_OPEN_SHORT_ARRAY, \T_CLOSURE), $nextComma + 1, $closer + 1)) !== false) { |
|
454 | + while ( ( $nextComma = $phpcsFile->findNext( array( \T_COMMA, $tokens[ $closer ][ 'code' ], \T_OPEN_SHORT_ARRAY, \T_CLOSURE ), $nextComma + 1, $closer + 1 ) ) !== false ) { |
|
455 | 455 | // Ignore anything within short array definition brackets. |
456 | - if ($tokens[$nextComma]['type'] === 'T_OPEN_SHORT_ARRAY' |
|
457 | - && (isset($tokens[$nextComma]['bracket_opener']) |
|
458 | - && $tokens[$nextComma]['bracket_opener'] === $nextComma) |
|
459 | - && isset($tokens[$nextComma]['bracket_closer']) |
|
456 | + if ( $tokens[ $nextComma ][ 'type' ] === 'T_OPEN_SHORT_ARRAY' |
|
457 | + && ( isset( $tokens[ $nextComma ][ 'bracket_opener' ] ) |
|
458 | + && $tokens[ $nextComma ][ 'bracket_opener' ] === $nextComma ) |
|
459 | + && isset( $tokens[ $nextComma ][ 'bracket_closer' ] ) |
|
460 | 460 | ) { |
461 | 461 | // Skip forward to the end of the short array definition. |
462 | - $nextComma = $tokens[$nextComma]['bracket_closer']; |
|
462 | + $nextComma = $tokens[ $nextComma ][ 'bracket_closer' ]; |
|
463 | 463 | continue; |
464 | 464 | } |
465 | 465 | |
466 | 466 | // Skip past closures passed as function parameters. |
467 | - if ($tokens[$nextComma]['type'] === 'T_CLOSURE' |
|
468 | - && (isset($tokens[$nextComma]['scope_condition']) |
|
469 | - && $tokens[$nextComma]['scope_condition'] === $nextComma) |
|
470 | - && isset($tokens[$nextComma]['scope_closer']) |
|
467 | + if ( $tokens[ $nextComma ][ 'type' ] === 'T_CLOSURE' |
|
468 | + && ( isset( $tokens[ $nextComma ][ 'scope_condition' ] ) |
|
469 | + && $tokens[ $nextComma ][ 'scope_condition' ] === $nextComma ) |
|
470 | + && isset( $tokens[ $nextComma ][ 'scope_closer' ] ) |
|
471 | 471 | ) { |
472 | 472 | // Skip forward to the end of the closure declaration. |
473 | - $nextComma = $tokens[$nextComma]['scope_closer']; |
|
473 | + $nextComma = $tokens[ $nextComma ][ 'scope_closer' ]; |
|
474 | 474 | continue; |
475 | 475 | } |
476 | 476 | |
477 | 477 | // Ignore comma's at a lower nesting level. |
478 | - if ($tokens[$nextComma]['type'] === 'T_COMMA' |
|
479 | - && isset($tokens[$nextComma]['nested_parenthesis']) |
|
480 | - && \count($tokens[$nextComma]['nested_parenthesis']) !== $nestedParenthesisCount |
|
478 | + if ( $tokens[ $nextComma ][ 'type' ] === 'T_COMMA' |
|
479 | + && isset( $tokens[ $nextComma ][ 'nested_parenthesis' ] ) |
|
480 | + && \count( $tokens[ $nextComma ][ 'nested_parenthesis' ] ) !== $nestedParenthesisCount |
|
481 | 481 | ) { |
482 | 482 | continue; |
483 | 483 | } |
484 | 484 | |
485 | 485 | // Ignore closing parenthesis/bracket if not 'ours'. |
486 | - if ($tokens[$nextComma]['type'] === $tokens[$closer]['type'] && $nextComma !== $closer) { |
|
486 | + if ( $tokens[ $nextComma ][ 'type' ] === $tokens[ $closer ][ 'type' ] && $nextComma !== $closer ) { |
|
487 | 487 | continue; |
488 | 488 | } |
489 | 489 | |
490 | 490 | // Ok, we've reached the end of the parameter. |
491 | - $parameters[$cnt]['start'] = $paramStart; |
|
492 | - $parameters[$cnt]['end'] = $nextComma - 1; |
|
493 | - $parameters[$cnt]['raw'] = trim($phpcsFile->getTokensAsString($paramStart, ($nextComma - $paramStart))); |
|
491 | + $parameters[ $cnt ][ 'start' ] = $paramStart; |
|
492 | + $parameters[ $cnt ][ 'end' ] = $nextComma - 1; |
|
493 | + $parameters[ $cnt ][ 'raw' ] = trim( $phpcsFile->getTokensAsString( $paramStart, ( $nextComma - $paramStart ) ) ); |
|
494 | 494 | |
495 | 495 | // Check if there are more tokens before the closing parenthesis. |
496 | 496 | // Prevents code like the following from setting a third parameter: |
497 | 497 | // functionCall( $param1, $param2, ); |
498 | - $hasNextParam = $phpcsFile->findNext(Tokens::$emptyTokens, $nextComma + 1, $closer, true, null, true); |
|
499 | - if ($hasNextParam === false) { |
|
498 | + $hasNextParam = $phpcsFile->findNext( Tokens::$emptyTokens, $nextComma + 1, $closer, true, null, true ); |
|
499 | + if ( $hasNextParam === false ) { |
|
500 | 500 | break; |
501 | 501 | } |
502 | 502 | |
@@ -525,14 +525,14 @@ discard block |
||
525 | 525 | * |
526 | 526 | * @return array|false |
527 | 527 | */ |
528 | - public function getFunctionCallParameter(File $phpcsFile, $stackPtr, $paramOffset) |
|
528 | + public function getFunctionCallParameter( File $phpcsFile, $stackPtr, $paramOffset ) |
|
529 | 529 | { |
530 | - $parameters = $this->getFunctionCallParameters($phpcsFile, $stackPtr); |
|
530 | + $parameters = $this->getFunctionCallParameters( $phpcsFile, $stackPtr ); |
|
531 | 531 | |
532 | - if (isset($parameters[$paramOffset]) === false) { |
|
532 | + if ( isset( $parameters[ $paramOffset ] ) === false ) { |
|
533 | 533 | return false; |
534 | 534 | } else { |
535 | - return $parameters[$paramOffset]; |
|
535 | + return $parameters[ $paramOffset ]; |
|
536 | 536 | } |
537 | 537 | } |
538 | 538 | |
@@ -555,26 +555,26 @@ discard block |
||
555 | 555 | * If the $scopeTypes are set: True if *one* of the conditions is a |
556 | 556 | * valid scope, false otherwise. |
557 | 557 | */ |
558 | - public function tokenHasScope(File $phpcsFile, $stackPtr, $validScopes = null) |
|
558 | + public function tokenHasScope( File $phpcsFile, $stackPtr, $validScopes = null ) |
|
559 | 559 | { |
560 | 560 | $tokens = $phpcsFile->getTokens(); |
561 | 561 | |
562 | 562 | // Check for the existence of the token. |
563 | - if (isset($tokens[$stackPtr]) === false) { |
|
563 | + if ( isset( $tokens[ $stackPtr ] ) === false ) { |
|
564 | 564 | return false; |
565 | 565 | } |
566 | 566 | |
567 | 567 | // No conditions = no scope. |
568 | - if (empty($tokens[$stackPtr]['conditions'])) { |
|
568 | + if ( empty( $tokens[ $stackPtr ][ 'conditions' ] ) ) { |
|
569 | 569 | return false; |
570 | 570 | } |
571 | 571 | |
572 | 572 | // Ok, there are conditions, do we have to check for specific ones ? |
573 | - if (isset($validScopes) === false) { |
|
573 | + if ( isset( $validScopes ) === false ) { |
|
574 | 574 | return true; |
575 | 575 | } |
576 | 576 | |
577 | - return $phpcsFile->hasCondition($stackPtr, $validScopes); |
|
577 | + return $phpcsFile->hasCondition( $stackPtr, $validScopes ); |
|
578 | 578 | } |
579 | 579 | |
580 | 580 | |
@@ -589,19 +589,19 @@ discard block |
||
589 | 589 | * |
590 | 590 | * @return bool True if within class scope, false otherwise. |
591 | 591 | */ |
592 | - public function inClassScope(File $phpcsFile, $stackPtr, $strict = true) |
|
592 | + public function inClassScope( File $phpcsFile, $stackPtr, $strict = true ) |
|
593 | 593 | { |
594 | - $validScopes = array(\T_CLASS); |
|
595 | - if (\defined('T_ANON_CLASS') === true) { |
|
596 | - $validScopes[] = \T_ANON_CLASS; |
|
594 | + $validScopes = array( \T_CLASS ); |
|
595 | + if ( \defined( 'T_ANON_CLASS' ) === true ) { |
|
596 | + $validScopes[ ] = \T_ANON_CLASS; |
|
597 | 597 | } |
598 | 598 | |
599 | - if ($strict === false) { |
|
600 | - $validScopes[] = \T_INTERFACE; |
|
601 | - $validScopes[] = \T_TRAIT; |
|
599 | + if ( $strict === false ) { |
|
600 | + $validScopes[ ] = \T_INTERFACE; |
|
601 | + $validScopes[ ] = \T_TRAIT; |
|
602 | 602 | } |
603 | 603 | |
604 | - return $phpcsFile->hasCondition($stackPtr, $validScopes); |
|
604 | + return $phpcsFile->hasCondition( $stackPtr, $validScopes ); |
|
605 | 605 | } |
606 | 606 | |
607 | 607 | |
@@ -615,31 +615,31 @@ discard block |
||
615 | 615 | * |
616 | 616 | * @return string |
617 | 617 | */ |
618 | - public function getFQClassNameFromNewToken(File $phpcsFile, $stackPtr) |
|
618 | + public function getFQClassNameFromNewToken( File $phpcsFile, $stackPtr ) |
|
619 | 619 | { |
620 | 620 | $tokens = $phpcsFile->getTokens(); |
621 | 621 | |
622 | 622 | // Check for the existence of the token. |
623 | - if (isset($tokens[$stackPtr]) === false) { |
|
623 | + if ( isset( $tokens[ $stackPtr ] ) === false ) { |
|
624 | 624 | return ''; |
625 | 625 | } |
626 | 626 | |
627 | - if ($tokens[$stackPtr]['code'] !== \T_NEW) { |
|
627 | + if ( $tokens[ $stackPtr ][ 'code' ] !== \T_NEW ) { |
|
628 | 628 | return ''; |
629 | 629 | } |
630 | 630 | |
631 | - $start = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true); |
|
632 | - if ($start === false) { |
|
631 | + $start = $phpcsFile->findNext( Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true ); |
|
632 | + if ( $start === false ) { |
|
633 | 633 | return ''; |
634 | 634 | } |
635 | 635 | |
636 | 636 | // Bow out if the next token is a variable as we don't know where it was defined. |
637 | - if ($tokens[$start]['code'] === \T_VARIABLE) { |
|
637 | + if ( $tokens[ $start ][ 'code' ] === \T_VARIABLE ) { |
|
638 | 638 | return ''; |
639 | 639 | } |
640 | 640 | |
641 | 641 | // Bow out if the next token is the class keyword. |
642 | - if ($tokens[$start]['type'] === 'T_ANON_CLASS' || $tokens[$start]['code'] === \T_CLASS) { |
|
642 | + if ( $tokens[ $start ][ 'type' ] === 'T_ANON_CLASS' || $tokens[ $start ][ 'code' ] === \T_CLASS ) { |
|
643 | 643 | return ''; |
644 | 644 | } |
645 | 645 | |
@@ -650,11 +650,11 @@ discard block |
||
650 | 650 | \T_WHITESPACE, |
651 | 651 | ); |
652 | 652 | |
653 | - $end = $phpcsFile->findNext($find, ($start + 1), null, true, null, true); |
|
654 | - $className = $phpcsFile->getTokensAsString($start, ($end - $start)); |
|
655 | - $className = trim($className); |
|
653 | + $end = $phpcsFile->findNext( $find, ( $start + 1 ), null, true, null, true ); |
|
654 | + $className = $phpcsFile->getTokensAsString( $start, ( $end - $start ) ); |
|
655 | + $className = trim( $className ); |
|
656 | 656 | |
657 | - return $this->getFQName($phpcsFile, $stackPtr, $className); |
|
657 | + return $this->getFQName( $phpcsFile, $stackPtr, $className ); |
|
658 | 658 | } |
659 | 659 | |
660 | 660 | |
@@ -669,28 +669,28 @@ discard block |
||
669 | 669 | * |
670 | 670 | * @return string |
671 | 671 | */ |
672 | - public function getFQExtendedClassName(File $phpcsFile, $stackPtr) |
|
672 | + public function getFQExtendedClassName( File $phpcsFile, $stackPtr ) |
|
673 | 673 | { |
674 | 674 | $tokens = $phpcsFile->getTokens(); |
675 | 675 | |
676 | 676 | // Check for the existence of the token. |
677 | - if (isset($tokens[$stackPtr]) === false) { |
|
677 | + if ( isset( $tokens[ $stackPtr ] ) === false ) { |
|
678 | 678 | return ''; |
679 | 679 | } |
680 | 680 | |
681 | - if ($tokens[$stackPtr]['code'] !== \T_CLASS |
|
682 | - && $tokens[$stackPtr]['type'] !== 'T_ANON_CLASS' |
|
683 | - && $tokens[$stackPtr]['type'] !== 'T_INTERFACE' |
|
681 | + if ( $tokens[ $stackPtr ][ 'code' ] !== \T_CLASS |
|
682 | + && $tokens[ $stackPtr ][ 'type' ] !== 'T_ANON_CLASS' |
|
683 | + && $tokens[ $stackPtr ][ 'type' ] !== 'T_INTERFACE' |
|
684 | 684 | ) { |
685 | 685 | return ''; |
686 | 686 | } |
687 | 687 | |
688 | - $extends = PHPCSHelper::findExtendedClassName($phpcsFile, $stackPtr); |
|
689 | - if (empty($extends) || \is_string($extends) === false) { |
|
688 | + $extends = PHPCSHelper::findExtendedClassName( $phpcsFile, $stackPtr ); |
|
689 | + if ( empty( $extends ) || \is_string( $extends ) === false ) { |
|
690 | 690 | return ''; |
691 | 691 | } |
692 | 692 | |
693 | - return $this->getFQName($phpcsFile, $stackPtr, $extends); |
|
693 | + return $this->getFQName( $phpcsFile, $stackPtr, $extends ); |
|
694 | 694 | } |
695 | 695 | |
696 | 696 | |
@@ -705,37 +705,37 @@ discard block |
||
705 | 705 | * |
706 | 706 | * @return string |
707 | 707 | */ |
708 | - public function getFQClassNameFromDoubleColonToken(File $phpcsFile, $stackPtr) |
|
708 | + public function getFQClassNameFromDoubleColonToken( File $phpcsFile, $stackPtr ) |
|
709 | 709 | { |
710 | 710 | $tokens = $phpcsFile->getTokens(); |
711 | 711 | |
712 | 712 | // Check for the existence of the token. |
713 | - if (isset($tokens[$stackPtr]) === false) { |
|
713 | + if ( isset( $tokens[ $stackPtr ] ) === false ) { |
|
714 | 714 | return ''; |
715 | 715 | } |
716 | 716 | |
717 | - if ($tokens[$stackPtr]['code'] !== \T_DOUBLE_COLON) { |
|
717 | + if ( $tokens[ $stackPtr ][ 'code' ] !== \T_DOUBLE_COLON ) { |
|
718 | 718 | return ''; |
719 | 719 | } |
720 | 720 | |
721 | 721 | // Nothing to do if previous token is a variable as we don't know where it was defined. |
722 | - if ($tokens[$stackPtr - 1]['code'] === \T_VARIABLE) { |
|
722 | + if ( $tokens[ $stackPtr - 1 ][ 'code' ] === \T_VARIABLE ) { |
|
723 | 723 | return ''; |
724 | 724 | } |
725 | 725 | |
726 | 726 | // Nothing to do if 'parent' or 'static' as we don't know how far the class tree extends. |
727 | - if (\in_array($tokens[$stackPtr - 1]['code'], array(\T_PARENT, \T_STATIC), true)) { |
|
727 | + if ( \in_array( $tokens[ $stackPtr - 1 ][ 'code' ], array( \T_PARENT, \T_STATIC ), true ) ) { |
|
728 | 728 | return ''; |
729 | 729 | } |
730 | 730 | |
731 | 731 | // Get the classname from the class declaration if self is used. |
732 | - if ($tokens[$stackPtr - 1]['code'] === \T_SELF) { |
|
733 | - $classDeclarationPtr = $phpcsFile->findPrevious(\T_CLASS, $stackPtr - 1); |
|
734 | - if ($classDeclarationPtr === false) { |
|
732 | + if ( $tokens[ $stackPtr - 1 ][ 'code' ] === \T_SELF ) { |
|
733 | + $classDeclarationPtr = $phpcsFile->findPrevious( \T_CLASS, $stackPtr - 1 ); |
|
734 | + if ( $classDeclarationPtr === false ) { |
|
735 | 735 | return ''; |
736 | 736 | } |
737 | - $className = $phpcsFile->getDeclarationName($classDeclarationPtr); |
|
738 | - return $this->getFQName($phpcsFile, $classDeclarationPtr, $className); |
|
737 | + $className = $phpcsFile->getDeclarationName( $classDeclarationPtr ); |
|
738 | + return $this->getFQName( $phpcsFile, $classDeclarationPtr, $className ); |
|
739 | 739 | } |
740 | 740 | |
741 | 741 | $find = array( |
@@ -745,16 +745,16 @@ discard block |
||
745 | 745 | \T_WHITESPACE, |
746 | 746 | ); |
747 | 747 | |
748 | - $start = $phpcsFile->findPrevious($find, $stackPtr - 1, null, true, null, true); |
|
749 | - if ($start === false || isset($tokens[($start + 1)]) === false) { |
|
748 | + $start = $phpcsFile->findPrevious( $find, $stackPtr - 1, null, true, null, true ); |
|
749 | + if ( $start === false || isset( $tokens[ ( $start + 1 ) ] ) === false ) { |
|
750 | 750 | return ''; |
751 | 751 | } |
752 | 752 | |
753 | - $start = ($start + 1); |
|
754 | - $className = $phpcsFile->getTokensAsString($start, ($stackPtr - $start)); |
|
755 | - $className = trim($className); |
|
753 | + $start = ( $start + 1 ); |
|
754 | + $className = $phpcsFile->getTokensAsString( $start, ( $stackPtr - $start ) ); |
|
755 | + $className = trim( $className ); |
|
756 | 756 | |
757 | - return $this->getFQName($phpcsFile, $stackPtr, $className); |
|
757 | + return $this->getFQName( $phpcsFile, $stackPtr, $className ); |
|
758 | 758 | } |
759 | 759 | |
760 | 760 | |
@@ -770,21 +770,21 @@ discard block |
||
770 | 770 | * |
771 | 771 | * @return string |
772 | 772 | */ |
773 | - public function getFQName(File $phpcsFile, $stackPtr, $name) |
|
773 | + public function getFQName( File $phpcsFile, $stackPtr, $name ) |
|
774 | 774 | { |
775 | - if (strpos($name, '\\') === 0) { |
|
775 | + if ( strpos( $name, '\\' ) === 0 ) { |
|
776 | 776 | // Already fully qualified. |
777 | 777 | return $name; |
778 | 778 | } |
779 | 779 | |
780 | 780 | // Remove the namespace keyword if used. |
781 | - if (strpos($name, 'namespace\\') === 0) { |
|
782 | - $name = substr($name, 10); |
|
781 | + if ( strpos( $name, 'namespace\\' ) === 0 ) { |
|
782 | + $name = substr( $name, 10 ); |
|
783 | 783 | } |
784 | 784 | |
785 | - $namespace = $this->determineNamespace($phpcsFile, $stackPtr); |
|
785 | + $namespace = $this->determineNamespace( $phpcsFile, $stackPtr ); |
|
786 | 786 | |
787 | - if ($namespace === '') { |
|
787 | + if ( $namespace === '' ) { |
|
788 | 788 | return '\\' . $name; |
789 | 789 | } else { |
790 | 790 | return '\\' . $namespace . '\\' . $name; |
@@ -800,13 +800,13 @@ discard block |
||
800 | 800 | * |
801 | 801 | * @return bool True if namespaced, false if global. |
802 | 802 | */ |
803 | - public function isNamespaced($FQName) |
|
803 | + public function isNamespaced( $FQName ) |
|
804 | 804 | { |
805 | - if (strpos($FQName, '\\') !== 0) { |
|
806 | - throw new PHPCS_Exception('$FQName must be a fully qualified name'); |
|
805 | + if ( strpos( $FQName, '\\' ) !== 0 ) { |
|
806 | + throw new PHPCS_Exception( '$FQName must be a fully qualified name' ); |
|
807 | 807 | } |
808 | 808 | |
809 | - return (strpos(substr($FQName, 1), '\\') !== false); |
|
809 | + return ( strpos( substr( $FQName, 1 ), '\\' ) !== false ); |
|
810 | 810 | } |
811 | 811 | |
812 | 812 | |
@@ -818,21 +818,21 @@ discard block |
||
818 | 818 | * |
819 | 819 | * @return string Namespace name or empty string if it couldn't be determined or no namespace applies. |
820 | 820 | */ |
821 | - public function determineNamespace(File $phpcsFile, $stackPtr) |
|
821 | + public function determineNamespace( File $phpcsFile, $stackPtr ) |
|
822 | 822 | { |
823 | 823 | $tokens = $phpcsFile->getTokens(); |
824 | 824 | |
825 | 825 | // Check for the existence of the token. |
826 | - if (isset($tokens[$stackPtr]) === false) { |
|
826 | + if ( isset( $tokens[ $stackPtr ] ) === false ) { |
|
827 | 827 | return ''; |
828 | 828 | } |
829 | 829 | |
830 | 830 | // Check for scoped namespace {}. |
831 | - if (empty($tokens[$stackPtr]['conditions']) === false) { |
|
832 | - $namespacePtr = $phpcsFile->getCondition($stackPtr, \T_NAMESPACE); |
|
833 | - if ($namespacePtr !== false) { |
|
834 | - $namespace = $this->getDeclaredNamespaceName($phpcsFile, $namespacePtr); |
|
835 | - if ($namespace !== false) { |
|
831 | + if ( empty( $tokens[ $stackPtr ][ 'conditions' ] ) === false ) { |
|
832 | + $namespacePtr = $phpcsFile->getCondition( $stackPtr, \T_NAMESPACE ); |
|
833 | + if ( $namespacePtr !== false ) { |
|
834 | + $namespace = $this->getDeclaredNamespaceName( $phpcsFile, $namespacePtr ); |
|
835 | + if ( $namespace !== false ) { |
|
836 | 836 | return $namespace; |
837 | 837 | } |
838 | 838 | |
@@ -851,19 +851,19 @@ discard block |
||
851 | 851 | $previousNSToken = $stackPtr; |
852 | 852 | $namespace = false; |
853 | 853 | do { |
854 | - $previousNSToken = $phpcsFile->findPrevious(\T_NAMESPACE, ($previousNSToken - 1)); |
|
854 | + $previousNSToken = $phpcsFile->findPrevious( \T_NAMESPACE, ( $previousNSToken - 1 ) ); |
|
855 | 855 | |
856 | 856 | // Stop if we encounter a scoped namespace declaration as we already know we're not in one. |
857 | - if (empty($tokens[$previousNSToken]['scope_condition']) === false && $tokens[$previousNSToken]['scope_condition'] === $previousNSToken) { |
|
857 | + if ( empty( $tokens[ $previousNSToken ][ 'scope_condition' ] ) === false && $tokens[ $previousNSToken ][ 'scope_condition' ] === $previousNSToken ) { |
|
858 | 858 | break; |
859 | 859 | } |
860 | 860 | |
861 | - $namespace = $this->getDeclaredNamespaceName($phpcsFile, $previousNSToken); |
|
861 | + $namespace = $this->getDeclaredNamespaceName( $phpcsFile, $previousNSToken ); |
|
862 | 862 | |
863 | - } while ($namespace === false && $previousNSToken !== false); |
|
863 | + } while ( $namespace === false && $previousNSToken !== false ); |
|
864 | 864 | |
865 | 865 | // If we still haven't got a namespace, return an empty string. |
866 | - if ($namespace === false) { |
|
866 | + if ( $namespace === false ) { |
|
867 | 867 | return ''; |
868 | 868 | } else { |
869 | 869 | return $namespace; |
@@ -882,26 +882,26 @@ discard block |
||
882 | 882 | * @return string|false Namespace name or false if not a namespace declaration. |
883 | 883 | * Namespace name can be an empty string for global namespace declaration. |
884 | 884 | */ |
885 | - public function getDeclaredNamespaceName(File $phpcsFile, $stackPtr) |
|
885 | + public function getDeclaredNamespaceName( File $phpcsFile, $stackPtr ) |
|
886 | 886 | { |
887 | 887 | $tokens = $phpcsFile->getTokens(); |
888 | 888 | |
889 | 889 | // Check for the existence of the token. |
890 | - if ($stackPtr === false || isset($tokens[$stackPtr]) === false) { |
|
890 | + if ( $stackPtr === false || isset( $tokens[ $stackPtr ] ) === false ) { |
|
891 | 891 | return false; |
892 | 892 | } |
893 | 893 | |
894 | - if ($tokens[$stackPtr]['code'] !== \T_NAMESPACE) { |
|
894 | + if ( $tokens[ $stackPtr ][ 'code' ] !== \T_NAMESPACE ) { |
|
895 | 895 | return false; |
896 | 896 | } |
897 | 897 | |
898 | - if ($tokens[($stackPtr + 1)]['code'] === \T_NS_SEPARATOR) { |
|
898 | + if ( $tokens[ ( $stackPtr + 1 ) ][ 'code' ] === \T_NS_SEPARATOR ) { |
|
899 | 899 | // Not a namespace declaration, but use of, i.e. namespace\someFunction(); |
900 | 900 | return false; |
901 | 901 | } |
902 | 902 | |
903 | - $nextToken = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true, null, true); |
|
904 | - if ($tokens[$nextToken]['code'] === \T_OPEN_CURLY_BRACKET) { |
|
903 | + $nextToken = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true ); |
|
904 | + if ( $tokens[ $nextToken ][ 'code' ] === \T_OPEN_CURLY_BRACKET ) { |
|
905 | 905 | // Declaration for global namespace when using multiple namespaces in a file. |
906 | 906 | // I.e.: namespace {} |
907 | 907 | return ''; |
@@ -915,8 +915,8 @@ discard block |
||
915 | 915 | ); |
916 | 916 | |
917 | 917 | $namespaceName = ''; |
918 | - while (isset($validTokens[$tokens[$nextToken]['code']]) === true) { |
|
919 | - $namespaceName .= trim($tokens[$nextToken]['content']); |
|
918 | + while ( isset( $validTokens[ $tokens[ $nextToken ][ 'code' ] ] ) === true ) { |
|
919 | + $namespaceName .= trim( $tokens[ $nextToken ][ 'content' ] ); |
|
920 | 920 | $nextToken++; |
921 | 921 | } |
922 | 922 | |
@@ -939,43 +939,43 @@ discard block |
||
939 | 939 | * no return type was found or the passed token was |
940 | 940 | * not of the correct type. |
941 | 941 | */ |
942 | - public function getReturnTypeHintToken(File $phpcsFile, $stackPtr) |
|
942 | + public function getReturnTypeHintToken( File $phpcsFile, $stackPtr ) |
|
943 | 943 | { |
944 | 944 | $tokens = $phpcsFile->getTokens(); |
945 | 945 | |
946 | - if (\defined('T_RETURN_TYPE') && $tokens[$stackPtr]['code'] === \T_RETURN_TYPE) { |
|
946 | + if ( \defined( 'T_RETURN_TYPE' ) && $tokens[ $stackPtr ][ 'code' ] === \T_RETURN_TYPE ) { |
|
947 | 947 | return $stackPtr; |
948 | 948 | } |
949 | 949 | |
950 | - if ($tokens[$stackPtr]['code'] !== \T_FUNCTION && $tokens[$stackPtr]['code'] !== \T_CLOSURE) { |
|
950 | + if ( $tokens[ $stackPtr ][ 'code' ] !== \T_FUNCTION && $tokens[ $stackPtr ][ 'code' ] !== \T_CLOSURE ) { |
|
951 | 951 | return false; |
952 | 952 | } |
953 | 953 | |
954 | - if (isset($tokens[$stackPtr]['parenthesis_closer']) === false) { |
|
954 | + if ( isset( $tokens[ $stackPtr ][ 'parenthesis_closer' ] ) === false ) { |
|
955 | 955 | return false; |
956 | 956 | } |
957 | 957 | |
958 | 958 | // Allow for interface and abstract method declarations. |
959 | 959 | $endOfFunctionDeclaration = null; |
960 | - if (isset($tokens[$stackPtr]['scope_opener'])) { |
|
961 | - $endOfFunctionDeclaration = $tokens[$stackPtr]['scope_opener']; |
|
960 | + if ( isset( $tokens[ $stackPtr ][ 'scope_opener' ] ) ) { |
|
961 | + $endOfFunctionDeclaration = $tokens[ $stackPtr ][ 'scope_opener' ]; |
|
962 | 962 | } else { |
963 | - $nextSemiColon = $phpcsFile->findNext(\T_SEMICOLON, ($tokens[$stackPtr]['parenthesis_closer'] + 1), null, false, null, true); |
|
964 | - if ($nextSemiColon !== false) { |
|
963 | + $nextSemiColon = $phpcsFile->findNext( \T_SEMICOLON, ( $tokens[ $stackPtr ][ 'parenthesis_closer' ] + 1 ), null, false, null, true ); |
|
964 | + if ( $nextSemiColon !== false ) { |
|
965 | 965 | $endOfFunctionDeclaration = $nextSemiColon; |
966 | 966 | } |
967 | 967 | } |
968 | 968 | |
969 | - if (isset($endOfFunctionDeclaration) === false) { |
|
969 | + if ( isset( $endOfFunctionDeclaration ) === false ) { |
|
970 | 970 | return false; |
971 | 971 | } |
972 | 972 | |
973 | 973 | $hasColon = $phpcsFile->findNext( |
974 | - array(\T_COLON, \T_INLINE_ELSE), |
|
975 | - ($tokens[$stackPtr]['parenthesis_closer'] + 1), |
|
974 | + array( \T_COLON, \T_INLINE_ELSE ), |
|
975 | + ( $tokens[ $stackPtr ][ 'parenthesis_closer' ] + 1 ), |
|
976 | 976 | $endOfFunctionDeclaration |
977 | 977 | ); |
978 | - if ($hasColon === false) { |
|
978 | + if ( $hasColon === false ) { |
|
979 | 979 | return false; |
980 | 980 | } |
981 | 981 | |
@@ -996,7 +996,7 @@ discard block |
||
996 | 996 | \T_STRING, |
997 | 997 | ); |
998 | 998 | |
999 | - return $phpcsFile->findPrevious($unrecognizedTypes, ($endOfFunctionDeclaration - 1), $hasColon); |
|
999 | + return $phpcsFile->findPrevious( $unrecognizedTypes, ( $endOfFunctionDeclaration - 1 ), $hasColon ); |
|
1000 | 1000 | } |
1001 | 1001 | |
1002 | 1002 | |
@@ -1018,37 +1018,37 @@ discard block |
||
1018 | 1018 | * |
1019 | 1019 | * @return string|false The name of the return type token. |
1020 | 1020 | */ |
1021 | - public function getReturnTypeHintName(File $phpcsFile, $stackPtr) |
|
1021 | + public function getReturnTypeHintName( File $phpcsFile, $stackPtr ) |
|
1022 | 1022 | { |
1023 | 1023 | $tokens = $phpcsFile->getTokens(); |
1024 | 1024 | |
1025 | 1025 | // In older PHPCS versions, the nullable indicator will turn a return type colon into a T_INLINE_ELSE. |
1026 | - $colon = $phpcsFile->findPrevious(array(\T_COLON, \T_INLINE_ELSE, \T_FUNCTION, \T_CLOSE_PARENTHESIS), ($stackPtr - 1)); |
|
1027 | - if ($colon === false |
|
1028 | - || ($tokens[$colon]['code'] !== \T_COLON && $tokens[$colon]['code'] !== \T_INLINE_ELSE) |
|
1026 | + $colon = $phpcsFile->findPrevious( array( \T_COLON, \T_INLINE_ELSE, \T_FUNCTION, \T_CLOSE_PARENTHESIS ), ( $stackPtr - 1 ) ); |
|
1027 | + if ( $colon === false |
|
1028 | + || ( $tokens[ $colon ][ 'code' ] !== \T_COLON && $tokens[ $colon ][ 'code' ] !== \T_INLINE_ELSE ) |
|
1029 | 1029 | ) { |
1030 | 1030 | // Shouldn't happen, just in case. |
1031 | 1031 | return; |
1032 | 1032 | } |
1033 | 1033 | |
1034 | 1034 | $returnTypeHint = ''; |
1035 | - for ($i = ($colon + 1); $i <= $stackPtr; $i++) { |
|
1035 | + for ( $i = ( $colon + 1 ); $i <= $stackPtr; $i++ ) { |
|
1036 | 1036 | // As of PHPCS 3.3.0+, all tokens are tokenized as "normal", so T_CALLABLE, T_SELF etc are |
1037 | 1037 | // all possible, just exclude anything that's regarded as empty and the nullable indicator. |
1038 | - if (isset(Tokens::$emptyTokens[$tokens[$i]['code']])) { |
|
1038 | + if ( isset( Tokens::$emptyTokens[ $tokens[ $i ][ 'code' ] ] ) ) { |
|
1039 | 1039 | continue; |
1040 | 1040 | } |
1041 | 1041 | |
1042 | - if ($tokens[$i]['type'] === 'T_NULLABLE') { |
|
1042 | + if ( $tokens[ $i ][ 'type' ] === 'T_NULLABLE' ) { |
|
1043 | 1043 | continue; |
1044 | 1044 | } |
1045 | 1045 | |
1046 | - if (\defined('T_NULLABLE') === false && $tokens[$i]['code'] === \T_INLINE_THEN) { |
|
1046 | + if ( \defined( 'T_NULLABLE' ) === false && $tokens[ $i ][ 'code' ] === \T_INLINE_THEN ) { |
|
1047 | 1047 | // Old PHPCS. |
1048 | 1048 | continue; |
1049 | 1049 | } |
1050 | 1050 | |
1051 | - $returnTypeHint .= $tokens[$i]['content']; |
|
1051 | + $returnTypeHint .= $tokens[ $i ][ 'content' ]; |
|
1052 | 1052 | } |
1053 | 1053 | |
1054 | 1054 | return $returnTypeHint; |
@@ -1069,11 +1069,11 @@ discard block |
||
1069 | 1069 | * |
1070 | 1070 | * @return bool |
1071 | 1071 | */ |
1072 | - public function isClassProperty(File $phpcsFile, $stackPtr) |
|
1072 | + public function isClassProperty( File $phpcsFile, $stackPtr ) |
|
1073 | 1073 | { |
1074 | 1074 | $tokens = $phpcsFile->getTokens(); |
1075 | 1075 | |
1076 | - if (isset($tokens[$stackPtr]) === false || $tokens[$stackPtr]['code'] !== \T_VARIABLE) { |
|
1076 | + if ( isset( $tokens[ $stackPtr ] ) === false || $tokens[ $stackPtr ][ 'code' ] !== \T_VARIABLE ) { |
|
1077 | 1077 | return false; |
1078 | 1078 | } |
1079 | 1079 | |
@@ -1084,17 +1084,17 @@ discard block |
||
1084 | 1084 | 'T_TRAIT' => true, |
1085 | 1085 | ); |
1086 | 1086 | |
1087 | - $scopePtr = $this->validDirectScope($phpcsFile, $stackPtr, $validScopes); |
|
1088 | - if ($scopePtr !== false) { |
|
1087 | + $scopePtr = $this->validDirectScope( $phpcsFile, $stackPtr, $validScopes ); |
|
1088 | + if ( $scopePtr !== false ) { |
|
1089 | 1089 | // Make sure it's not a method parameter. |
1090 | - if (empty($tokens[$stackPtr]['nested_parenthesis']) === true) { |
|
1090 | + if ( empty( $tokens[ $stackPtr ][ 'nested_parenthesis' ] ) === true ) { |
|
1091 | 1091 | return true; |
1092 | 1092 | } else { |
1093 | - $parenthesis = array_keys($tokens[$stackPtr]['nested_parenthesis']); |
|
1094 | - $deepestOpen = array_pop($parenthesis); |
|
1095 | - if ($deepestOpen < $scopePtr |
|
1096 | - || isset($tokens[$deepestOpen]['parenthesis_owner']) === false |
|
1097 | - || $tokens[$tokens[$deepestOpen]['parenthesis_owner']]['code'] !== \T_FUNCTION |
|
1093 | + $parenthesis = array_keys( $tokens[ $stackPtr ][ 'nested_parenthesis' ] ); |
|
1094 | + $deepestOpen = array_pop( $parenthesis ); |
|
1095 | + if ( $deepestOpen < $scopePtr |
|
1096 | + || isset( $tokens[ $deepestOpen ][ 'parenthesis_owner' ] ) === false |
|
1097 | + || $tokens[ $tokens[ $deepestOpen ][ 'parenthesis_owner' ] ][ 'code' ] !== \T_FUNCTION |
|
1098 | 1098 | ) { |
1099 | 1099 | return true; |
1100 | 1100 | } |
@@ -1114,11 +1114,11 @@ discard block |
||
1114 | 1114 | * |
1115 | 1115 | * @return bool |
1116 | 1116 | */ |
1117 | - public function isClassConstant(File $phpcsFile, $stackPtr) |
|
1117 | + public function isClassConstant( File $phpcsFile, $stackPtr ) |
|
1118 | 1118 | { |
1119 | 1119 | $tokens = $phpcsFile->getTokens(); |
1120 | 1120 | |
1121 | - if (isset($tokens[$stackPtr]) === false || $tokens[$stackPtr]['code'] !== \T_CONST) { |
|
1121 | + if ( isset( $tokens[ $stackPtr ] ) === false || $tokens[ $stackPtr ][ 'code' ] !== \T_CONST ) { |
|
1122 | 1122 | return false; |
1123 | 1123 | } |
1124 | 1124 | |
@@ -1128,7 +1128,7 @@ discard block |
||
1128 | 1128 | 'T_ANON_CLASS' => true, |
1129 | 1129 | 'T_INTERFACE' => true, |
1130 | 1130 | ); |
1131 | - if ($this->validDirectScope($phpcsFile, $stackPtr, $validScopes) !== false) { |
|
1131 | + if ( $this->validDirectScope( $phpcsFile, $stackPtr, $validScopes ) !== false ) { |
|
1132 | 1132 | return true; |
1133 | 1133 | } |
1134 | 1134 | |
@@ -1152,25 +1152,25 @@ discard block |
||
1152 | 1152 | * |
1153 | 1153 | * @return int|bool StackPtr to the scope if valid, false otherwise. |
1154 | 1154 | */ |
1155 | - protected function validDirectScope(File $phpcsFile, $stackPtr, $validScopes) |
|
1155 | + protected function validDirectScope( File $phpcsFile, $stackPtr, $validScopes ) |
|
1156 | 1156 | { |
1157 | 1157 | $tokens = $phpcsFile->getTokens(); |
1158 | 1158 | |
1159 | - if (empty($tokens[$stackPtr]['conditions']) === true) { |
|
1159 | + if ( empty( $tokens[ $stackPtr ][ 'conditions' ] ) === true ) { |
|
1160 | 1160 | return false; |
1161 | 1161 | } |
1162 | 1162 | |
1163 | 1163 | /* |
1164 | 1164 | * Check only the direct wrapping scope of the token. |
1165 | 1165 | */ |
1166 | - $conditions = array_keys($tokens[$stackPtr]['conditions']); |
|
1167 | - $ptr = array_pop($conditions); |
|
1166 | + $conditions = array_keys( $tokens[ $stackPtr ][ 'conditions' ] ); |
|
1167 | + $ptr = array_pop( $conditions ); |
|
1168 | 1168 | |
1169 | - if (isset($tokens[$ptr]) === false) { |
|
1169 | + if ( isset( $tokens[ $ptr ] ) === false ) { |
|
1170 | 1170 | return false; |
1171 | 1171 | } |
1172 | 1172 | |
1173 | - if (isset($validScopes[$tokens[$ptr]['type']]) === true) { |
|
1173 | + if ( isset( $validScopes[ $tokens[ $ptr ][ 'type' ] ] ) === true ) { |
|
1174 | 1174 | return $ptr; |
1175 | 1175 | } |
1176 | 1176 | |
@@ -1194,34 +1194,34 @@ discard block |
||
1194 | 1194 | * - no type hints were found |
1195 | 1195 | * - or the passed token was not of the correct type. |
1196 | 1196 | */ |
1197 | - public function getTypeHintsFromFunctionDeclaration(File $phpcsFile, $stackPtr) |
|
1197 | + public function getTypeHintsFromFunctionDeclaration( File $phpcsFile, $stackPtr ) |
|
1198 | 1198 | { |
1199 | 1199 | $tokens = $phpcsFile->getTokens(); |
1200 | 1200 | |
1201 | - if ($tokens[$stackPtr]['code'] !== \T_FUNCTION && $tokens[$stackPtr]['code'] !== \T_CLOSURE) { |
|
1201 | + if ( $tokens[ $stackPtr ][ 'code' ] !== \T_FUNCTION && $tokens[ $stackPtr ][ 'code' ] !== \T_CLOSURE ) { |
|
1202 | 1202 | return array(); |
1203 | 1203 | } |
1204 | 1204 | |
1205 | - $parameters = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr); |
|
1206 | - if (empty($parameters) || \is_array($parameters) === false) { |
|
1205 | + $parameters = PHPCSHelper::getMethodParameters( $phpcsFile, $stackPtr ); |
|
1206 | + if ( empty( $parameters ) || \is_array( $parameters ) === false ) { |
|
1207 | 1207 | return array(); |
1208 | 1208 | } |
1209 | 1209 | |
1210 | 1210 | $typeHints = array(); |
1211 | 1211 | |
1212 | - foreach ($parameters as $param) { |
|
1213 | - if ($param['type_hint'] === '') { |
|
1212 | + foreach ( $parameters as $param ) { |
|
1213 | + if ( $param[ 'type_hint' ] === '' ) { |
|
1214 | 1214 | continue; |
1215 | 1215 | } |
1216 | 1216 | |
1217 | 1217 | // Strip off potential nullable indication. |
1218 | - $typeHint = ltrim($param['type_hint'], '?'); |
|
1218 | + $typeHint = ltrim( $param[ 'type_hint' ], '?' ); |
|
1219 | 1219 | |
1220 | 1220 | // Strip off potential (global) namespace indication. |
1221 | - $typeHint = ltrim($typeHint, '\\'); |
|
1221 | + $typeHint = ltrim( $typeHint, '\\' ); |
|
1222 | 1222 | |
1223 | - if ($typeHint !== '') { |
|
1224 | - $typeHints[] = $typeHint; |
|
1223 | + if ( $typeHint !== '' ) { |
|
1224 | + $typeHints[ ] = $typeHint; |
|
1225 | 1225 | } |
1226 | 1226 | } |
1227 | 1227 | |
@@ -1238,36 +1238,36 @@ discard block |
||
1238 | 1238 | * @return string|false The algorithm name without quotes if this was a relevant hash |
1239 | 1239 | * function call or false if it was not. |
1240 | 1240 | */ |
1241 | - public function getHashAlgorithmParameter(File $phpcsFile, $stackPtr) |
|
1241 | + public function getHashAlgorithmParameter( File $phpcsFile, $stackPtr ) |
|
1242 | 1242 | { |
1243 | 1243 | $tokens = $phpcsFile->getTokens(); |
1244 | 1244 | |
1245 | 1245 | // Check for the existence of the token. |
1246 | - if (isset($tokens[$stackPtr]) === false) { |
|
1246 | + if ( isset( $tokens[ $stackPtr ] ) === false ) { |
|
1247 | 1247 | return false; |
1248 | 1248 | } |
1249 | 1249 | |
1250 | - if ($tokens[$stackPtr]['code'] !== \T_STRING) { |
|
1250 | + if ( $tokens[ $stackPtr ][ 'code' ] !== \T_STRING ) { |
|
1251 | 1251 | return false; |
1252 | 1252 | } |
1253 | 1253 | |
1254 | - $functionName = $tokens[$stackPtr]['content']; |
|
1255 | - $functionNameLc = strtolower($functionName); |
|
1254 | + $functionName = $tokens[ $stackPtr ][ 'content' ]; |
|
1255 | + $functionNameLc = strtolower( $functionName ); |
|
1256 | 1256 | |
1257 | 1257 | // Bow out if not one of the functions we're targetting. |
1258 | - if (isset($this->hashAlgoFunctions[$functionNameLc]) === false) { |
|
1258 | + if ( isset( $this->hashAlgoFunctions[ $functionNameLc ] ) === false ) { |
|
1259 | 1259 | return false; |
1260 | 1260 | } |
1261 | 1261 | |
1262 | 1262 | // Get the parameter from the function call which should contain the algorithm name. |
1263 | - $algoParam = $this->getFunctionCallParameter($phpcsFile, $stackPtr, $this->hashAlgoFunctions[$functionNameLc]); |
|
1264 | - if ($algoParam === false) { |
|
1263 | + $algoParam = $this->getFunctionCallParameter( $phpcsFile, $stackPtr, $this->hashAlgoFunctions[ $functionNameLc ] ); |
|
1264 | + if ( $algoParam === false ) { |
|
1265 | 1265 | return false; |
1266 | 1266 | } |
1267 | 1267 | |
1268 | 1268 | // Algorithm is a text string, so we need to remove the quotes. |
1269 | - $algo = strtolower(trim($algoParam['raw'])); |
|
1270 | - $algo = $this->stripQuotes($algo); |
|
1269 | + $algo = strtolower( trim( $algoParam[ 'raw' ] ) ); |
|
1270 | + $algo = $this->stripQuotes( $algo ); |
|
1271 | 1271 | |
1272 | 1272 | return $algo; |
1273 | 1273 | } |
@@ -1281,36 +1281,36 @@ discard block |
||
1281 | 1281 | * |
1282 | 1282 | * @return bool |
1283 | 1283 | */ |
1284 | - public function isUseOfGlobalConstant(File $phpcsFile, $stackPtr) |
|
1284 | + public function isUseOfGlobalConstant( File $phpcsFile, $stackPtr ) |
|
1285 | 1285 | { |
1286 | 1286 | static $isLowPHPCS, $isLowPHP; |
1287 | 1287 | |
1288 | 1288 | $tokens = $phpcsFile->getTokens(); |
1289 | 1289 | |
1290 | 1290 | // Check for the existence of the token. |
1291 | - if (isset($tokens[$stackPtr]) === false) { |
|
1291 | + if ( isset( $tokens[ $stackPtr ] ) === false ) { |
|
1292 | 1292 | return false; |
1293 | 1293 | } |
1294 | 1294 | |
1295 | 1295 | // Is this one of the tokens this function handles ? |
1296 | - if ($tokens[$stackPtr]['code'] !== \T_STRING) { |
|
1296 | + if ( $tokens[ $stackPtr ][ 'code' ] !== \T_STRING ) { |
|
1297 | 1297 | return false; |
1298 | 1298 | } |
1299 | 1299 | |
1300 | 1300 | // Check for older PHP, PHPCS version so we can compensate for misidentified tokens. |
1301 | - if (isset($isLowPHPCS, $isLowPHP) === false) { |
|
1301 | + if ( isset( $isLowPHPCS, $isLowPHP ) === false ) { |
|
1302 | 1302 | $isLowPHP = false; |
1303 | 1303 | $isLowPHPCS = false; |
1304 | - if (version_compare(\PHP_VERSION_ID, '50400', '<')) { |
|
1304 | + if ( version_compare( \PHP_VERSION_ID, '50400', '<' ) ) { |
|
1305 | 1305 | $isLowPHP = true; |
1306 | - $isLowPHPCS = version_compare(PHPCSHelper::getVersion(), '2.4.0', '<'); |
|
1306 | + $isLowPHPCS = version_compare( PHPCSHelper::getVersion(), '2.4.0', '<' ); |
|
1307 | 1307 | } |
1308 | 1308 | } |
1309 | 1309 | |
1310 | - $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); |
|
1311 | - if ($next !== false |
|
1312 | - && ($tokens[$next]['code'] === \T_OPEN_PARENTHESIS |
|
1313 | - || $tokens[$next]['code'] === \T_DOUBLE_COLON) |
|
1310 | + $next = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); |
|
1311 | + if ( $next !== false |
|
1312 | + && ( $tokens[ $next ][ 'code' ] === \T_OPEN_PARENTHESIS |
|
1313 | + || $tokens[ $next ][ 'code' ] === \T_DOUBLE_COLON ) |
|
1314 | 1314 | ) { |
1315 | 1315 | // Function call or declaration. |
1316 | 1316 | return false; |
@@ -1338,30 +1338,30 @@ discard block |
||
1338 | 1338 | 'T_PRIVATE' => true, |
1339 | 1339 | ); |
1340 | 1340 | |
1341 | - $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
|
1342 | - if ($prev !== false |
|
1343 | - && (isset($tokensToIgnore[$tokens[$prev]['type']]) === true |
|
1344 | - || ($tokens[$prev]['code'] === \T_STRING |
|
1345 | - && (($isLowPHPCS === true |
|
1346 | - && $tokens[$prev]['content'] === 'trait') |
|
1347 | - || ($isLowPHP === true |
|
1348 | - && $tokens[$prev]['content'] === 'insteadof')))) |
|
1341 | + $prev = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true ); |
|
1342 | + if ( $prev !== false |
|
1343 | + && ( isset( $tokensToIgnore[ $tokens[ $prev ][ 'type' ] ] ) === true |
|
1344 | + || ( $tokens[ $prev ][ 'code' ] === \T_STRING |
|
1345 | + && ( ( $isLowPHPCS === true |
|
1346 | + && $tokens[ $prev ][ 'content' ] === 'trait' ) |
|
1347 | + || ( $isLowPHP === true |
|
1348 | + && $tokens[ $prev ][ 'content' ] === 'insteadof' ) ) ) ) |
|
1349 | 1349 | ) { |
1350 | 1350 | // Not the use of a constant. |
1351 | 1351 | return false; |
1352 | 1352 | } |
1353 | 1353 | |
1354 | - if ($prev !== false |
|
1355 | - && $tokens[$prev]['code'] === \T_NS_SEPARATOR |
|
1356 | - && $tokens[($prev - 1)]['code'] === \T_STRING |
|
1354 | + if ( $prev !== false |
|
1355 | + && $tokens[ $prev ][ 'code' ] === \T_NS_SEPARATOR |
|
1356 | + && $tokens[ ( $prev - 1 ) ][ 'code' ] === \T_STRING |
|
1357 | 1357 | ) { |
1358 | 1358 | // Namespaced constant of the same name. |
1359 | 1359 | return false; |
1360 | 1360 | } |
1361 | 1361 | |
1362 | - if ($prev !== false |
|
1363 | - && $tokens[$prev]['code'] === \T_CONST |
|
1364 | - && $this->isClassConstant($phpcsFile, $prev) === true |
|
1362 | + if ( $prev !== false |
|
1363 | + && $tokens[ $prev ][ 'code' ] === \T_CONST |
|
1364 | + && $this->isClassConstant( $phpcsFile, $prev ) === true |
|
1365 | 1365 | ) { |
1366 | 1366 | // Class constant declaration of the same name. |
1367 | 1367 | return false; |
@@ -1370,21 +1370,21 @@ discard block |
||
1370 | 1370 | /* |
1371 | 1371 | * Deal with a number of variations of use statements. |
1372 | 1372 | */ |
1373 | - for ($i = $stackPtr; $i > 0; $i--) { |
|
1374 | - if ($tokens[$i]['line'] !== $tokens[$stackPtr]['line']) { |
|
1373 | + for ( $i = $stackPtr; $i > 0; $i-- ) { |
|
1374 | + if ( $tokens[ $i ][ 'line' ] !== $tokens[ $stackPtr ][ 'line' ] ) { |
|
1375 | 1375 | break; |
1376 | 1376 | } |
1377 | 1377 | } |
1378 | 1378 | |
1379 | - $firstOnLine = $phpcsFile->findNext(Tokens::$emptyTokens, ($i + 1), null, true); |
|
1380 | - if ($firstOnLine !== false && $tokens[$firstOnLine]['code'] === \T_USE) { |
|
1381 | - $nextOnLine = $phpcsFile->findNext(Tokens::$emptyTokens, ($firstOnLine + 1), null, true); |
|
1382 | - if ($nextOnLine !== false) { |
|
1383 | - if (($tokens[$nextOnLine]['code'] === \T_STRING && $tokens[$nextOnLine]['content'] === 'const') |
|
1384 | - || $tokens[$nextOnLine]['code'] === \T_CONST // Happens in some PHPCS versions. |
|
1379 | + $firstOnLine = $phpcsFile->findNext( Tokens::$emptyTokens, ( $i + 1 ), null, true ); |
|
1380 | + if ( $firstOnLine !== false && $tokens[ $firstOnLine ][ 'code' ] === \T_USE ) { |
|
1381 | + $nextOnLine = $phpcsFile->findNext( Tokens::$emptyTokens, ( $firstOnLine + 1 ), null, true ); |
|
1382 | + if ( $nextOnLine !== false ) { |
|
1383 | + if ( ( $tokens[ $nextOnLine ][ 'code' ] === \T_STRING && $tokens[ $nextOnLine ][ 'content' ] === 'const' ) |
|
1384 | + || $tokens[ $nextOnLine ][ 'code' ] === \T_CONST // Happens in some PHPCS versions. |
|
1385 | 1385 | ) { |
1386 | - $hasNsSep = $phpcsFile->findNext(\T_NS_SEPARATOR, ($nextOnLine + 1), $stackPtr); |
|
1387 | - if ($hasNsSep !== false) { |
|
1386 | + $hasNsSep = $phpcsFile->findNext( \T_NS_SEPARATOR, ( $nextOnLine + 1 ), $stackPtr ); |
|
1387 | + if ( $hasNsSep !== false ) { |
|
1388 | 1388 | // Namespaced const (group) use statement. |
1389 | 1389 | return false; |
1390 | 1390 | } |
@@ -1419,15 +1419,15 @@ discard block |
||
1419 | 1419 | * False if not or if it could not be reliably determined |
1420 | 1420 | * (variable or calculations and such). |
1421 | 1421 | */ |
1422 | - public function isPositiveNumber(File $phpcsFile, $start, $end, $allowFloats = false) |
|
1422 | + public function isPositiveNumber( File $phpcsFile, $start, $end, $allowFloats = false ) |
|
1423 | 1423 | { |
1424 | - $number = $this->isNumber($phpcsFile, $start, $end, $allowFloats); |
|
1424 | + $number = $this->isNumber( $phpcsFile, $start, $end, $allowFloats ); |
|
1425 | 1425 | |
1426 | - if ($number === false) { |
|
1426 | + if ( $number === false ) { |
|
1427 | 1427 | return false; |
1428 | 1428 | } |
1429 | 1429 | |
1430 | - return ($number > 0); |
|
1430 | + return ( $number > 0 ); |
|
1431 | 1431 | } |
1432 | 1432 | |
1433 | 1433 | |
@@ -1451,15 +1451,15 @@ discard block |
||
1451 | 1451 | * False if not or if it could not be reliably determined |
1452 | 1452 | * (variable or calculations and such). |
1453 | 1453 | */ |
1454 | - public function isNegativeNumber(File $phpcsFile, $start, $end, $allowFloats = false) |
|
1454 | + public function isNegativeNumber( File $phpcsFile, $start, $end, $allowFloats = false ) |
|
1455 | 1455 | { |
1456 | - $number = $this->isNumber($phpcsFile, $start, $end, $allowFloats); |
|
1456 | + $number = $this->isNumber( $phpcsFile, $start, $end, $allowFloats ); |
|
1457 | 1457 | |
1458 | - if ($number === false) { |
|
1458 | + if ( $number === false ) { |
|
1459 | 1459 | return false; |
1460 | 1460 | } |
1461 | 1461 | |
1462 | - return ($number < 0); |
|
1462 | + return ( $number < 0 ); |
|
1463 | 1463 | } |
1464 | 1464 | |
1465 | 1465 | /** |
@@ -1488,89 +1488,89 @@ discard block |
||
1488 | 1488 | * number or if it could not be reliably determined |
1489 | 1489 | * (variable or calculations and such). |
1490 | 1490 | */ |
1491 | - protected function isNumber(File $phpcsFile, $start, $end, $allowFloats = false) |
|
1491 | + protected function isNumber( File $phpcsFile, $start, $end, $allowFloats = false ) |
|
1492 | 1492 | { |
1493 | 1493 | $stringTokens = Tokens::$heredocTokens + Tokens::$stringTokens; |
1494 | 1494 | |
1495 | 1495 | $validTokens = array(); |
1496 | - $validTokens[\T_LNUMBER] = true; |
|
1497 | - $validTokens[\T_TRUE] = true; // Evaluates to int 1. |
|
1498 | - $validTokens[\T_FALSE] = true; // Evaluates to int 0. |
|
1499 | - $validTokens[\T_NULL] = true; // Evaluates to int 0. |
|
1496 | + $validTokens[ \T_LNUMBER ] = true; |
|
1497 | + $validTokens[ \T_TRUE ] = true; // Evaluates to int 1. |
|
1498 | + $validTokens[ \T_FALSE ] = true; // Evaluates to int 0. |
|
1499 | + $validTokens[ \T_NULL ] = true; // Evaluates to int 0. |
|
1500 | 1500 | |
1501 | - if ($allowFloats === true) { |
|
1502 | - $validTokens[\T_DNUMBER] = true; |
|
1501 | + if ( $allowFloats === true ) { |
|
1502 | + $validTokens[ \T_DNUMBER ] = true; |
|
1503 | 1503 | } |
1504 | 1504 | |
1505 | 1505 | $maybeValidTokens = $stringTokens + $validTokens; |
1506 | 1506 | |
1507 | 1507 | $tokens = $phpcsFile->getTokens(); |
1508 | - $searchEnd = ($end + 1); |
|
1508 | + $searchEnd = ( $end + 1 ); |
|
1509 | 1509 | $negativeNumber = false; |
1510 | 1510 | |
1511 | - if (isset($tokens[$start], $tokens[$searchEnd]) === false) { |
|
1511 | + if ( isset( $tokens[ $start ], $tokens[ $searchEnd ] ) === false ) { |
|
1512 | 1512 | return false; |
1513 | 1513 | } |
1514 | 1514 | |
1515 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, $start, $searchEnd, true); |
|
1516 | - while ($nextNonEmpty !== false |
|
1517 | - && ($tokens[$nextNonEmpty]['code'] === \T_PLUS |
|
1518 | - || $tokens[$nextNonEmpty]['code'] === \T_MINUS) |
|
1515 | + $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, $start, $searchEnd, true ); |
|
1516 | + while ( $nextNonEmpty !== false |
|
1517 | + && ( $tokens[ $nextNonEmpty ][ 'code' ] === \T_PLUS |
|
1518 | + || $tokens[ $nextNonEmpty ][ 'code' ] === \T_MINUS ) |
|
1519 | 1519 | ) { |
1520 | 1520 | |
1521 | - if ($tokens[$nextNonEmpty]['code'] === \T_MINUS) { |
|
1522 | - $negativeNumber = ($negativeNumber === false) ? true : false; |
|
1521 | + if ( $tokens[ $nextNonEmpty ][ 'code' ] === \T_MINUS ) { |
|
1522 | + $negativeNumber = ( $negativeNumber === false ) ? true : false; |
|
1523 | 1523 | } |
1524 | 1524 | |
1525 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextNonEmpty + 1), $searchEnd, true); |
|
1525 | + $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $nextNonEmpty + 1 ), $searchEnd, true ); |
|
1526 | 1526 | } |
1527 | 1527 | |
1528 | - if ($nextNonEmpty === false || isset($maybeValidTokens[$tokens[$nextNonEmpty]['code']]) === false) { |
|
1528 | + if ( $nextNonEmpty === false || isset( $maybeValidTokens[ $tokens[ $nextNonEmpty ][ 'code' ] ] ) === false ) { |
|
1529 | 1529 | return false; |
1530 | 1530 | } |
1531 | 1531 | |
1532 | 1532 | $content = false; |
1533 | - if ($tokens[$nextNonEmpty]['code'] === \T_LNUMBER |
|
1534 | - || $tokens[$nextNonEmpty]['code'] === \T_DNUMBER |
|
1533 | + if ( $tokens[ $nextNonEmpty ][ 'code' ] === \T_LNUMBER |
|
1534 | + || $tokens[ $nextNonEmpty ][ 'code' ] === \T_DNUMBER |
|
1535 | 1535 | ) { |
1536 | - $content = (float) $tokens[$nextNonEmpty]['content']; |
|
1537 | - } elseif ($tokens[$nextNonEmpty]['code'] === \T_TRUE) { |
|
1536 | + $content = (float)$tokens[ $nextNonEmpty ][ 'content' ]; |
|
1537 | + } elseif ( $tokens[ $nextNonEmpty ][ 'code' ] === \T_TRUE ) { |
|
1538 | 1538 | $content = 1.0; |
1539 | - } elseif ($tokens[$nextNonEmpty]['code'] === \T_FALSE |
|
1540 | - || $tokens[$nextNonEmpty]['code'] === \T_NULL |
|
1539 | + } elseif ( $tokens[ $nextNonEmpty ][ 'code' ] === \T_FALSE |
|
1540 | + || $tokens[ $nextNonEmpty ][ 'code' ] === \T_NULL |
|
1541 | 1541 | ) { |
1542 | 1542 | $content = 0.0; |
1543 | - } elseif (isset($stringTokens[$tokens[$nextNonEmpty]['code']]) === true) { |
|
1543 | + } elseif ( isset( $stringTokens[ $tokens[ $nextNonEmpty ][ 'code' ] ] ) === true ) { |
|
1544 | 1544 | |
1545 | - if ($tokens[$nextNonEmpty]['code'] === \T_START_HEREDOC |
|
1546 | - || $tokens[$nextNonEmpty]['code'] === \T_START_NOWDOC |
|
1545 | + if ( $tokens[ $nextNonEmpty ][ 'code' ] === \T_START_HEREDOC |
|
1546 | + || $tokens[ $nextNonEmpty ][ 'code' ] === \T_START_NOWDOC |
|
1547 | 1547 | ) { |
1548 | 1548 | // Skip past heredoc/nowdoc opener to the first content. |
1549 | - $firstDocToken = $phpcsFile->findNext(array(\T_HEREDOC, \T_NOWDOC), ($nextNonEmpty + 1), $searchEnd); |
|
1550 | - if ($firstDocToken === false) { |
|
1549 | + $firstDocToken = $phpcsFile->findNext( array( \T_HEREDOC, \T_NOWDOC ), ( $nextNonEmpty + 1 ), $searchEnd ); |
|
1550 | + if ( $firstDocToken === false ) { |
|
1551 | 1551 | // Live coding or parse error. |
1552 | 1552 | return false; |
1553 | 1553 | } |
1554 | 1554 | |
1555 | - $stringContent = $content = $tokens[$firstDocToken]['content']; |
|
1555 | + $stringContent = $content = $tokens[ $firstDocToken ][ 'content' ]; |
|
1556 | 1556 | |
1557 | 1557 | // Skip forward to the end in preparation for the next part of the examination. |
1558 | - $nextNonEmpty = $phpcsFile->findNext(array(\T_END_HEREDOC, \T_END_NOWDOC), ($nextNonEmpty + 1), $searchEnd); |
|
1559 | - if ($nextNonEmpty === false) { |
|
1558 | + $nextNonEmpty = $phpcsFile->findNext( array( \T_END_HEREDOC, \T_END_NOWDOC ), ( $nextNonEmpty + 1 ), $searchEnd ); |
|
1559 | + if ( $nextNonEmpty === false ) { |
|
1560 | 1560 | // Live coding or parse error. |
1561 | 1561 | return false; |
1562 | 1562 | } |
1563 | 1563 | } else { |
1564 | 1564 | // Gather subsequent lines for a multi-line string. |
1565 | - for ($i = $nextNonEmpty; $i < $searchEnd; $i++) { |
|
1566 | - if ($tokens[$i]['code'] !== $tokens[$nextNonEmpty]['code']) { |
|
1565 | + for ( $i = $nextNonEmpty; $i < $searchEnd; $i++ ) { |
|
1566 | + if ( $tokens[ $i ][ 'code' ] !== $tokens[ $nextNonEmpty ][ 'code' ] ) { |
|
1567 | 1567 | break; |
1568 | 1568 | } |
1569 | - $content .= $tokens[$i]['content']; |
|
1569 | + $content .= $tokens[ $i ][ 'content' ]; |
|
1570 | 1570 | } |
1571 | 1571 | |
1572 | 1572 | $nextNonEmpty = --$i; |
1573 | - $content = $this->stripQuotes($content); |
|
1573 | + $content = $this->stripQuotes( $content ); |
|
1574 | 1574 | $stringContent = $content; |
1575 | 1575 | } |
1576 | 1576 | |
@@ -1581,40 +1581,40 @@ discard block |
||
1581 | 1581 | $regexInt = '`^\s*[0-9]+`'; |
1582 | 1582 | $regexFloat = '`^\s*(?:[+-]?(?:(?:(?P<LNUM>[0-9]+)|(?P<DNUM>([0-9]*\.(?P>LNUM)|(?P>LNUM)\.[0-9]*)))[eE][+-]?(?P>LNUM))|(?P>DNUM))`'; |
1583 | 1583 | |
1584 | - $intString = preg_match($regexInt, $content, $intMatch); |
|
1585 | - $floatString = preg_match($regexFloat, $content, $floatMatch); |
|
1584 | + $intString = preg_match( $regexInt, $content, $intMatch ); |
|
1585 | + $floatString = preg_match( $regexFloat, $content, $floatMatch ); |
|
1586 | 1586 | |
1587 | 1587 | // Does the text string start with a number ? If so, PHP would juggle it and use it as a number. |
1588 | - if ($allowFloats === false) { |
|
1589 | - if ($intString !== 1 || $floatString === 1) { |
|
1590 | - if ($floatString === 1) { |
|
1588 | + if ( $allowFloats === false ) { |
|
1589 | + if ( $intString !== 1 || $floatString === 1 ) { |
|
1590 | + if ( $floatString === 1 ) { |
|
1591 | 1591 | // Found float. Only integers targetted. |
1592 | 1592 | return false; |
1593 | 1593 | } |
1594 | 1594 | |
1595 | 1595 | $content = 0.0; |
1596 | 1596 | } else { |
1597 | - $content = (float) trim($intMatch[0]); |
|
1597 | + $content = (float)trim( $intMatch[ 0 ] ); |
|
1598 | 1598 | } |
1599 | 1599 | } else { |
1600 | - if ($intString !== 1 && $floatString !== 1) { |
|
1600 | + if ( $intString !== 1 && $floatString !== 1 ) { |
|
1601 | 1601 | $content = 0.0; |
1602 | 1602 | } else { |
1603 | - $content = ($floatString === 1) ? (float) trim($floatMatch[0]) : (float) trim($intMatch[0]); |
|
1603 | + $content = ( $floatString === 1 ) ? (float)trim( $floatMatch[ 0 ] ) : (float)trim( $intMatch[ 0 ] ); |
|
1604 | 1604 | } |
1605 | 1605 | } |
1606 | 1606 | |
1607 | 1607 | // Allow for different behaviour for hex numeric strings between PHP 5 vs PHP 7. |
1608 | - if ($intString === 1 && trim($intMatch[0]) === '0' |
|
1609 | - && preg_match('`^\s*(0x[A-Fa-f0-9]+)`', $stringContent, $hexNumberString) === 1 |
|
1610 | - && $this->supportsBelow('5.6') === true |
|
1608 | + if ( $intString === 1 && trim( $intMatch[ 0 ] ) === '0' |
|
1609 | + && preg_match( '`^\s*(0x[A-Fa-f0-9]+)`', $stringContent, $hexNumberString ) === 1 |
|
1610 | + && $this->supportsBelow( '5.6' ) === true |
|
1611 | 1611 | ) { |
1612 | 1612 | // The filter extension still allows for hex numeric strings in PHP 7, so |
1613 | 1613 | // use that to get the numeric value if possible. |
1614 | 1614 | // If the filter extension is not available, the value will be zero, but so be it. |
1615 | - if (function_exists('filter_var')) { |
|
1616 | - $filtered = filter_var($hexNumberString[1], \FILTER_VALIDATE_INT, \FILTER_FLAG_ALLOW_HEX); |
|
1617 | - if ($filtered !== false) { |
|
1615 | + if ( function_exists( 'filter_var' ) ) { |
|
1616 | + $filtered = filter_var( $hexNumberString[ 1 ], \FILTER_VALIDATE_INT, \FILTER_FLAG_ALLOW_HEX ); |
|
1617 | + if ( $filtered !== false ) { |
|
1618 | 1618 | $content = $filtered; |
1619 | 1619 | } |
1620 | 1620 | } |
@@ -1622,17 +1622,17 @@ discard block |
||
1622 | 1622 | } |
1623 | 1623 | |
1624 | 1624 | // OK, so we have a number, now is there still more code after it ? |
1625 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextNonEmpty + 1), $searchEnd, true); |
|
1626 | - if ($nextNonEmpty !== false) { |
|
1625 | + $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $nextNonEmpty + 1 ), $searchEnd, true ); |
|
1626 | + if ( $nextNonEmpty !== false ) { |
|
1627 | 1627 | return false; |
1628 | 1628 | } |
1629 | 1629 | |
1630 | - if ($negativeNumber === true) { |
|
1630 | + if ( $negativeNumber === true ) { |
|
1631 | 1631 | $content = -$content; |
1632 | 1632 | } |
1633 | 1633 | |
1634 | - if ($allowFloats === false) { |
|
1635 | - return (int) $content; |
|
1634 | + if ( $allowFloats === false ) { |
|
1635 | + return (int)$content; |
|
1636 | 1636 | } |
1637 | 1637 | |
1638 | 1638 | return $content; |
@@ -1656,66 +1656,66 @@ discard block |
||
1656 | 1656 | * |
1657 | 1657 | * @return bool |
1658 | 1658 | */ |
1659 | - protected function isNumericCalculation(File $phpcsFile, $start, $end) |
|
1659 | + protected function isNumericCalculation( File $phpcsFile, $start, $end ) |
|
1660 | 1660 | { |
1661 | 1661 | $arithmeticTokens = Tokens::$arithmeticTokens; |
1662 | 1662 | |
1663 | 1663 | // phpcs:disable PHPCompatibility.Constants.NewConstants.t_powFound |
1664 | - if (\defined('T_POW') && isset($arithmeticTokens[\T_POW]) === false) { |
|
1664 | + if ( \defined( 'T_POW' ) && isset( $arithmeticTokens[ \T_POW ] ) === false ) { |
|
1665 | 1665 | // T_POW was not added to the arithmetic array until PHPCS 2.9.0. |
1666 | - $arithmeticTokens[\T_POW] = \T_POW; |
|
1666 | + $arithmeticTokens[ \T_POW ] = \T_POW; |
|
1667 | 1667 | } |
1668 | 1668 | // phpcs:enable |
1669 | 1669 | |
1670 | 1670 | $skipTokens = Tokens::$emptyTokens; |
1671 | - $skipTokens[] = \T_MINUS; |
|
1672 | - $skipTokens[] = \T_PLUS; |
|
1671 | + $skipTokens[ ] = \T_MINUS; |
|
1672 | + $skipTokens[ ] = \T_PLUS; |
|
1673 | 1673 | |
1674 | 1674 | // Find the first arithmetic operator, but skip past +/- signs before numbers. |
1675 | - $nextNonEmpty = ($start - 1); |
|
1675 | + $nextNonEmpty = ( $start - 1 ); |
|
1676 | 1676 | do { |
1677 | - $nextNonEmpty = $phpcsFile->findNext($skipTokens, ($nextNonEmpty + 1), ($end + 1), true); |
|
1678 | - $arithmeticOperator = $phpcsFile->findNext($arithmeticTokens, ($nextNonEmpty + 1), ($end + 1)); |
|
1679 | - } while ($nextNonEmpty !== false && $arithmeticOperator !== false && $nextNonEmpty === $arithmeticOperator); |
|
1677 | + $nextNonEmpty = $phpcsFile->findNext( $skipTokens, ( $nextNonEmpty + 1 ), ( $end + 1 ), true ); |
|
1678 | + $arithmeticOperator = $phpcsFile->findNext( $arithmeticTokens, ( $nextNonEmpty + 1 ), ( $end + 1 ) ); |
|
1679 | + } while ( $nextNonEmpty !== false && $arithmeticOperator !== false && $nextNonEmpty === $arithmeticOperator ); |
|
1680 | 1680 | |
1681 | - if ($arithmeticOperator === false) { |
|
1681 | + if ( $arithmeticOperator === false ) { |
|
1682 | 1682 | return false; |
1683 | 1683 | } |
1684 | 1684 | |
1685 | 1685 | $tokens = $phpcsFile->getTokens(); |
1686 | 1686 | $subsetStart = $start; |
1687 | - $subsetEnd = ($arithmeticOperator - 1); |
|
1687 | + $subsetEnd = ( $arithmeticOperator - 1 ); |
|
1688 | 1688 | |
1689 | - while ($this->isNumber($phpcsFile, $subsetStart, $subsetEnd, true) !== false |
|
1690 | - && isset($tokens[($arithmeticOperator + 1)]) === true |
|
1689 | + while ( $this->isNumber( $phpcsFile, $subsetStart, $subsetEnd, true ) !== false |
|
1690 | + && isset( $tokens[ ( $arithmeticOperator + 1 ) ] ) === true |
|
1691 | 1691 | ) { |
1692 | 1692 | // Recognize T_POW for PHPCS < 2.4.0 on low PHP versions. |
1693 | - if (\defined('T_POW') === false |
|
1694 | - && $tokens[$arithmeticOperator]['code'] === \T_MULTIPLY |
|
1695 | - && $tokens[($arithmeticOperator + 1)]['code'] === \T_MULTIPLY |
|
1696 | - && isset($tokens[$arithmeticOperator + 2]) === true |
|
1693 | + if ( \defined( 'T_POW' ) === false |
|
1694 | + && $tokens[ $arithmeticOperator ][ 'code' ] === \T_MULTIPLY |
|
1695 | + && $tokens[ ( $arithmeticOperator + 1 ) ][ 'code' ] === \T_MULTIPLY |
|
1696 | + && isset( $tokens[ $arithmeticOperator + 2 ] ) === true |
|
1697 | 1697 | ) { |
1698 | 1698 | // Move operator one forward to the second * in T_POW. |
1699 | 1699 | ++$arithmeticOperator; |
1700 | 1700 | } |
1701 | 1701 | |
1702 | - $subsetStart = ($arithmeticOperator + 1); |
|
1702 | + $subsetStart = ( $arithmeticOperator + 1 ); |
|
1703 | 1703 | $nextNonEmpty = $arithmeticOperator; |
1704 | 1704 | do { |
1705 | - $nextNonEmpty = $phpcsFile->findNext($skipTokens, ($nextNonEmpty + 1), ($end + 1), true); |
|
1706 | - $arithmeticOperator = $phpcsFile->findNext($arithmeticTokens, ($nextNonEmpty + 1), ($end + 1)); |
|
1707 | - } while ($nextNonEmpty !== false && $arithmeticOperator !== false && $nextNonEmpty === $arithmeticOperator); |
|
1705 | + $nextNonEmpty = $phpcsFile->findNext( $skipTokens, ( $nextNonEmpty + 1 ), ( $end + 1 ), true ); |
|
1706 | + $arithmeticOperator = $phpcsFile->findNext( $arithmeticTokens, ( $nextNonEmpty + 1 ), ( $end + 1 ) ); |
|
1707 | + } while ( $nextNonEmpty !== false && $arithmeticOperator !== false && $nextNonEmpty === $arithmeticOperator ); |
|
1708 | 1708 | |
1709 | - if ($arithmeticOperator === false) { |
|
1709 | + if ( $arithmeticOperator === false ) { |
|
1710 | 1710 | // Last calculation operator already reached. |
1711 | - if ($this->isNumber($phpcsFile, $subsetStart, $end, true) !== false) { |
|
1711 | + if ( $this->isNumber( $phpcsFile, $subsetStart, $end, true ) !== false ) { |
|
1712 | 1712 | return true; |
1713 | 1713 | } |
1714 | 1714 | |
1715 | 1715 | return false; |
1716 | 1716 | } |
1717 | 1717 | |
1718 | - $subsetEnd = ($arithmeticOperator - 1); |
|
1718 | + $subsetEnd = ( $arithmeticOperator - 1 ); |
|
1719 | 1719 | } |
1720 | 1720 | |
1721 | 1721 | return false; |
@@ -1741,22 +1741,22 @@ discard block |
||
1741 | 1741 | * |
1742 | 1742 | * @return bool True if short ternary, or false otherwise. |
1743 | 1743 | */ |
1744 | - public function isShortTernary(File $phpcsFile, $stackPtr) |
|
1744 | + public function isShortTernary( File $phpcsFile, $stackPtr ) |
|
1745 | 1745 | { |
1746 | 1746 | $tokens = $phpcsFile->getTokens(); |
1747 | - if (isset($tokens[$stackPtr]) === false |
|
1748 | - || $tokens[$stackPtr]['code'] !== \T_INLINE_THEN |
|
1747 | + if ( isset( $tokens[ $stackPtr ] ) === false |
|
1748 | + || $tokens[ $stackPtr ][ 'code' ] !== \T_INLINE_THEN |
|
1749 | 1749 | ) { |
1750 | 1750 | return false; |
1751 | 1751 | } |
1752 | 1752 | |
1753 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); |
|
1754 | - if ($nextNonEmpty === false) { |
|
1753 | + $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); |
|
1754 | + if ( $nextNonEmpty === false ) { |
|
1755 | 1755 | // Live coding or parse error. |
1756 | 1756 | return false; |
1757 | 1757 | } |
1758 | 1758 | |
1759 | - if ($tokens[$nextNonEmpty]['code'] === \T_INLINE_ELSE) { |
|
1759 | + if ( $tokens[ $nextNonEmpty ][ 'code' ] === \T_INLINE_ELSE ) { |
|
1760 | 1760 | return true; |
1761 | 1761 | } |
1762 | 1762 | |
@@ -1775,39 +1775,39 @@ discard block |
||
1775 | 1775 | * |
1776 | 1776 | * @return bool |
1777 | 1777 | */ |
1778 | - public function isShortList(File $phpcsFile, $stackPtr) |
|
1778 | + public function isShortList( File $phpcsFile, $stackPtr ) |
|
1779 | 1779 | { |
1780 | 1780 | $tokens = $phpcsFile->getTokens(); |
1781 | 1781 | |
1782 | 1782 | // Check for the existence of the token. |
1783 | - if (isset($tokens[$stackPtr]) === false) { |
|
1783 | + if ( isset( $tokens[ $stackPtr ] ) === false ) { |
|
1784 | 1784 | return false; |
1785 | 1785 | } |
1786 | 1786 | |
1787 | 1787 | // Is this one of the tokens this function handles ? |
1788 | - if ($tokens[$stackPtr]['code'] !== \T_OPEN_SHORT_ARRAY |
|
1789 | - && $tokens[$stackPtr]['code'] !== \T_CLOSE_SHORT_ARRAY |
|
1788 | + if ( $tokens[ $stackPtr ][ 'code' ] !== \T_OPEN_SHORT_ARRAY |
|
1789 | + && $tokens[ $stackPtr ][ 'code' ] !== \T_CLOSE_SHORT_ARRAY |
|
1790 | 1790 | ) { |
1791 | 1791 | return false; |
1792 | 1792 | } |
1793 | 1793 | |
1794 | - switch ($tokens[$stackPtr]['code']) { |
|
1794 | + switch ( $tokens[ $stackPtr ][ 'code' ] ) { |
|
1795 | 1795 | case \T_OPEN_SHORT_ARRAY: |
1796 | - if (isset($tokens[$stackPtr]['bracket_closer']) === true) { |
|
1796 | + if ( isset( $tokens[ $stackPtr ][ 'bracket_closer' ] ) === true ) { |
|
1797 | 1797 | $opener = $stackPtr; |
1798 | - $closer = $tokens[$stackPtr]['bracket_closer']; |
|
1798 | + $closer = $tokens[ $stackPtr ][ 'bracket_closer' ]; |
|
1799 | 1799 | } |
1800 | 1800 | break; |
1801 | 1801 | |
1802 | 1802 | case \T_CLOSE_SHORT_ARRAY: |
1803 | - if (isset($tokens[$stackPtr]['bracket_opener']) === true) { |
|
1804 | - $opener = $tokens[$stackPtr]['bracket_opener']; |
|
1803 | + if ( isset( $tokens[ $stackPtr ][ 'bracket_opener' ] ) === true ) { |
|
1804 | + $opener = $tokens[ $stackPtr ][ 'bracket_opener' ]; |
|
1805 | 1805 | $closer = $stackPtr; |
1806 | 1806 | } |
1807 | 1807 | break; |
1808 | 1808 | } |
1809 | 1809 | |
1810 | - if (isset($opener, $closer) === false) { |
|
1810 | + if ( isset( $opener, $closer ) === false ) { |
|
1811 | 1811 | // Parse error, live coding or real square bracket. |
1812 | 1812 | return false; |
1813 | 1813 | } |
@@ -1816,42 +1816,42 @@ discard block |
||
1816 | 1816 | * PHPCS cross-version compatibility: work around for square brackets misidentified |
1817 | 1817 | * as short array when preceded by a variable variable in older PHPCS versions. |
1818 | 1818 | */ |
1819 | - $prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($opener - 1), null, true, null, true); |
|
1819 | + $prevNonEmpty = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $opener - 1 ), null, true, null, true ); |
|
1820 | 1820 | |
1821 | - if ($prevNonEmpty !== false |
|
1822 | - && $tokens[$prevNonEmpty]['code'] === \T_CLOSE_CURLY_BRACKET |
|
1823 | - && isset($tokens[$prevNonEmpty]['bracket_opener']) === true |
|
1821 | + if ( $prevNonEmpty !== false |
|
1822 | + && $tokens[ $prevNonEmpty ][ 'code' ] === \T_CLOSE_CURLY_BRACKET |
|
1823 | + && isset( $tokens[ $prevNonEmpty ][ 'bracket_opener' ] ) === true |
|
1824 | 1824 | ) { |
1825 | 1825 | $maybeVariableVariable = $phpcsFile->findPrevious( |
1826 | 1826 | Tokens::$emptyTokens, |
1827 | - ($tokens[$prevNonEmpty]['bracket_opener'] - 1), |
|
1827 | + ( $tokens[ $prevNonEmpty ][ 'bracket_opener' ] - 1 ), |
|
1828 | 1828 | null, |
1829 | 1829 | true, |
1830 | 1830 | null, |
1831 | 1831 | true |
1832 | 1832 | ); |
1833 | 1833 | |
1834 | - if ($tokens[$maybeVariableVariable]['code'] === \T_VARIABLE |
|
1835 | - || $tokens[$maybeVariableVariable]['code'] === \T_DOLLAR |
|
1834 | + if ( $tokens[ $maybeVariableVariable ][ 'code' ] === \T_VARIABLE |
|
1835 | + || $tokens[ $maybeVariableVariable ][ 'code' ] === \T_DOLLAR |
|
1836 | 1836 | ) { |
1837 | 1837 | return false; |
1838 | 1838 | } |
1839 | 1839 | } |
1840 | 1840 | |
1841 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($closer + 1), null, true, null, true); |
|
1841 | + $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $closer + 1 ), null, true, null, true ); |
|
1842 | 1842 | |
1843 | - if ($nextNonEmpty !== false && $tokens[$nextNonEmpty]['code'] === \T_EQUAL) { |
|
1843 | + if ( $nextNonEmpty !== false && $tokens[ $nextNonEmpty ][ 'code' ] === \T_EQUAL ) { |
|
1844 | 1844 | return true; |
1845 | 1845 | } |
1846 | 1846 | |
1847 | - if ($prevNonEmpty !== false |
|
1848 | - && $tokens[$prevNonEmpty]['code'] === \T_AS |
|
1849 | - && isset($tokens[$prevNonEmpty]['nested_parenthesis']) === true |
|
1847 | + if ( $prevNonEmpty !== false |
|
1848 | + && $tokens[ $prevNonEmpty ][ 'code' ] === \T_AS |
|
1849 | + && isset( $tokens[ $prevNonEmpty ][ 'nested_parenthesis' ] ) === true |
|
1850 | 1850 | ) { |
1851 | - $parentheses = array_reverse($tokens[$prevNonEmpty]['nested_parenthesis'], true); |
|
1852 | - foreach ($parentheses as $open => $close) { |
|
1853 | - if (isset($tokens[$open]['parenthesis_owner']) |
|
1854 | - && $tokens[$tokens[$open]['parenthesis_owner']]['code'] === \T_FOREACH |
|
1851 | + $parentheses = array_reverse( $tokens[ $prevNonEmpty ][ 'nested_parenthesis' ], true ); |
|
1852 | + foreach ( $parentheses as $open => $close ) { |
|
1853 | + if ( isset( $tokens[ $open ][ 'parenthesis_owner' ] ) |
|
1854 | + && $tokens[ $tokens[ $open ][ 'parenthesis_owner' ] ][ 'code' ] === \T_FOREACH |
|
1855 | 1855 | ) { |
1856 | 1856 | return true; |
1857 | 1857 | } |
@@ -1862,48 +1862,48 @@ discard block |
||
1862 | 1862 | $parentOpener = $opener; |
1863 | 1863 | do { |
1864 | 1864 | $parentOpener = $phpcsFile->findPrevious( |
1865 | - array(\T_OPEN_SHORT_ARRAY, \T_OPEN_SQUARE_BRACKET), |
|
1866 | - ($parentOpener - 1), |
|
1865 | + array( \T_OPEN_SHORT_ARRAY, \T_OPEN_SQUARE_BRACKET ), |
|
1866 | + ( $parentOpener - 1 ), |
|
1867 | 1867 | null, |
1868 | 1868 | false, |
1869 | 1869 | null, |
1870 | 1870 | true |
1871 | 1871 | ); |
1872 | 1872 | |
1873 | - if ($parentOpener === false) { |
|
1873 | + if ( $parentOpener === false ) { |
|
1874 | 1874 | return false; |
1875 | 1875 | } |
1876 | 1876 | |
1877 | - } while (isset($tokens[$parentOpener]['bracket_closer']) === true |
|
1878 | - && $tokens[$parentOpener]['bracket_closer'] < $opener |
|
1877 | + } while ( isset( $tokens[ $parentOpener ][ 'bracket_closer' ] ) === true |
|
1878 | + && $tokens[ $parentOpener ][ 'bracket_closer' ] < $opener |
|
1879 | 1879 | ); |
1880 | 1880 | |
1881 | - if (isset($tokens[$parentOpener]['bracket_closer']) === true |
|
1882 | - && $tokens[$parentOpener]['bracket_closer'] > $closer |
|
1881 | + if ( isset( $tokens[ $parentOpener ][ 'bracket_closer' ] ) === true |
|
1882 | + && $tokens[ $parentOpener ][ 'bracket_closer' ] > $closer |
|
1883 | 1883 | ) { |
1884 | 1884 | // Work around tokenizer issue in PHPCS 2.0 - 2.7. |
1885 | 1885 | $phpcsVersion = PHPCSHelper::getVersion(); |
1886 | - if ((version_compare($phpcsVersion, '2.0', '>') === true |
|
1887 | - && version_compare($phpcsVersion, '2.8', '<') === true) |
|
1888 | - && $tokens[$parentOpener]['code'] === \T_OPEN_SQUARE_BRACKET |
|
1886 | + if ( ( version_compare( $phpcsVersion, '2.0', '>' ) === true |
|
1887 | + && version_compare( $phpcsVersion, '2.8', '<' ) === true ) |
|
1888 | + && $tokens[ $parentOpener ][ 'code' ] === \T_OPEN_SQUARE_BRACKET |
|
1889 | 1889 | ) { |
1890 | 1890 | $nextNonEmpty = $phpcsFile->findNext( |
1891 | 1891 | Tokens::$emptyTokens, |
1892 | - ($tokens[$parentOpener]['bracket_closer'] + 1), |
|
1892 | + ( $tokens[ $parentOpener ][ 'bracket_closer' ] + 1 ), |
|
1893 | 1893 | null, |
1894 | 1894 | true, |
1895 | 1895 | null, |
1896 | 1896 | true |
1897 | 1897 | ); |
1898 | 1898 | |
1899 | - if ($nextNonEmpty !== false && $tokens[$nextNonEmpty]['code'] === \T_EQUAL) { |
|
1899 | + if ( $nextNonEmpty !== false && $tokens[ $nextNonEmpty ][ 'code' ] === \T_EQUAL ) { |
|
1900 | 1900 | return true; |
1901 | 1901 | } |
1902 | 1902 | |
1903 | 1903 | return false; |
1904 | 1904 | } |
1905 | 1905 | |
1906 | - return $this->isShortList($phpcsFile, $parentOpener); |
|
1906 | + return $this->isShortList( $phpcsFile, $parentOpener ); |
|
1907 | 1907 | } |
1908 | 1908 | |
1909 | 1909 | return false; |
@@ -1922,14 +1922,14 @@ discard block |
||
1922 | 1922 | * |
1923 | 1923 | * @return bool |
1924 | 1924 | */ |
1925 | - public function isVariable(File $phpcsFile, $start, $end, $targetNestingLevel) |
|
1925 | + public function isVariable( File $phpcsFile, $start, $end, $targetNestingLevel ) |
|
1926 | 1926 | { |
1927 | 1927 | static $tokenBlackList, $bracketTokens; |
1928 | 1928 | |
1929 | 1929 | // Create the token arrays only once. |
1930 | - if (isset($tokenBlackList, $bracketTokens) === false) { |
|
1930 | + if ( isset( $tokenBlackList, $bracketTokens ) === false ) { |
|
1931 | 1931 | |
1932 | - $tokenBlackList = array( |
|
1932 | + $tokenBlackList = array( |
|
1933 | 1933 | \T_OPEN_PARENTHESIS => \T_OPEN_PARENTHESIS, |
1934 | 1934 | \T_STRING_CONCAT => \T_STRING_CONCAT, |
1935 | 1935 | ); |
@@ -1954,43 +1954,43 @@ discard block |
||
1954 | 1954 | $tokens = $phpcsFile->getTokens(); |
1955 | 1955 | |
1956 | 1956 | // If no variable at all was found, then it's definitely a no-no. |
1957 | - $hasVariable = $phpcsFile->findNext(\T_VARIABLE, $start, $end); |
|
1958 | - if ($hasVariable === false) { |
|
1957 | + $hasVariable = $phpcsFile->findNext( \T_VARIABLE, $start, $end ); |
|
1958 | + if ( $hasVariable === false ) { |
|
1959 | 1959 | return false; |
1960 | 1960 | } |
1961 | 1961 | |
1962 | 1962 | // Check if the variable found is at the right level. Deeper levels are always an error. |
1963 | - if (isset($tokens[$hasVariable]['nested_parenthesis']) |
|
1964 | - && \count($tokens[$hasVariable]['nested_parenthesis']) !== $targetNestingLevel |
|
1963 | + if ( isset( $tokens[ $hasVariable ][ 'nested_parenthesis' ] ) |
|
1964 | + && \count( $tokens[ $hasVariable ][ 'nested_parenthesis' ] ) !== $targetNestingLevel |
|
1965 | 1965 | ) { |
1966 | 1966 | return false; |
1967 | 1967 | } |
1968 | 1968 | |
1969 | 1969 | // Ok, so the first variable is at the right level, now are there any |
1970 | 1970 | // blacklisted tokens within the empty() ? |
1971 | - $hasBadToken = $phpcsFile->findNext($tokenBlackList, $start, $end); |
|
1972 | - if ($hasBadToken === false) { |
|
1971 | + $hasBadToken = $phpcsFile->findNext( $tokenBlackList, $start, $end ); |
|
1972 | + if ( $hasBadToken === false ) { |
|
1973 | 1973 | return true; |
1974 | 1974 | } |
1975 | 1975 | |
1976 | 1976 | // If there are also bracket tokens, the blacklisted token might be part of a variable |
1977 | 1977 | // variable, but if there are no bracket tokens, we know we have an error. |
1978 | - $hasBrackets = $phpcsFile->findNext($bracketTokens, $start, $end); |
|
1979 | - if ($hasBrackets === false) { |
|
1978 | + $hasBrackets = $phpcsFile->findNext( $bracketTokens, $start, $end ); |
|
1979 | + if ( $hasBrackets === false ) { |
|
1980 | 1980 | return false; |
1981 | 1981 | } |
1982 | 1982 | |
1983 | 1983 | // Ok, we have both a blacklisted token as well as brackets, so we need to walk |
1984 | 1984 | // the tokens of the variable variable. |
1985 | - for ($i = $start; $i < $end; $i++) { |
|
1985 | + for ( $i = $start; $i < $end; $i++ ) { |
|
1986 | 1986 | // If this is a bracket token, skip to the end of the bracketed expression. |
1987 | - if (isset($bracketTokens[$tokens[$i]['code']], $tokens[$i]['bracket_closer'])) { |
|
1988 | - $i = $tokens[$i]['bracket_closer']; |
|
1987 | + if ( isset( $bracketTokens[ $tokens[ $i ][ 'code' ] ], $tokens[ $i ][ 'bracket_closer' ] ) ) { |
|
1988 | + $i = $tokens[ $i ][ 'bracket_closer' ]; |
|
1989 | 1989 | continue; |
1990 | 1990 | } |
1991 | 1991 | |
1992 | 1992 | // If it's a blacklisted token, not within brackets, we have an error. |
1993 | - if (isset($tokenBlackList[$tokens[$i]['code']])) { |
|
1993 | + if ( isset( $tokenBlackList[ $tokens[ $i ][ 'code' ] ] ) ) { |
|
1994 | 1994 | return false; |
1995 | 1995 | } |
1996 | 1996 | } |
@@ -2016,56 +2016,56 @@ discard block |
||
2016 | 2016 | * @return bool True if the token passed is a unary operator. |
2017 | 2017 | * False otherwise or if the token is not a T_PLUS/T_MINUS token. |
2018 | 2018 | */ |
2019 | - public static function isUnaryPlusMinus(File $phpcsFile, $stackPtr) |
|
2019 | + public static function isUnaryPlusMinus( File $phpcsFile, $stackPtr ) |
|
2020 | 2020 | { |
2021 | 2021 | $tokens = $phpcsFile->getTokens(); |
2022 | 2022 | |
2023 | - if (isset($tokens[$stackPtr]) === false |
|
2024 | - || ($tokens[$stackPtr]['code'] !== \T_PLUS |
|
2025 | - && $tokens[$stackPtr]['code'] !== \T_MINUS) |
|
2023 | + if ( isset( $tokens[ $stackPtr ] ) === false |
|
2024 | + || ( $tokens[ $stackPtr ][ 'code' ] !== \T_PLUS |
|
2025 | + && $tokens[ $stackPtr ][ 'code' ] !== \T_MINUS ) |
|
2026 | 2026 | ) { |
2027 | 2027 | return false; |
2028 | 2028 | } |
2029 | 2029 | |
2030 | - $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); |
|
2031 | - if ($next === false) { |
|
2030 | + $next = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); |
|
2031 | + if ( $next === false ) { |
|
2032 | 2032 | // Live coding or parse error. |
2033 | 2033 | return false; |
2034 | 2034 | } |
2035 | 2035 | |
2036 | - if (isset(Tokens::$operators[$tokens[$next]['code']]) === true) { |
|
2036 | + if ( isset( Tokens::$operators[ $tokens[ $next ][ 'code' ] ] ) === true ) { |
|
2037 | 2037 | // Next token is an operator, so this is not a unary. |
2038 | 2038 | return false; |
2039 | 2039 | } |
2040 | 2040 | |
2041 | - $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
|
2041 | + $prev = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $stackPtr - 1 ), null, true ); |
|
2042 | 2042 | |
2043 | - if ($tokens[$prev]['code'] === \T_RETURN) { |
|
2043 | + if ( $tokens[ $prev ][ 'code' ] === \T_RETURN ) { |
|
2044 | 2044 | // Just returning a positive/negative value; eg. (return -1). |
2045 | 2045 | return true; |
2046 | 2046 | } |
2047 | 2047 | |
2048 | - if (isset(Tokens::$operators[$tokens[$prev]['code']]) === true) { |
|
2048 | + if ( isset( Tokens::$operators[ $tokens[ $prev ][ 'code' ] ] ) === true ) { |
|
2049 | 2049 | // Just trying to operate on a positive/negative value; eg. ($var * -1). |
2050 | 2050 | return true; |
2051 | 2051 | } |
2052 | 2052 | |
2053 | - if (isset(Tokens::$comparisonTokens[$tokens[$prev]['code']]) === true) { |
|
2053 | + if ( isset( Tokens::$comparisonTokens[ $tokens[ $prev ][ 'code' ] ] ) === true ) { |
|
2054 | 2054 | // Just trying to compare a positive/negative value; eg. ($var === -1). |
2055 | 2055 | return true; |
2056 | 2056 | } |
2057 | 2057 | |
2058 | - if (isset(Tokens::$booleanOperators[$tokens[$prev]['code']]) === true) { |
|
2058 | + if ( isset( Tokens::$booleanOperators[ $tokens[ $prev ][ 'code' ] ] ) === true ) { |
|
2059 | 2059 | // Just trying to compare a positive/negative value; eg. ($var || -1 === $b). |
2060 | 2060 | return true; |
2061 | 2061 | } |
2062 | 2062 | |
2063 | - if (isset(Tokens::$assignmentTokens[$tokens[$prev]['code']]) === true) { |
|
2063 | + if ( isset( Tokens::$assignmentTokens[ $tokens[ $prev ][ 'code' ] ] ) === true ) { |
|
2064 | 2064 | // Just trying to assign a positive/negative value; eg. ($var = -1). |
2065 | 2065 | return true; |
2066 | 2066 | } |
2067 | 2067 | |
2068 | - if (isset(Tokens::$castTokens[$tokens[$prev]['code']]) === true) { |
|
2068 | + if ( isset( Tokens::$castTokens[ $tokens[ $prev ][ 'code' ] ] ) === true ) { |
|
2069 | 2069 | // Just casting a positive/negative value; eg. (string) -$var. |
2070 | 2070 | return true; |
2071 | 2071 | } |
@@ -2084,7 +2084,7 @@ discard block |
||
2084 | 2084 | \T_STRING_CONCAT => true, |
2085 | 2085 | ); |
2086 | 2086 | |
2087 | - if (isset($invalidTokens[$tokens[$prev]['code']]) === true) { |
|
2087 | + if ( isset( $invalidTokens[ $tokens[ $prev ][ 'code' ] ] ) === true ) { |
|
2088 | 2088 | // Just trying to use a positive/negative value; eg. myFunction($var, -2). |
2089 | 2089 | return true; |
2090 | 2090 | } |
@@ -33,13 +33,13 @@ discard block |
||
33 | 33 | * |
34 | 34 | * @return void |
35 | 35 | */ |
36 | - public function handleFeature(File $phpcsFile, $stackPtr, array $itemInfo) |
|
36 | + public function handleFeature( File $phpcsFile, $stackPtr, array $itemInfo ) |
|
37 | 37 | { |
38 | - $itemArray = $this->getItemArray($itemInfo); |
|
39 | - $errorInfo = $this->getErrorInfo($itemArray, $itemInfo); |
|
38 | + $itemArray = $this->getItemArray( $itemInfo ); |
|
39 | + $errorInfo = $this->getErrorInfo( $itemArray, $itemInfo ); |
|
40 | 40 | |
41 | - if ($this->shouldThrowError($errorInfo) === true) { |
|
42 | - $this->addError($phpcsFile, $stackPtr, $itemInfo, $errorInfo); |
|
41 | + if ( $this->shouldThrowError( $errorInfo ) === true ) { |
|
42 | + $this->addError( $phpcsFile, $stackPtr, $itemInfo, $errorInfo ); |
|
43 | 43 | } |
44 | 44 | } |
45 | 45 | |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | * |
52 | 52 | * @return bool |
53 | 53 | */ |
54 | - abstract protected function shouldThrowError(array $errorInfo); |
|
54 | + abstract protected function shouldThrowError( array $errorInfo ); |
|
55 | 55 | |
56 | 56 | |
57 | 57 | /** |
@@ -73,9 +73,9 @@ discard block |
||
73 | 73 | * |
74 | 74 | * @return array Array with only the version information. |
75 | 75 | */ |
76 | - protected function getVersionArray(array $itemArray) |
|
76 | + protected function getVersionArray( array $itemArray ) |
|
77 | 77 | { |
78 | - return array_diff_key($itemArray, array_flip($this->getNonVersionArrayKeys())); |
|
78 | + return array_diff_key( $itemArray, array_flip( $this->getNonVersionArrayKeys() ) ); |
|
79 | 79 | } |
80 | 80 | |
81 | 81 | |
@@ -87,9 +87,9 @@ discard block |
||
87 | 87 | * |
88 | 88 | * @return string |
89 | 89 | */ |
90 | - protected function getItemName(array $itemInfo, array $errorInfo) |
|
90 | + protected function getItemName( array $itemInfo, array $errorInfo ) |
|
91 | 91 | { |
92 | - return $itemInfo['name']; |
|
92 | + return $itemInfo[ 'name' ]; |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * |
111 | 111 | * @return string |
112 | 112 | */ |
113 | - protected function filterErrorMsg($error, array $itemInfo, array $errorInfo) |
|
113 | + protected function filterErrorMsg( $error, array $itemInfo, array $errorInfo ) |
|
114 | 114 | { |
115 | 115 | return $error; |
116 | 116 | } |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | * |
126 | 126 | * @return array |
127 | 127 | */ |
128 | - protected function filterErrorData(array $data, array $itemInfo, array $errorInfo) |
|
128 | + protected function filterErrorData( array $data, array $itemInfo, array $errorInfo ) |
|
129 | 129 | { |
130 | 130 | return $data; |
131 | 131 | } |
@@ -29,9 +29,9 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @return bool |
31 | 31 | */ |
32 | - protected function shouldThrowError(array $errorInfo) |
|
32 | + protected function shouldThrowError( array $errorInfo ) |
|
33 | 33 | { |
34 | - return ($errorInfo['not_in_version'] !== ''); |
|
34 | + return ( $errorInfo[ 'not_in_version' ] !== '' ); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | |
@@ -43,21 +43,21 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @return array |
45 | 45 | */ |
46 | - public function getErrorInfo(array $itemArray, array $itemInfo) |
|
46 | + public function getErrorInfo( array $itemArray, array $itemInfo ) |
|
47 | 47 | { |
48 | 48 | $errorInfo = array( |
49 | 49 | 'not_in_version' => '', |
50 | 50 | 'error' => true, |
51 | 51 | ); |
52 | 52 | |
53 | - $versionArray = $this->getVersionArray($itemArray); |
|
53 | + $versionArray = $this->getVersionArray( $itemArray ); |
|
54 | 54 | |
55 | - if (empty($versionArray) === false) { |
|
56 | - foreach ($versionArray as $version => $present) { |
|
57 | - if ($errorInfo['not_in_version'] === '' && $present === false |
|
58 | - && $this->supportsBelow($version) === true |
|
55 | + if ( empty( $versionArray ) === false ) { |
|
56 | + foreach ( $versionArray as $version => $present ) { |
|
57 | + if ( $errorInfo[ 'not_in_version' ] === '' && $present === false |
|
58 | + && $this->supportsBelow( $version ) === true |
|
59 | 59 | ) { |
60 | - $errorInfo['not_in_version'] = $version; |
|
60 | + $errorInfo[ 'not_in_version' ] = $version; |
|
61 | 61 | } |
62 | 62 | } |
63 | 63 | } |
@@ -89,20 +89,20 @@ discard block |
||
89 | 89 | * |
90 | 90 | * @return void |
91 | 91 | */ |
92 | - public function addError(File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo) |
|
92 | + public function addError( File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo ) |
|
93 | 93 | { |
94 | - $itemName = $this->getItemName($itemInfo, $errorInfo); |
|
94 | + $itemName = $this->getItemName( $itemInfo, $errorInfo ); |
|
95 | 95 | $error = $this->getErrorMsgTemplate(); |
96 | 96 | |
97 | - $errorCode = $this->stringToErrorCode($itemName) . 'Found'; |
|
97 | + $errorCode = $this->stringToErrorCode( $itemName ) . 'Found'; |
|
98 | 98 | $data = array( |
99 | 99 | $itemName, |
100 | - $errorInfo['not_in_version'], |
|
100 | + $errorInfo[ 'not_in_version' ], |
|
101 | 101 | ); |
102 | 102 | |
103 | - $error = $this->filterErrorMsg($error, $itemInfo, $errorInfo); |
|
104 | - $data = $this->filterErrorData($data, $itemInfo, $errorInfo); |
|
103 | + $error = $this->filterErrorMsg( $error, $itemInfo, $errorInfo ); |
|
104 | + $data = $this->filterErrorData( $data, $itemInfo, $errorInfo ); |
|
105 | 105 | |
106 | - $this->addMessage($phpcsFile, $error, $stackPtr, $errorInfo['error'], $errorCode, $data); |
|
106 | + $this->addMessage( $phpcsFile, $error, $stackPtr, $errorInfo[ 'error' ], $errorCode, $data ); |
|
107 | 107 | } |
108 | 108 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @return void |
39 | 39 | */ |
40 | - public function handleFeature(File $phpcsFile, $stackPtr, array $itemInfo); |
|
40 | + public function handleFeature( File $phpcsFile, $stackPtr, array $itemInfo ); |
|
41 | 41 | |
42 | 42 | |
43 | 43 | /** |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @return array Version and other information about the item. |
49 | 49 | */ |
50 | - public function getItemArray(array $itemInfo); |
|
50 | + public function getItemArray( array $itemInfo ); |
|
51 | 51 | |
52 | 52 | |
53 | 53 | /** |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * |
59 | 59 | * @return array |
60 | 60 | */ |
61 | - public function getErrorInfo(array $itemArray, array $itemInfo); |
|
61 | + public function getErrorInfo( array $itemArray, array $itemInfo ); |
|
62 | 62 | |
63 | 63 | |
64 | 64 | /** |
@@ -73,5 +73,5 @@ discard block |
||
73 | 73 | * |
74 | 74 | * @return void |
75 | 75 | */ |
76 | - public function addError(File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo); |
|
76 | + public function addError( File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo ); |
|
77 | 77 | } |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | */ |
126 | 126 | protected function bowOutEarly() |
127 | 127 | { |
128 | - return ($this->supportsBelow('5.5') !== true); |
|
128 | + return ( $this->supportsBelow( '5.5' ) !== true ); |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | |
@@ -138,57 +138,57 @@ discard block |
||
138 | 138 | * |
139 | 139 | * @return void|int Null or integer stack pointer to skip forward. |
140 | 140 | */ |
141 | - public function process(File $phpcsFile, $stackPtr) |
|
141 | + public function process( File $phpcsFile, $stackPtr ) |
|
142 | 142 | { |
143 | - if ($this->bowOutEarly() === true) { |
|
143 | + if ( $this->bowOutEarly() === true ) { |
|
144 | 144 | return; |
145 | 145 | } |
146 | 146 | |
147 | 147 | $tokens = $phpcsFile->getTokens(); |
148 | 148 | |
149 | - switch ($tokens[$stackPtr]['type']) { |
|
149 | + switch ( $tokens[ $stackPtr ][ 'type' ] ) { |
|
150 | 150 | case 'T_FUNCTION': |
151 | 151 | case 'T_CLOSURE': |
152 | - $params = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr); |
|
153 | - if (empty($params)) { |
|
152 | + $params = PHPCSHelper::getMethodParameters( $phpcsFile, $stackPtr ); |
|
153 | + if ( empty( $params ) ) { |
|
154 | 154 | // No parameters. |
155 | 155 | return; |
156 | 156 | } |
157 | 157 | |
158 | - $funcToken = $tokens[$stackPtr]; |
|
158 | + $funcToken = $tokens[ $stackPtr ]; |
|
159 | 159 | |
160 | - if (isset($funcToken['parenthesis_owner'], $funcToken['parenthesis_opener'], $funcToken['parenthesis_closer']) === false |
|
161 | - || $funcToken['parenthesis_owner'] !== $stackPtr |
|
162 | - || isset($tokens[$funcToken['parenthesis_opener']], $tokens[$funcToken['parenthesis_closer']]) === false |
|
160 | + if ( isset( $funcToken[ 'parenthesis_owner' ], $funcToken[ 'parenthesis_opener' ], $funcToken[ 'parenthesis_closer' ] ) === false |
|
161 | + || $funcToken[ 'parenthesis_owner' ] !== $stackPtr |
|
162 | + || isset( $tokens[ $funcToken[ 'parenthesis_opener' ] ], $tokens[ $funcToken[ 'parenthesis_closer' ] ] ) === false |
|
163 | 163 | ) { |
164 | 164 | // Hmm.. something is going wrong as these should all be available & valid. |
165 | 165 | return; |
166 | 166 | } |
167 | 167 | |
168 | - $opener = $funcToken['parenthesis_opener']; |
|
169 | - $closer = $funcToken['parenthesis_closer']; |
|
168 | + $opener = $funcToken[ 'parenthesis_opener' ]; |
|
169 | + $closer = $funcToken[ 'parenthesis_closer' ]; |
|
170 | 170 | |
171 | 171 | // Which nesting level is the one we are interested in ? |
172 | 172 | $nestedParenthesisCount = 1; |
173 | - if (isset($tokens[$opener]['nested_parenthesis'])) { |
|
174 | - $nestedParenthesisCount += \count($tokens[$opener]['nested_parenthesis']); |
|
173 | + if ( isset( $tokens[ $opener ][ 'nested_parenthesis' ] ) ) { |
|
174 | + $nestedParenthesisCount += \count( $tokens[ $opener ][ 'nested_parenthesis' ] ); |
|
175 | 175 | } |
176 | 176 | |
177 | - foreach ($params as $param) { |
|
178 | - if (isset($param['default']) === false) { |
|
177 | + foreach ( $params as $param ) { |
|
178 | + if ( isset( $param[ 'default' ] ) === false ) { |
|
179 | 179 | continue; |
180 | 180 | } |
181 | 181 | |
182 | - $end = $param['token']; |
|
183 | - while (($end = $phpcsFile->findNext(array(\T_COMMA, \T_CLOSE_PARENTHESIS), ($end + 1), ($closer + 1))) !== false) { |
|
184 | - $maybeSkipTo = $this->isRealEndOfDeclaration($tokens, $end, $nestedParenthesisCount); |
|
185 | - if ($maybeSkipTo !== true) { |
|
182 | + $end = $param[ 'token' ]; |
|
183 | + while ( ( $end = $phpcsFile->findNext( array( \T_COMMA, \T_CLOSE_PARENTHESIS ), ( $end + 1 ), ( $closer + 1 ) ) ) !== false ) { |
|
184 | + $maybeSkipTo = $this->isRealEndOfDeclaration( $tokens, $end, $nestedParenthesisCount ); |
|
185 | + if ( $maybeSkipTo !== true ) { |
|
186 | 186 | $end = $maybeSkipTo; |
187 | 187 | continue; |
188 | 188 | } |
189 | 189 | |
190 | 190 | // Ignore closing parenthesis/bracket if not 'ours'. |
191 | - if ($tokens[$end]['code'] === \T_CLOSE_PARENTHESIS && $end !== $closer) { |
|
191 | + if ( $tokens[ $end ][ 'code' ] === \T_CLOSE_PARENTHESIS && $end !== $closer ) { |
|
192 | 192 | continue; |
193 | 193 | } |
194 | 194 | |
@@ -196,8 +196,8 @@ discard block |
||
196 | 196 | break; |
197 | 197 | } |
198 | 198 | |
199 | - if ($this->isValidAssignment($phpcsFile, $param['token'], $end) === false) { |
|
200 | - $this->throwError($phpcsFile, $param['token'], 'default', $param['content']); |
|
199 | + if ( $this->isValidAssignment( $phpcsFile, $param[ 'token' ], $end ) === false ) { |
|
200 | + $this->throwError( $phpcsFile, $param[ 'token' ], 'default', $param[ 'content' ] ); |
|
201 | 201 | } |
202 | 202 | } |
203 | 203 | |
@@ -213,75 +213,75 @@ discard block |
||
213 | 213 | $type = 'const'; |
214 | 214 | |
215 | 215 | // Filter out non-property declarations. |
216 | - if ($tokens[$stackPtr]['code'] === \T_VARIABLE) { |
|
217 | - if ($this->isClassProperty($phpcsFile, $stackPtr) === false) { |
|
216 | + if ( $tokens[ $stackPtr ][ 'code' ] === \T_VARIABLE ) { |
|
217 | + if ( $this->isClassProperty( $phpcsFile, $stackPtr ) === false ) { |
|
218 | 218 | return; |
219 | 219 | } |
220 | 220 | |
221 | 221 | $type = 'property'; |
222 | 222 | |
223 | 223 | // Move back one token to have the same starting point as the others. |
224 | - $stackPtr = ($stackPtr - 1); |
|
224 | + $stackPtr = ( $stackPtr - 1 ); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | // Filter out late static binding and class properties. |
228 | - if ($tokens[$stackPtr]['code'] === \T_STATIC) { |
|
229 | - $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true, null, true); |
|
230 | - if ($next === false || $tokens[$next]['code'] !== \T_VARIABLE) { |
|
228 | + if ( $tokens[ $stackPtr ][ 'code' ] === \T_STATIC ) { |
|
229 | + $next = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true, null, true ); |
|
230 | + if ( $next === false || $tokens[ $next ][ 'code' ] !== \T_VARIABLE ) { |
|
231 | 231 | // Late static binding. |
232 | 232 | return; |
233 | 233 | } |
234 | 234 | |
235 | - if ($this->isClassProperty($phpcsFile, $next) === true) { |
|
235 | + if ( $this->isClassProperty( $phpcsFile, $next ) === true ) { |
|
236 | 236 | // Class properties are examined based on the T_VARIABLE token. |
237 | 237 | return; |
238 | 238 | } |
239 | - unset($next); |
|
239 | + unset( $next ); |
|
240 | 240 | |
241 | 241 | $type = 'staticvar'; |
242 | 242 | } |
243 | 243 | |
244 | - $endOfStatement = $phpcsFile->findNext(array(\T_SEMICOLON, \T_CLOSE_TAG), ($stackPtr + 1)); |
|
245 | - if ($endOfStatement === false) { |
|
244 | + $endOfStatement = $phpcsFile->findNext( array( \T_SEMICOLON, \T_CLOSE_TAG ), ( $stackPtr + 1 ) ); |
|
245 | + if ( $endOfStatement === false ) { |
|
246 | 246 | // No semi-colon - live coding. |
247 | 247 | return; |
248 | 248 | } |
249 | 249 | |
250 | 250 | $targetNestingLevel = 0; |
251 | - if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) { |
|
252 | - $targetNestingLevel = \count($tokens[$stackPtr]['nested_parenthesis']); |
|
251 | + if ( isset( $tokens[ $stackPtr ][ 'nested_parenthesis' ] ) === true ) { |
|
252 | + $targetNestingLevel = \count( $tokens[ $stackPtr ][ 'nested_parenthesis' ] ); |
|
253 | 253 | } |
254 | 254 | |
255 | 255 | // Examine each variable/constant in multi-declarations. |
256 | 256 | $start = $stackPtr; |
257 | 257 | $end = $stackPtr; |
258 | - while (($end = $phpcsFile->findNext(array(\T_COMMA, \T_SEMICOLON, \T_OPEN_SHORT_ARRAY, \T_CLOSE_TAG), ($end + 1), ($endOfStatement + 1))) !== false) { |
|
258 | + while ( ( $end = $phpcsFile->findNext( array( \T_COMMA, \T_SEMICOLON, \T_OPEN_SHORT_ARRAY, \T_CLOSE_TAG ), ( $end + 1 ), ( $endOfStatement + 1 ) ) ) !== false ) { |
|
259 | 259 | |
260 | - $maybeSkipTo = $this->isRealEndOfDeclaration($tokens, $end, $targetNestingLevel); |
|
261 | - if ($maybeSkipTo !== true) { |
|
260 | + $maybeSkipTo = $this->isRealEndOfDeclaration( $tokens, $end, $targetNestingLevel ); |
|
261 | + if ( $maybeSkipTo !== true ) { |
|
262 | 262 | $end = $maybeSkipTo; |
263 | 263 | continue; |
264 | 264 | } |
265 | 265 | |
266 | - $start = $phpcsFile->findNext(Tokens::$emptyTokens, ($start + 1), $end, true); |
|
267 | - if ($start === false |
|
268 | - || ($tokens[$stackPtr]['code'] === \T_CONST && $tokens[$start]['code'] !== \T_STRING) |
|
269 | - || ($tokens[$stackPtr]['code'] !== \T_CONST && $tokens[$start]['code'] !== \T_VARIABLE) |
|
266 | + $start = $phpcsFile->findNext( Tokens::$emptyTokens, ( $start + 1 ), $end, true ); |
|
267 | + if ( $start === false |
|
268 | + || ( $tokens[ $stackPtr ][ 'code' ] === \T_CONST && $tokens[ $start ][ 'code' ] !== \T_STRING ) |
|
269 | + || ( $tokens[ $stackPtr ][ 'code' ] !== \T_CONST && $tokens[ $start ][ 'code' ] !== \T_VARIABLE ) |
|
270 | 270 | ) { |
271 | 271 | // Shouldn't be possible. |
272 | 272 | continue; |
273 | 273 | } |
274 | 274 | |
275 | - if ($this->isValidAssignment($phpcsFile, $start, $end) === false) { |
|
275 | + if ( $this->isValidAssignment( $phpcsFile, $start, $end ) === false ) { |
|
276 | 276 | // Create the "found" snippet. |
277 | 277 | $content = ''; |
278 | - $tokenCount = ($end - $start); |
|
279 | - if ($tokenCount < 20) { |
|
278 | + $tokenCount = ( $end - $start ); |
|
279 | + if ( $tokenCount < 20 ) { |
|
280 | 280 | // Prevent large arrays from being added to the error message. |
281 | - $content = $phpcsFile->getTokensAsString($start, ($tokenCount + 1)); |
|
281 | + $content = $phpcsFile->getTokensAsString( $start, ( $tokenCount + 1 ) ); |
|
282 | 282 | } |
283 | 283 | |
284 | - $this->throwError($phpcsFile, $start, $type, $content); |
|
284 | + $this->throwError( $phpcsFile, $start, $type, $content ); |
|
285 | 285 | } |
286 | 286 | |
287 | 287 | $start = $end; |
@@ -304,16 +304,16 @@ discard block |
||
304 | 304 | * |
305 | 305 | * @return bool |
306 | 306 | */ |
307 | - protected function isValidAssignment(File $phpcsFile, $stackPtr, $end) |
|
307 | + protected function isValidAssignment( File $phpcsFile, $stackPtr, $end ) |
|
308 | 308 | { |
309 | 309 | $tokens = $phpcsFile->getTokens(); |
310 | - $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), $end, true); |
|
311 | - if ($next === false || $tokens[$next]['code'] !== \T_EQUAL) { |
|
310 | + $next = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), $end, true ); |
|
311 | + if ( $next === false || $tokens[ $next ][ 'code' ] !== \T_EQUAL ) { |
|
312 | 312 | // No value assigned. |
313 | 313 | return true; |
314 | 314 | } |
315 | 315 | |
316 | - return $this->isStaticValue($phpcsFile, $tokens, ($next + 1), ($end - 1)); |
|
316 | + return $this->isStaticValue( $phpcsFile, $tokens, ( $next + 1 ), ( $end - 1 ) ); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | |
@@ -331,20 +331,20 @@ discard block |
||
331 | 331 | * |
332 | 332 | * @return bool |
333 | 333 | */ |
334 | - protected function isStaticValue(File $phpcsFile, $tokens, $start, $end, $nestedArrays = 0) |
|
334 | + protected function isStaticValue( File $phpcsFile, $tokens, $start, $end, $nestedArrays = 0 ) |
|
335 | 335 | { |
336 | - $nextNonSimple = $phpcsFile->findNext($this->safeOperands, $start, ($end + 1), true); |
|
337 | - if ($nextNonSimple === false) { |
|
336 | + $nextNonSimple = $phpcsFile->findNext( $this->safeOperands, $start, ( $end + 1 ), true ); |
|
337 | + if ( $nextNonSimple === false ) { |
|
338 | 338 | return true; |
339 | 339 | } |
340 | 340 | |
341 | 341 | /* |
342 | 342 | * OK, so we have at least one token which needs extra examination. |
343 | 343 | */ |
344 | - switch ($tokens[$nextNonSimple]['code']) { |
|
344 | + switch ( $tokens[ $nextNonSimple ][ 'code' ] ) { |
|
345 | 345 | case \T_MINUS: |
346 | 346 | case \T_PLUS: |
347 | - if ($this->isNumber($phpcsFile, $start, $end, true) !== false) { |
|
347 | + if ( $this->isNumber( $phpcsFile, $start, $end, true ) !== false ) { |
|
348 | 348 | // Int or float with sign. |
349 | 349 | return true; |
350 | 350 | } |
@@ -355,70 +355,70 @@ discard block |
||
355 | 355 | case \T_PARENT: |
356 | 356 | case \T_SELF: |
357 | 357 | case \T_DOUBLE_COLON: |
358 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextNonSimple + 1), ($end + 1), true); |
|
358 | + $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $nextNonSimple + 1 ), ( $end + 1 ), true ); |
|
359 | 359 | |
360 | - if ($tokens[$nextNonSimple]['code'] === \T_NAMESPACE) { |
|
360 | + if ( $tokens[ $nextNonSimple ][ 'code' ] === \T_NAMESPACE ) { |
|
361 | 361 | // Allow only `namespace\...`. |
362 | - if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_NS_SEPARATOR) { |
|
362 | + if ( $nextNonEmpty === false || $tokens[ $nextNonEmpty ][ 'code' ] !== \T_NS_SEPARATOR ) { |
|
363 | 363 | return false; |
364 | 364 | } |
365 | - } elseif ($tokens[$nextNonSimple]['code'] === \T_PARENT |
|
366 | - || $tokens[$nextNonSimple]['code'] === \T_SELF |
|
365 | + } elseif ( $tokens[ $nextNonSimple ][ 'code' ] === \T_PARENT |
|
366 | + || $tokens[ $nextNonSimple ][ 'code' ] === \T_SELF |
|
367 | 367 | ) { |
368 | 368 | // Allow only `parent::` and `self::`. |
369 | - if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_DOUBLE_COLON) { |
|
369 | + if ( $nextNonEmpty === false || $tokens[ $nextNonEmpty ][ 'code' ] !== \T_DOUBLE_COLON ) { |
|
370 | 370 | return false; |
371 | 371 | } |
372 | - } elseif ($tokens[$nextNonSimple]['code'] === \T_DOUBLE_COLON) { |
|
372 | + } elseif ( $tokens[ $nextNonSimple ][ 'code' ] === \T_DOUBLE_COLON ) { |
|
373 | 373 | // Allow only `T_STRING::T_STRING`. |
374 | - if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_STRING) { |
|
374 | + if ( $nextNonEmpty === false || $tokens[ $nextNonEmpty ][ 'code' ] !== \T_STRING ) { |
|
375 | 375 | return false; |
376 | 376 | } |
377 | 377 | |
378 | - $prevNonEmpty = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($nextNonSimple - 1), null, true); |
|
378 | + $prevNonEmpty = $phpcsFile->findPrevious( Tokens::$emptyTokens, ( $nextNonSimple - 1 ), null, true ); |
|
379 | 379 | // No need to worry about parent/self, that's handled above and |
380 | 380 | // the double colon is skipped over in that case. |
381 | - if ($prevNonEmpty === false || $tokens[$prevNonEmpty]['code'] !== \T_STRING) { |
|
381 | + if ( $prevNonEmpty === false || $tokens[ $prevNonEmpty ][ 'code' ] !== \T_STRING ) { |
|
382 | 382 | return false; |
383 | 383 | } |
384 | 384 | } |
385 | 385 | |
386 | 386 | // Examine what comes after the namespace/parent/self/double colon, if anything. |
387 | - return $this->isStaticValue($phpcsFile, $tokens, ($nextNonEmpty + 1), $end, $nestedArrays); |
|
387 | + return $this->isStaticValue( $phpcsFile, $tokens, ( $nextNonEmpty + 1 ), $end, $nestedArrays ); |
|
388 | 388 | |
389 | 389 | case \T_ARRAY: |
390 | 390 | case \T_OPEN_SHORT_ARRAY: |
391 | 391 | ++$nestedArrays; |
392 | 392 | |
393 | - $arrayItems = $this->getFunctionCallParameters($phpcsFile, $nextNonSimple); |
|
394 | - if (empty($arrayItems) === false) { |
|
395 | - foreach ($arrayItems as $item) { |
|
393 | + $arrayItems = $this->getFunctionCallParameters( $phpcsFile, $nextNonSimple ); |
|
394 | + if ( empty( $arrayItems ) === false ) { |
|
395 | + foreach ( $arrayItems as $item ) { |
|
396 | 396 | // Check for a double arrow, but only if it's for this array item, not for a nested array. |
397 | 397 | $doubleArrow = false; |
398 | 398 | |
399 | 399 | $maybeDoubleArrow = $phpcsFile->findNext( |
400 | - array(\T_DOUBLE_ARROW, \T_ARRAY, \T_OPEN_SHORT_ARRAY), |
|
401 | - $item['start'], |
|
402 | - ($item['end'] + 1) |
|
400 | + array( \T_DOUBLE_ARROW, \T_ARRAY, \T_OPEN_SHORT_ARRAY ), |
|
401 | + $item[ 'start' ], |
|
402 | + ( $item[ 'end' ] + 1 ) |
|
403 | 403 | ); |
404 | - if ($maybeDoubleArrow !== false && $tokens[$maybeDoubleArrow]['code'] === \T_DOUBLE_ARROW) { |
|
404 | + if ( $maybeDoubleArrow !== false && $tokens[ $maybeDoubleArrow ][ 'code' ] === \T_DOUBLE_ARROW ) { |
|
405 | 405 | // Double arrow is for this nesting level. |
406 | 406 | $doubleArrow = $maybeDoubleArrow; |
407 | 407 | } |
408 | 408 | |
409 | - if ($doubleArrow === false) { |
|
410 | - if ($this->isStaticValue($phpcsFile, $tokens, $item['start'], $item['end'], $nestedArrays) === false) { |
|
409 | + if ( $doubleArrow === false ) { |
|
410 | + if ( $this->isStaticValue( $phpcsFile, $tokens, $item[ 'start' ], $item[ 'end' ], $nestedArrays ) === false ) { |
|
411 | 411 | return false; |
412 | 412 | } |
413 | 413 | |
414 | 414 | } else { |
415 | 415 | // Examine array key. |
416 | - if ($this->isStaticValue($phpcsFile, $tokens, $item['start'], ($doubleArrow - 1), $nestedArrays) === false) { |
|
416 | + if ( $this->isStaticValue( $phpcsFile, $tokens, $item[ 'start' ], ( $doubleArrow - 1 ), $nestedArrays ) === false ) { |
|
417 | 417 | return false; |
418 | 418 | } |
419 | 419 | |
420 | 420 | // Examine array value. |
421 | - if ($this->isStaticValue($phpcsFile, $tokens, ($doubleArrow + 1), $item['end'], $nestedArrays) === false) { |
|
421 | + if ( $this->isStaticValue( $phpcsFile, $tokens, ( $doubleArrow + 1 ), $item[ 'end' ], $nestedArrays ) === false ) { |
|
422 | 422 | return false; |
423 | 423 | } |
424 | 424 | } |
@@ -432,27 +432,27 @@ discard block |
||
432 | 432 | * We already know we will have a valid closer as otherwise we wouldn't have been |
433 | 433 | * able to get the array items. |
434 | 434 | */ |
435 | - $closer = ($nextNonSimple + 1); |
|
436 | - if ($tokens[$nextNonSimple]['code'] === \T_OPEN_SHORT_ARRAY |
|
437 | - && isset($tokens[$nextNonSimple]['bracket_closer']) === true |
|
435 | + $closer = ( $nextNonSimple + 1 ); |
|
436 | + if ( $tokens[ $nextNonSimple ][ 'code' ] === \T_OPEN_SHORT_ARRAY |
|
437 | + && isset( $tokens[ $nextNonSimple ][ 'bracket_closer' ] ) === true |
|
438 | 438 | ) { |
439 | - $closer = $tokens[$nextNonSimple]['bracket_closer']; |
|
439 | + $closer = $tokens[ $nextNonSimple ][ 'bracket_closer' ]; |
|
440 | 440 | } else { |
441 | - $maybeOpener = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextNonSimple + 1), ($end + 1), true); |
|
442 | - if ($tokens[$maybeOpener]['code'] === \T_OPEN_PARENTHESIS) { |
|
441 | + $maybeOpener = $phpcsFile->findNext( Tokens::$emptyTokens, ( $nextNonSimple + 1 ), ( $end + 1 ), true ); |
|
442 | + if ( $tokens[ $maybeOpener ][ 'code' ] === \T_OPEN_PARENTHESIS ) { |
|
443 | 443 | $opener = $maybeOpener; |
444 | - if (isset($tokens[$opener]['parenthesis_closer']) === true) { |
|
445 | - $closer = $tokens[$opener]['parenthesis_closer']; |
|
444 | + if ( isset( $tokens[ $opener ][ 'parenthesis_closer' ] ) === true ) { |
|
445 | + $closer = $tokens[ $opener ][ 'parenthesis_closer' ]; |
|
446 | 446 | } |
447 | 447 | } |
448 | 448 | } |
449 | 449 | |
450 | - if ($closer === $end) { |
|
450 | + if ( $closer === $end ) { |
|
451 | 451 | return true; |
452 | 452 | } |
453 | 453 | |
454 | 454 | // Examine what comes after the array, if anything. |
455 | - return $this->isStaticValue($phpcsFile, $tokens, ($closer + 1), $end, $nestedArrays); |
|
455 | + return $this->isStaticValue( $phpcsFile, $tokens, ( $closer + 1 ), $end, $nestedArrays ); |
|
456 | 456 | |
457 | 457 | } |
458 | 458 | |
@@ -471,25 +471,25 @@ discard block |
||
471 | 471 | * |
472 | 472 | * @return void |
473 | 473 | */ |
474 | - protected function throwError(File $phpcsFile, $stackPtr, $type, $content = '') |
|
474 | + protected function throwError( File $phpcsFile, $stackPtr, $type, $content = '' ) |
|
475 | 475 | { |
476 | 476 | $error = static::ERROR_PHRASE; |
477 | 477 | $phrase = ''; |
478 | 478 | $errorCode = 'Found'; |
479 | 479 | |
480 | - if (isset($this->errorPhrases[$type]) === true) { |
|
481 | - $errorCode = $this->stringToErrorCode($type) . 'Found'; |
|
482 | - $phrase = $this->errorPhrases[$type]; |
|
480 | + if ( isset( $this->errorPhrases[ $type ] ) === true ) { |
|
481 | + $errorCode = $this->stringToErrorCode( $type ) . 'Found'; |
|
482 | + $phrase = $this->errorPhrases[ $type ]; |
|
483 | 483 | } |
484 | 484 | |
485 | - $data = array($phrase); |
|
485 | + $data = array( $phrase ); |
|
486 | 486 | |
487 | - if (empty($content) === false) { |
|
487 | + if ( empty( $content ) === false ) { |
|
488 | 488 | $error .= ' Found: %s'; |
489 | - $data[] = $content; |
|
489 | + $data[ ] = $content; |
|
490 | 490 | } |
491 | 491 | |
492 | - $phpcsFile->addError($error, $stackPtr, $errorCode, $data); |
|
492 | + $phpcsFile->addError( $error, $stackPtr, $errorCode, $data ); |
|
493 | 493 | } |
494 | 494 | |
495 | 495 | |
@@ -505,26 +505,26 @@ discard block |
||
505 | 505 | * |
506 | 506 | * @return bool|int True if this is the real end. Int stackPtr to skip to if not. |
507 | 507 | */ |
508 | - private function isRealEndOfDeclaration($tokens, $endPtr, $targetLevel) |
|
508 | + private function isRealEndOfDeclaration( $tokens, $endPtr, $targetLevel ) |
|
509 | 509 | { |
510 | 510 | // Ignore anything within short array definition brackets for now. |
511 | - if ($tokens[$endPtr]['code'] === \T_OPEN_SHORT_ARRAY |
|
512 | - && (isset($tokens[$endPtr]['bracket_opener']) |
|
513 | - && $tokens[$endPtr]['bracket_opener'] === $endPtr) |
|
514 | - && isset($tokens[$endPtr]['bracket_closer']) |
|
511 | + if ( $tokens[ $endPtr ][ 'code' ] === \T_OPEN_SHORT_ARRAY |
|
512 | + && ( isset( $tokens[ $endPtr ][ 'bracket_opener' ] ) |
|
513 | + && $tokens[ $endPtr ][ 'bracket_opener' ] === $endPtr ) |
|
514 | + && isset( $tokens[ $endPtr ][ 'bracket_closer' ] ) |
|
515 | 515 | ) { |
516 | 516 | // Skip forward to the end of the short array definition. |
517 | - return $tokens[$endPtr]['bracket_closer']; |
|
517 | + return $tokens[ $endPtr ][ 'bracket_closer' ]; |
|
518 | 518 | } |
519 | 519 | |
520 | 520 | // Skip past comma's at a lower nesting level. |
521 | - if ($tokens[$endPtr]['code'] === \T_COMMA) { |
|
521 | + if ( $tokens[ $endPtr ][ 'code' ] === \T_COMMA ) { |
|
522 | 522 | // Check if a comma is at the nesting level we're targetting. |
523 | 523 | $nestingLevel = 0; |
524 | - if (isset($tokens[$endPtr]['nested_parenthesis']) === true) { |
|
525 | - $nestingLevel = \count($tokens[$endPtr]['nested_parenthesis']); |
|
524 | + if ( isset( $tokens[ $endPtr ][ 'nested_parenthesis' ] ) === true ) { |
|
525 | + $nestingLevel = \count( $tokens[ $endPtr ][ 'nested_parenthesis' ] ); |
|
526 | 526 | } |
527 | - if ($nestingLevel > $targetLevel) { |
|
527 | + if ( $nestingLevel > $targetLevel ) { |
|
528 | 528 | return $endPtr; |
529 | 529 | } |
530 | 530 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public function register() |
37 | 37 | { |
38 | - return array(\T_CONST); |
|
38 | + return array( \T_CONST ); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
@@ -47,9 +47,9 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @return void |
49 | 49 | */ |
50 | - public function process(File $phpcsFile, $stackPtr) |
|
50 | + public function process( File $phpcsFile, $stackPtr ) |
|
51 | 51 | { |
52 | - if ($this->supportsBelow('5.5') !== true) { |
|
52 | + if ( $this->supportsBelow( '5.5' ) !== true ) { |
|
53 | 53 | return; |
54 | 54 | } |
55 | 55 | |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | \T_OPEN_SHORT_ARRAY => \T_OPEN_SHORT_ARRAY, |
60 | 60 | ); |
61 | 61 | |
62 | - while (($hasArray = $phpcsFile->findNext($find, ($stackPtr + 1), null, false, null, true)) !== false) { |
|
62 | + while ( ( $hasArray = $phpcsFile->findNext( $find, ( $stackPtr + 1 ), null, false, null, true ) ) !== false ) { |
|
63 | 63 | $phpcsFile->addError( |
64 | 64 | 'Constant arrays using the "const" keyword are not allowed in PHP 5.5 or earlier', |
65 | 65 | $hasArray, |
@@ -68,10 +68,10 @@ discard block |
||
68 | 68 | |
69 | 69 | // Skip past the content of the array. |
70 | 70 | $stackPtr = $hasArray; |
71 | - if ($tokens[$hasArray]['code'] === \T_OPEN_SHORT_ARRAY && isset($tokens[$hasArray]['bracket_closer'])) { |
|
72 | - $stackPtr = $tokens[$hasArray]['bracket_closer']; |
|
73 | - } elseif ($tokens[$hasArray]['code'] === \T_ARRAY && isset($tokens[$hasArray]['parenthesis_closer'])) { |
|
74 | - $stackPtr = $tokens[$hasArray]['parenthesis_closer']; |
|
71 | + if ( $tokens[ $hasArray ][ 'code' ] === \T_OPEN_SHORT_ARRAY && isset( $tokens[ $hasArray ][ 'bracket_closer' ] ) ) { |
|
72 | + $stackPtr = $tokens[ $hasArray ][ 'bracket_closer' ]; |
|
73 | + } elseif ( $tokens[ $hasArray ][ 'code' ] === \T_ARRAY && isset( $tokens[ $hasArray ][ 'parenthesis_closer' ] ) ) { |
|
74 | + $stackPtr = $tokens[ $hasArray ][ 'parenthesis_closer' ]; |
|
75 | 75 | } |
76 | 76 | } |
77 | 77 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | */ |
36 | 36 | public function register() |
37 | 37 | { |
38 | - return array(\T_STRING); |
|
38 | + return array( \T_STRING ); |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
@@ -47,9 +47,9 @@ discard block |
||
47 | 47 | * |
48 | 48 | * @return void |
49 | 49 | */ |
50 | - public function process(File $phpcsFile, $stackPtr) |
|
50 | + public function process( File $phpcsFile, $stackPtr ) |
|
51 | 51 | { |
52 | - if ($this->supportsBelow('5.6') !== true) { |
|
52 | + if ( $this->supportsBelow( '5.6' ) !== true ) { |
|
53 | 53 | return; |
54 | 54 | } |
55 | 55 | |
@@ -62,30 +62,30 @@ discard block |
||
62 | 62 | \T_CONST => true, |
63 | 63 | ); |
64 | 64 | |
65 | - $prevToken = $phpcsFile->findPrevious(\T_WHITESPACE, ($stackPtr - 1), null, true); |
|
66 | - if (isset($ignore[$tokens[$prevToken]['code']]) === true) { |
|
65 | + $prevToken = $phpcsFile->findPrevious( \T_WHITESPACE, ( $stackPtr - 1 ), null, true ); |
|
66 | + if ( isset( $ignore[ $tokens[ $prevToken ][ 'code' ] ] ) === true ) { |
|
67 | 67 | // Not a call to a PHP function. |
68 | 68 | return; |
69 | 69 | } |
70 | 70 | |
71 | - $functionLc = strtolower($tokens[$stackPtr]['content']); |
|
72 | - if ($functionLc !== 'define') { |
|
71 | + $functionLc = strtolower( $tokens[ $stackPtr ][ 'content' ] ); |
|
72 | + if ( $functionLc !== 'define' ) { |
|
73 | 73 | return; |
74 | 74 | } |
75 | 75 | |
76 | - $secondParam = $this->getFunctionCallParameter($phpcsFile, $stackPtr, 2); |
|
77 | - if (isset($secondParam['start'], $secondParam['end']) === false) { |
|
76 | + $secondParam = $this->getFunctionCallParameter( $phpcsFile, $stackPtr, 2 ); |
|
77 | + if ( isset( $secondParam[ 'start' ], $secondParam[ 'end' ] ) === false ) { |
|
78 | 78 | return; |
79 | 79 | } |
80 | 80 | |
81 | 81 | $targetNestingLevel = 0; |
82 | - if (isset($tokens[$secondParam['start']]['nested_parenthesis'])) { |
|
83 | - $targetNestingLevel = \count($tokens[$secondParam['start']]['nested_parenthesis']); |
|
82 | + if ( isset( $tokens[ $secondParam[ 'start' ] ][ 'nested_parenthesis' ] ) ) { |
|
83 | + $targetNestingLevel = \count( $tokens[ $secondParam[ 'start' ] ][ 'nested_parenthesis' ] ); |
|
84 | 84 | } |
85 | 85 | |
86 | - $array = $phpcsFile->findNext(array(\T_ARRAY, \T_OPEN_SHORT_ARRAY), $secondParam['start'], ($secondParam['end'] + 1)); |
|
87 | - if ($array !== false) { |
|
88 | - if ((isset($tokens[$array]['nested_parenthesis']) === false && $targetNestingLevel === 0) || \count($tokens[$array]['nested_parenthesis']) === $targetNestingLevel) { |
|
86 | + $array = $phpcsFile->findNext( array( \T_ARRAY, \T_OPEN_SHORT_ARRAY ), $secondParam[ 'start' ], ( $secondParam[ 'end' ] + 1 ) ); |
|
87 | + if ( $array !== false ) { |
|
88 | + if ( ( isset( $tokens[ $array ][ 'nested_parenthesis' ] ) === false && $targetNestingLevel === 0 ) || \count( $tokens[ $array ][ 'nested_parenthesis' ] ) === $targetNestingLevel ) { |
|
89 | 89 | $phpcsFile->addError( |
90 | 90 | 'Constant arrays using define are not allowed in PHP 5.6 or earlier', |
91 | 91 | $array, |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | */ |
63 | 63 | protected function bowOutEarly() |
64 | 64 | { |
65 | - return ($this->supportsBelow('5.2') !== true); |
|
65 | + return ( $this->supportsBelow( '5.2' ) !== true ); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | |
@@ -76,15 +76,15 @@ discard block |
||
76 | 76 | * |
77 | 77 | * @return bool True if no heredoc (or assignment) is found, false otherwise. |
78 | 78 | */ |
79 | - protected function isValidAssignment(File $phpcsFile, $stackPtr, $end) |
|
79 | + protected function isValidAssignment( File $phpcsFile, $stackPtr, $end ) |
|
80 | 80 | { |
81 | 81 | $tokens = $phpcsFile->getTokens(); |
82 | - $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), $end, true); |
|
83 | - if ($next === false || $tokens[$next]['code'] !== \T_EQUAL) { |
|
82 | + $next = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), $end, true ); |
|
83 | + if ( $next === false || $tokens[ $next ][ 'code' ] !== \T_EQUAL ) { |
|
84 | 84 | // No value assigned. |
85 | 85 | return true; |
86 | 86 | } |
87 | 87 | |
88 | - return ($phpcsFile->findNext(\T_START_HEREDOC, ($next + 1), $end, false, null, true) === false); |
|
88 | + return ( $phpcsFile->findNext( \T_START_HEREDOC, ( $next + 1 ), $end, false, null, true ) === false ); |
|
89 | 89 | } |
90 | 90 | } |