@@ -3599,7 +3599,7 @@ discard block |
||
3599 | 3599 | */ |
3600 | 3600 | public function register() |
3601 | 3601 | { |
3602 | - return array(\T_STRING); |
|
3602 | + return array( \T_STRING ); |
|
3603 | 3603 | } |
3604 | 3604 | |
3605 | 3605 | /** |
@@ -3611,23 +3611,23 @@ discard block |
||
3611 | 3611 | * |
3612 | 3612 | * @return void |
3613 | 3613 | */ |
3614 | - public function process(File $phpcsFile, $stackPtr) |
|
3614 | + public function process( File $phpcsFile, $stackPtr ) |
|
3615 | 3615 | { |
3616 | 3616 | $tokens = $phpcsFile->getTokens(); |
3617 | - $constantName = $tokens[$stackPtr]['content']; |
|
3617 | + $constantName = $tokens[ $stackPtr ][ 'content' ]; |
|
3618 | 3618 | |
3619 | - if (isset($this->newConstants[$constantName]) === false) { |
|
3619 | + if ( isset( $this->newConstants[ $constantName ] ) === false ) { |
|
3620 | 3620 | return; |
3621 | 3621 | } |
3622 | 3622 | |
3623 | - if ($this->isUseOfGlobalConstant($phpcsFile, $stackPtr) === false) { |
|
3623 | + if ( $this->isUseOfGlobalConstant( $phpcsFile, $stackPtr ) === false ) { |
|
3624 | 3624 | return; |
3625 | 3625 | } |
3626 | 3626 | |
3627 | 3627 | $itemInfo = array( |
3628 | 3628 | 'name' => $constantName, |
3629 | 3629 | ); |
3630 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
3630 | + $this->handleFeature( $phpcsFile, $stackPtr, $itemInfo ); |
|
3631 | 3631 | } |
3632 | 3632 | |
3633 | 3633 | |
@@ -3638,9 +3638,9 @@ discard block |
||
3638 | 3638 | * |
3639 | 3639 | * @return array Version and other information about the item. |
3640 | 3640 | */ |
3641 | - public function getItemArray(array $itemInfo) |
|
3641 | + public function getItemArray( array $itemInfo ) |
|
3642 | 3642 | { |
3643 | - return $this->newConstants[$itemInfo['name']]; |
|
3643 | + return $this->newConstants[ $itemInfo[ 'name' ] ]; |
|
3644 | 3644 | } |
3645 | 3645 | |
3646 | 3646 |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | */ |
490 | 490 | public function register() |
491 | 491 | { |
492 | - return array(\T_STRING); |
|
492 | + return array( \T_STRING ); |
|
493 | 493 | } |
494 | 494 | |
495 | 495 | |
@@ -502,23 +502,23 @@ discard block |
||
502 | 502 | * |
503 | 503 | * @return void |
504 | 504 | */ |
505 | - public function process(File $phpcsFile, $stackPtr) |
|
505 | + public function process( File $phpcsFile, $stackPtr ) |
|
506 | 506 | { |
507 | 507 | $tokens = $phpcsFile->getTokens(); |
508 | - $constantName = $tokens[$stackPtr]['content']; |
|
508 | + $constantName = $tokens[ $stackPtr ][ 'content' ]; |
|
509 | 509 | |
510 | - if (isset($this->removedConstants[$constantName]) === false) { |
|
510 | + if ( isset( $this->removedConstants[ $constantName ] ) === false ) { |
|
511 | 511 | return; |
512 | 512 | } |
513 | 513 | |
514 | - if ($this->isUseOfGlobalConstant($phpcsFile, $stackPtr) === false) { |
|
514 | + if ( $this->isUseOfGlobalConstant( $phpcsFile, $stackPtr ) === false ) { |
|
515 | 515 | return; |
516 | 516 | } |
517 | 517 | |
518 | 518 | $itemInfo = array( |
519 | 519 | 'name' => $constantName, |
520 | 520 | ); |
521 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
521 | + $this->handleFeature( $phpcsFile, $stackPtr, $itemInfo ); |
|
522 | 522 | } |
523 | 523 | |
524 | 524 | |
@@ -529,9 +529,9 @@ discard block |
||
529 | 529 | * |
530 | 530 | * @return array Version and other information about the item. |
531 | 531 | */ |
532 | - public function getItemArray(array $itemInfo) |
|
532 | + public function getItemArray( array $itemInfo ) |
|
533 | 533 | { |
534 | - return $this->removedConstants[$itemInfo['name']]; |
|
534 | + return $this->removedConstants[ $itemInfo[ 'name' ] ]; |
|
535 | 535 | } |
536 | 536 | |
537 | 537 |
@@ -119,8 +119,8 @@ discard block |
||
119 | 119 | public function register() |
120 | 120 | { |
121 | 121 | // Handle case-insensitivity of interface names. |
122 | - $this->newInterfaces = $this->arrayKeysToLowercase($this->newInterfaces); |
|
123 | - $this->unsupportedMethods = $this->arrayKeysToLowercase($this->unsupportedMethods); |
|
122 | + $this->newInterfaces = $this->arrayKeysToLowercase( $this->newInterfaces ); |
|
123 | + $this->unsupportedMethods = $this->arrayKeysToLowercase( $this->unsupportedMethods ); |
|
124 | 124 | |
125 | 125 | $targets = array( |
126 | 126 | \T_CLASS, |
@@ -128,12 +128,12 @@ discard block |
||
128 | 128 | \T_CLOSURE, |
129 | 129 | ); |
130 | 130 | |
131 | - if (\defined('T_ANON_CLASS')) { |
|
132 | - $targets[] = \T_ANON_CLASS; |
|
131 | + if ( \defined( 'T_ANON_CLASS' ) ) { |
|
132 | + $targets[ ] = \T_ANON_CLASS; |
|
133 | 133 | } |
134 | 134 | |
135 | - if (\defined('T_RETURN_TYPE')) { |
|
136 | - $targets[] = \T_RETURN_TYPE; |
|
135 | + if ( \defined( 'T_RETURN_TYPE' ) ) { |
|
136 | + $targets[ ] = \T_RETURN_TYPE; |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | return $targets; |
@@ -149,30 +149,30 @@ discard block |
||
149 | 149 | * |
150 | 150 | * @return void |
151 | 151 | */ |
152 | - public function process(File $phpcsFile, $stackPtr) |
|
152 | + public function process( File $phpcsFile, $stackPtr ) |
|
153 | 153 | { |
154 | 154 | $tokens = $phpcsFile->getTokens(); |
155 | 155 | |
156 | - switch ($tokens[$stackPtr]['type']) { |
|
156 | + switch ( $tokens[ $stackPtr ][ 'type' ] ) { |
|
157 | 157 | case 'T_CLASS': |
158 | 158 | case 'T_ANON_CLASS': |
159 | - $this->processClassToken($phpcsFile, $stackPtr); |
|
159 | + $this->processClassToken( $phpcsFile, $stackPtr ); |
|
160 | 160 | break; |
161 | 161 | |
162 | 162 | case 'T_FUNCTION': |
163 | 163 | case 'T_CLOSURE': |
164 | - $this->processFunctionToken($phpcsFile, $stackPtr); |
|
164 | + $this->processFunctionToken( $phpcsFile, $stackPtr ); |
|
165 | 165 | |
166 | 166 | // Deal with older PHPCS versions which don't recognize return type hints |
167 | 167 | // as well as newer PHPCS versions (3.3.0+) where the tokenization has changed. |
168 | - $returnTypeHint = $this->getReturnTypeHintToken($phpcsFile, $stackPtr); |
|
169 | - if ($returnTypeHint !== false) { |
|
170 | - $this->processReturnTypeToken($phpcsFile, $returnTypeHint); |
|
168 | + $returnTypeHint = $this->getReturnTypeHintToken( $phpcsFile, $stackPtr ); |
|
169 | + if ( $returnTypeHint !== false ) { |
|
170 | + $this->processReturnTypeToken( $phpcsFile, $returnTypeHint ); |
|
171 | 171 | } |
172 | 172 | break; |
173 | 173 | |
174 | 174 | case 'T_RETURN_TYPE': |
175 | - $this->processReturnTypeToken($phpcsFile, $stackPtr); |
|
175 | + $this->processReturnTypeToken( $phpcsFile, $stackPtr ); |
|
176 | 176 | break; |
177 | 177 | |
178 | 178 | default: |
@@ -194,53 +194,53 @@ discard block |
||
194 | 194 | * |
195 | 195 | * @return void |
196 | 196 | */ |
197 | - private function processClassToken(File $phpcsFile, $stackPtr) |
|
197 | + private function processClassToken( File $phpcsFile, $stackPtr ) |
|
198 | 198 | { |
199 | - $interfaces = PHPCSHelper::findImplementedInterfaceNames($phpcsFile, $stackPtr); |
|
199 | + $interfaces = PHPCSHelper::findImplementedInterfaceNames( $phpcsFile, $stackPtr ); |
|
200 | 200 | |
201 | - if (\is_array($interfaces) === false || $interfaces === array()) { |
|
201 | + if ( \is_array( $interfaces ) === false || $interfaces === array() ) { |
|
202 | 202 | return; |
203 | 203 | } |
204 | 204 | |
205 | 205 | $tokens = $phpcsFile->getTokens(); |
206 | 206 | $checkMethods = false; |
207 | 207 | |
208 | - if (isset($tokens[$stackPtr]['scope_closer'])) { |
|
208 | + if ( isset( $tokens[ $stackPtr ][ 'scope_closer' ] ) ) { |
|
209 | 209 | $checkMethods = true; |
210 | - $scopeCloser = $tokens[$stackPtr]['scope_closer']; |
|
210 | + $scopeCloser = $tokens[ $stackPtr ][ 'scope_closer' ]; |
|
211 | 211 | } |
212 | 212 | |
213 | - foreach ($interfaces as $interface) { |
|
214 | - $interface = ltrim($interface, '\\'); |
|
215 | - $interfaceLc = strtolower($interface); |
|
213 | + foreach ( $interfaces as $interface ) { |
|
214 | + $interface = ltrim( $interface, '\\' ); |
|
215 | + $interfaceLc = strtolower( $interface ); |
|
216 | 216 | |
217 | - if (isset($this->newInterfaces[$interfaceLc]) === true) { |
|
217 | + if ( isset( $this->newInterfaces[ $interfaceLc ] ) === true ) { |
|
218 | 218 | $itemInfo = array( |
219 | 219 | 'name' => $interface, |
220 | 220 | 'nameLc' => $interfaceLc, |
221 | 221 | ); |
222 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
222 | + $this->handleFeature( $phpcsFile, $stackPtr, $itemInfo ); |
|
223 | 223 | } |
224 | 224 | |
225 | - if ($checkMethods === true && isset($this->unsupportedMethods[$interfaceLc]) === true) { |
|
225 | + if ( $checkMethods === true && isset( $this->unsupportedMethods[ $interfaceLc ] ) === true ) { |
|
226 | 226 | $nextFunc = $stackPtr; |
227 | - while (($nextFunc = $phpcsFile->findNext(\T_FUNCTION, ($nextFunc + 1), $scopeCloser)) !== false) { |
|
228 | - $funcName = $phpcsFile->getDeclarationName($nextFunc); |
|
229 | - $funcNameLc = strtolower($funcName); |
|
230 | - if ($funcNameLc === '') { |
|
227 | + while ( ( $nextFunc = $phpcsFile->findNext( \T_FUNCTION, ( $nextFunc + 1 ), $scopeCloser ) ) !== false ) { |
|
228 | + $funcName = $phpcsFile->getDeclarationName( $nextFunc ); |
|
229 | + $funcNameLc = strtolower( $funcName ); |
|
230 | + if ( $funcNameLc === '' ) { |
|
231 | 231 | continue; |
232 | 232 | } |
233 | 233 | |
234 | - if (isset($this->unsupportedMethods[$interfaceLc][$funcNameLc]) === true) { |
|
234 | + if ( isset( $this->unsupportedMethods[ $interfaceLc ][ $funcNameLc ] ) === true ) { |
|
235 | 235 | $error = 'Classes that implement interface %s do not support the method %s(). See %s'; |
236 | - $errorCode = $this->stringToErrorCode($interface) . 'UnsupportedMethod'; |
|
236 | + $errorCode = $this->stringToErrorCode( $interface ) . 'UnsupportedMethod'; |
|
237 | 237 | $data = array( |
238 | 238 | $interface, |
239 | 239 | $funcName, |
240 | - $this->unsupportedMethods[$interfaceLc][$funcNameLc], |
|
240 | + $this->unsupportedMethods[ $interfaceLc ][ $funcNameLc ], |
|
241 | 241 | ); |
242 | 242 | |
243 | - $phpcsFile->addError($error, $nextFunc, $errorCode, $data); |
|
243 | + $phpcsFile->addError( $error, $nextFunc, $errorCode, $data ); |
|
244 | 244 | } |
245 | 245 | } |
246 | 246 | } |
@@ -259,23 +259,23 @@ discard block |
||
259 | 259 | * |
260 | 260 | * @return void |
261 | 261 | */ |
262 | - private function processFunctionToken(File $phpcsFile, $stackPtr) |
|
262 | + private function processFunctionToken( File $phpcsFile, $stackPtr ) |
|
263 | 263 | { |
264 | - $typeHints = $this->getTypeHintsFromFunctionDeclaration($phpcsFile, $stackPtr); |
|
265 | - if (empty($typeHints) || \is_array($typeHints) === false) { |
|
264 | + $typeHints = $this->getTypeHintsFromFunctionDeclaration( $phpcsFile, $stackPtr ); |
|
265 | + if ( empty( $typeHints ) || \is_array( $typeHints ) === false ) { |
|
266 | 266 | return; |
267 | 267 | } |
268 | 268 | |
269 | - foreach ($typeHints as $hint) { |
|
269 | + foreach ( $typeHints as $hint ) { |
|
270 | 270 | |
271 | - $typeHintLc = strtolower($hint); |
|
271 | + $typeHintLc = strtolower( $hint ); |
|
272 | 272 | |
273 | - if (isset($this->newInterfaces[$typeHintLc]) === true) { |
|
273 | + if ( isset( $this->newInterfaces[ $typeHintLc ] ) === true ) { |
|
274 | 274 | $itemInfo = array( |
275 | 275 | 'name' => $hint, |
276 | 276 | 'nameLc' => $typeHintLc, |
277 | 277 | ); |
278 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
278 | + $this->handleFeature( $phpcsFile, $stackPtr, $itemInfo ); |
|
279 | 279 | } |
280 | 280 | } |
281 | 281 | } |
@@ -292,13 +292,13 @@ discard block |
||
292 | 292 | * |
293 | 293 | * @return void |
294 | 294 | */ |
295 | - private function processReturnTypeToken(File $phpcsFile, $stackPtr) |
|
295 | + private function processReturnTypeToken( File $phpcsFile, $stackPtr ) |
|
296 | 296 | { |
297 | - $returnTypeHint = $this->getReturnTypeHintName($phpcsFile, $stackPtr); |
|
298 | - $returnTypeHint = ltrim($returnTypeHint, '\\'); |
|
299 | - $returnTypeHintLc = strtolower($returnTypeHint); |
|
297 | + $returnTypeHint = $this->getReturnTypeHintName( $phpcsFile, $stackPtr ); |
|
298 | + $returnTypeHint = ltrim( $returnTypeHint, '\\' ); |
|
299 | + $returnTypeHintLc = strtolower( $returnTypeHint ); |
|
300 | 300 | |
301 | - if (isset($this->newInterfaces[$returnTypeHintLc]) === false) { |
|
301 | + if ( isset( $this->newInterfaces[ $returnTypeHintLc ] ) === false ) { |
|
302 | 302 | return; |
303 | 303 | } |
304 | 304 | |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | 'name' => $returnTypeHint, |
308 | 308 | 'nameLc' => $returnTypeHintLc, |
309 | 309 | ); |
310 | - $this->handleFeature($phpcsFile, $stackPtr, $itemInfo); |
|
310 | + $this->handleFeature( $phpcsFile, $stackPtr, $itemInfo ); |
|
311 | 311 | } |
312 | 312 | |
313 | 313 | |
@@ -318,9 +318,9 @@ discard block |
||
318 | 318 | * |
319 | 319 | * @return array Version and other information about the item. |
320 | 320 | */ |
321 | - public function getItemArray(array $itemInfo) |
|
321 | + public function getItemArray( array $itemInfo ) |
|
322 | 322 | { |
323 | - return $this->newInterfaces[$itemInfo['nameLc']]; |
|
323 | + return $this->newInterfaces[ $itemInfo[ 'nameLc' ] ]; |
|
324 | 324 | } |
325 | 325 | |
326 | 326 |
@@ -45,12 +45,12 @@ discard block |
||
45 | 45 | public function register() |
46 | 46 | { |
47 | 47 | // Handle case-insensitivity of interface names. |
48 | - $this->internalInterfaces = $this->arrayKeysToLowercase($this->internalInterfaces); |
|
48 | + $this->internalInterfaces = $this->arrayKeysToLowercase( $this->internalInterfaces ); |
|
49 | 49 | |
50 | - $targets = array(\T_CLASS); |
|
50 | + $targets = array( \T_CLASS ); |
|
51 | 51 | |
52 | - if (\defined('T_ANON_CLASS')) { |
|
53 | - $targets[] = \T_ANON_CLASS; |
|
52 | + if ( \defined( 'T_ANON_CLASS' ) ) { |
|
53 | + $targets[ ] = \T_ANON_CLASS; |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | return $targets; |
@@ -66,26 +66,26 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @return void |
68 | 68 | */ |
69 | - public function process(File $phpcsFile, $stackPtr) |
|
69 | + public function process( File $phpcsFile, $stackPtr ) |
|
70 | 70 | { |
71 | - $interfaces = PHPCSHelper::findImplementedInterfaceNames($phpcsFile, $stackPtr); |
|
71 | + $interfaces = PHPCSHelper::findImplementedInterfaceNames( $phpcsFile, $stackPtr ); |
|
72 | 72 | |
73 | - if (\is_array($interfaces) === false || $interfaces === array()) { |
|
73 | + if ( \is_array( $interfaces ) === false || $interfaces === array() ) { |
|
74 | 74 | return; |
75 | 75 | } |
76 | 76 | |
77 | - foreach ($interfaces as $interface) { |
|
78 | - $interface = ltrim($interface, '\\'); |
|
79 | - $interfaceLc = strtolower($interface); |
|
80 | - if (isset($this->internalInterfaces[$interfaceLc]) === true) { |
|
77 | + foreach ( $interfaces as $interface ) { |
|
78 | + $interface = ltrim( $interface, '\\' ); |
|
79 | + $interfaceLc = strtolower( $interface ); |
|
80 | + if ( isset( $this->internalInterfaces[ $interfaceLc ] ) === true ) { |
|
81 | 81 | $error = 'The interface %s %s'; |
82 | - $errorCode = $this->stringToErrorCode($interfaceLc) . 'Found'; |
|
82 | + $errorCode = $this->stringToErrorCode( $interfaceLc ) . 'Found'; |
|
83 | 83 | $data = array( |
84 | 84 | $interface, |
85 | - $this->internalInterfaces[$interfaceLc], |
|
85 | + $this->internalInterfaces[ $interfaceLc ], |
|
86 | 86 | ); |
87 | 87 | |
88 | - $phpcsFile->addError($error, $stackPtr, $errorCode, $data); |
|
88 | + $phpcsFile->addError( $error, $stackPtr, $errorCode, $data ); |
|
89 | 89 | } |
90 | 90 | } |
91 | 91 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | */ |
37 | 37 | public function register() |
38 | 38 | { |
39 | - $this->isLowPHPVersion = version_compare(\PHP_VERSION_ID, '50400', '<'); |
|
39 | + $this->isLowPHPVersion = version_compare( \PHP_VERSION_ID, '50400', '<' ); |
|
40 | 40 | |
41 | 41 | return array( |
42 | 42 | \T_LNUMBER, // Binary, octal integers. |
@@ -54,34 +54,34 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @return void |
56 | 56 | */ |
57 | - public function process(File $phpcsFile, $stackPtr) |
|
57 | + public function process( File $phpcsFile, $stackPtr ) |
|
58 | 58 | { |
59 | 59 | $tokens = $phpcsFile->getTokens(); |
60 | - $token = $tokens[$stackPtr]; |
|
60 | + $token = $tokens[ $stackPtr ]; |
|
61 | 61 | |
62 | - if ($this->couldBeBinaryInteger($tokens, $stackPtr) === true) { |
|
63 | - if ($this->supportsBelow('5.3')) { |
|
62 | + if ( $this->couldBeBinaryInteger( $tokens, $stackPtr ) === true ) { |
|
63 | + if ( $this->supportsBelow( '5.3' ) ) { |
|
64 | 64 | $error = 'Binary integer literals were not present in PHP version 5.3 or earlier. Found: %s'; |
65 | - if ($this->isLowPHPVersion === false) { |
|
66 | - $data = array($token['content']); |
|
65 | + if ( $this->isLowPHPVersion === false ) { |
|
66 | + $data = array( $token[ 'content' ] ); |
|
67 | 67 | } else { |
68 | - $data = array($this->getBinaryInteger($phpcsFile, $tokens, $stackPtr)); |
|
68 | + $data = array( $this->getBinaryInteger( $phpcsFile, $tokens, $stackPtr ) ); |
|
69 | 69 | } |
70 | - $phpcsFile->addError($error, $stackPtr, 'BinaryIntegerFound', $data); |
|
70 | + $phpcsFile->addError( $error, $stackPtr, 'BinaryIntegerFound', $data ); |
|
71 | 71 | } |
72 | 72 | |
73 | - if ($this->isInvalidBinaryInteger($tokens, $stackPtr) === true) { |
|
73 | + if ( $this->isInvalidBinaryInteger( $tokens, $stackPtr ) === true ) { |
|
74 | 74 | $error = 'Invalid binary integer detected. Found: %s'; |
75 | - $data = array($this->getBinaryInteger($phpcsFile, $tokens, $stackPtr)); |
|
76 | - $phpcsFile->addWarning($error, $stackPtr, 'InvalidBinaryIntegerFound', $data); |
|
75 | + $data = array( $this->getBinaryInteger( $phpcsFile, $tokens, $stackPtr ) ); |
|
76 | + $phpcsFile->addWarning( $error, $stackPtr, 'InvalidBinaryIntegerFound', $data ); |
|
77 | 77 | } |
78 | 78 | return; |
79 | 79 | } |
80 | 80 | |
81 | - $isError = $this->supportsAbove('7.0'); |
|
82 | - $data = array( $token['content'] ); |
|
81 | + $isError = $this->supportsAbove( '7.0' ); |
|
82 | + $data = array( $token[ 'content' ] ); |
|
83 | 83 | |
84 | - if ($this->isInvalidOctalInteger($tokens, $stackPtr) === true) { |
|
84 | + if ( $this->isInvalidOctalInteger( $tokens, $stackPtr ) === true ) { |
|
85 | 85 | $this->addMessage( |
86 | 86 | $phpcsFile, |
87 | 87 | 'Invalid octal integer detected. Prior to PHP 7 this would lead to a truncated number. From PHP 7 onwards this causes a parse error. Found: %s', |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | return; |
94 | 94 | } |
95 | 95 | |
96 | - if ($this->isHexidecimalNumericString($tokens, $stackPtr) === true) { |
|
96 | + if ( $this->isHexidecimalNumericString( $tokens, $stackPtr ) === true ) { |
|
97 | 97 | $this->addMessage( |
98 | 98 | $phpcsFile, |
99 | 99 | 'The behaviour of hexadecimal numeric strings was inconsistent prior to PHP 7 and support has been removed in PHP 7. Found: %s', |
@@ -115,21 +115,21 @@ discard block |
||
115 | 115 | * |
116 | 116 | * @return bool |
117 | 117 | */ |
118 | - private function couldBeBinaryInteger($tokens, $stackPtr) |
|
118 | + private function couldBeBinaryInteger( $tokens, $stackPtr ) |
|
119 | 119 | { |
120 | - $token = $tokens[$stackPtr]; |
|
120 | + $token = $tokens[ $stackPtr ]; |
|
121 | 121 | |
122 | - if ($token['code'] !== \T_LNUMBER) { |
|
122 | + if ( $token[ 'code' ] !== \T_LNUMBER ) { |
|
123 | 123 | return false; |
124 | 124 | } |
125 | 125 | |
126 | - if ($this->isLowPHPVersion === false) { |
|
127 | - return (preg_match('`^0b[0-1]+$`D', $token['content']) === 1); |
|
126 | + if ( $this->isLowPHPVersion === false ) { |
|
127 | + return ( preg_match( '`^0b[0-1]+$`D', $token[ 'content' ] ) === 1 ); |
|
128 | 128 | } |
129 | 129 | // Pre-5.4, binary strings are tokenized as T_LNUMBER (0) + T_STRING ("b01010101"). |
130 | 130 | // At this point, we don't yet care whether it's a valid binary int, that's a separate check. |
131 | 131 | else { |
132 | - return($token['content'] === '0' && $tokens[$stackPtr + 1]['code'] === \T_STRING && preg_match('`^b[0-9]+$`D', $tokens[$stackPtr + 1]['content']) === 1); |
|
132 | + return( $token[ 'content' ] === '0' && $tokens[ $stackPtr + 1 ][ 'code' ] === \T_STRING && preg_match( '`^b[0-9]+$`D', $tokens[ $stackPtr + 1 ][ 'content' ] ) === 1 ); |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | |
@@ -141,17 +141,17 @@ discard block |
||
141 | 141 | * |
142 | 142 | * @return bool |
143 | 143 | */ |
144 | - private function isInvalidBinaryInteger($tokens, $stackPtr) |
|
144 | + private function isInvalidBinaryInteger( $tokens, $stackPtr ) |
|
145 | 145 | { |
146 | - if ($this->couldBeBinaryInteger($tokens, $stackPtr) === false) { |
|
146 | + if ( $this->couldBeBinaryInteger( $tokens, $stackPtr ) === false ) { |
|
147 | 147 | return false; |
148 | 148 | } |
149 | 149 | |
150 | - if ($this->isLowPHPVersion === false) { |
|
150 | + if ( $this->isLowPHPVersion === false ) { |
|
151 | 151 | // If it's an invalid binary int, the token will be split into two T_LNUMBER tokens. |
152 | - return ($tokens[$stackPtr + 1]['code'] === \T_LNUMBER); |
|
152 | + return ( $tokens[ $stackPtr + 1 ][ 'code' ] === \T_LNUMBER ); |
|
153 | 153 | } else { |
154 | - return (preg_match('`^b[0-1]+$`D', $tokens[$stackPtr + 1]['content']) === 0); |
|
154 | + return ( preg_match( '`^b[0-1]+$`D', $tokens[ $stackPtr + 1 ][ 'content' ] ) === 0 ); |
|
155 | 155 | } |
156 | 156 | } |
157 | 157 | |
@@ -165,19 +165,19 @@ discard block |
||
165 | 165 | * |
166 | 166 | * @return string |
167 | 167 | */ |
168 | - private function getBinaryInteger(File $phpcsFile, $tokens, $stackPtr) |
|
168 | + private function getBinaryInteger( File $phpcsFile, $tokens, $stackPtr ) |
|
169 | 169 | { |
170 | 170 | $length = 2; // PHP < 5.4 T_LNUMBER + T_STRING. |
171 | 171 | |
172 | - if ($this->isLowPHPVersion === false) { |
|
172 | + if ( $this->isLowPHPVersion === false ) { |
|
173 | 173 | $i = $stackPtr; |
174 | - while ($tokens[$i]['code'] === \T_LNUMBER) { |
|
174 | + while ( $tokens[ $i ][ 'code' ] === \T_LNUMBER ) { |
|
175 | 175 | $i++; |
176 | 176 | } |
177 | - $length = ($i - $stackPtr); |
|
177 | + $length = ( $i - $stackPtr ); |
|
178 | 178 | } |
179 | 179 | |
180 | - return $phpcsFile->getTokensAsString($stackPtr, $length); |
|
180 | + return $phpcsFile->getTokensAsString( $stackPtr, $length ); |
|
181 | 181 | } |
182 | 182 | |
183 | 183 | /** |
@@ -188,11 +188,11 @@ discard block |
||
188 | 188 | * |
189 | 189 | * @return bool |
190 | 190 | */ |
191 | - private function isInvalidOctalInteger($tokens, $stackPtr) |
|
191 | + private function isInvalidOctalInteger( $tokens, $stackPtr ) |
|
192 | 192 | { |
193 | - $token = $tokens[$stackPtr]; |
|
193 | + $token = $tokens[ $stackPtr ]; |
|
194 | 194 | |
195 | - if ($token['code'] === \T_LNUMBER && preg_match('`^0[0-7]*[8-9]+[0-9]*$`D', $token['content']) === 1) { |
|
195 | + if ( $token[ 'code' ] === \T_LNUMBER && preg_match( '`^0[0-7]*[8-9]+[0-9]*$`D', $token[ 'content' ] ) === 1 ) { |
|
196 | 196 | return true; |
197 | 197 | } |
198 | 198 | |
@@ -207,11 +207,11 @@ discard block |
||
207 | 207 | * |
208 | 208 | * @return bool |
209 | 209 | */ |
210 | - private function isHexidecimalNumericString($tokens, $stackPtr) |
|
210 | + private function isHexidecimalNumericString( $tokens, $stackPtr ) |
|
211 | 211 | { |
212 | - $token = $tokens[$stackPtr]; |
|
212 | + $token = $tokens[ $stackPtr ]; |
|
213 | 213 | |
214 | - if ($token['code'] === \T_CONSTANT_ENCAPSED_STRING && preg_match('`^0x[a-f0-9]+$`iD', $this->stripQuotes($token['content'])) === 1) { |
|
214 | + if ( $token[ 'code' ] === \T_CONSTANT_ENCAPSED_STRING && preg_match( '`^0x[a-f0-9]+$`iD', $this->stripQuotes( $token[ 'content' ] ) ) === 1 ) { |
|
215 | 215 | return true; |
216 | 216 | } |
217 | 217 |
@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function register() |
47 | 47 | { |
48 | - if (version_compare(\PHP_VERSION_ID, '70000', '<') === true) { |
|
48 | + if ( version_compare( \PHP_VERSION_ID, '70000', '<' ) === true ) { |
|
49 | 49 | // phpcs:ignore PHPCompatibility.IniDirectives.RemovedIniDirectives.asp_tagsRemoved |
50 | - $this->aspTags = (bool) ini_get('asp_tags'); |
|
50 | + $this->aspTags = (bool)ini_get( 'asp_tags' ); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | return array( |
@@ -67,30 +67,30 @@ discard block |
||
67 | 67 | * |
68 | 68 | * @return void |
69 | 69 | */ |
70 | - public function process(File $phpcsFile, $stackPtr) |
|
70 | + public function process( File $phpcsFile, $stackPtr ) |
|
71 | 71 | { |
72 | - if ($this->supportsAbove('7.0') === false) { |
|
72 | + if ( $this->supportsAbove( '7.0' ) === false ) { |
|
73 | 73 | return; |
74 | 74 | } |
75 | 75 | |
76 | 76 | $tokens = $phpcsFile->getTokens(); |
77 | - $openTag = $tokens[$stackPtr]; |
|
78 | - $content = trim($openTag['content']); |
|
77 | + $openTag = $tokens[ $stackPtr ]; |
|
78 | + $content = trim( $openTag[ 'content' ] ); |
|
79 | 79 | |
80 | - if ($content === '' || $content === '<?php') { |
|
80 | + if ( $content === '' || $content === '<?php' ) { |
|
81 | 81 | return; |
82 | 82 | } |
83 | 83 | |
84 | - if ($openTag['code'] === \T_OPEN_TAG || $openTag['code'] === \T_OPEN_TAG_WITH_ECHO) { |
|
84 | + if ( $openTag[ 'code' ] === \T_OPEN_TAG || $openTag[ 'code' ] === \T_OPEN_TAG_WITH_ECHO ) { |
|
85 | 85 | |
86 | - if ($content === '<%' || $content === '<%=') { |
|
87 | - $data = array( |
|
86 | + if ( $content === '<%' || $content === '<%=' ) { |
|
87 | + $data = array( |
|
88 | 88 | 'ASP', |
89 | 89 | $content, |
90 | 90 | ); |
91 | 91 | $errorCode = 'ASPOpenTagFound'; |
92 | 92 | |
93 | - } elseif (strpos($content, '<script ') !== false) { |
|
93 | + } elseif ( strpos( $content, '<script ' ) !== false ) { |
|
94 | 94 | $data = array( |
95 | 95 | 'Script', |
96 | 96 | $content, |
@@ -102,10 +102,10 @@ discard block |
||
102 | 102 | } |
103 | 103 | // Account for incorrect script open tags. |
104 | 104 | // The "(?:<s)?" in the regex is to work-around a bug in the tokenizer in PHP 5.2. |
105 | - elseif ($openTag['code'] === \T_INLINE_HTML |
|
106 | - && preg_match('`((?:<s)?cript (?:[^>]+)?language=[\'"]?php[\'"]?(?:[^>]+)?>)`i', $content, $match) === 1 |
|
105 | + elseif ( $openTag[ 'code' ] === \T_INLINE_HTML |
|
106 | + && preg_match( '`((?:<s)?cript (?:[^>]+)?language=[\'"]?php[\'"]?(?:[^>]+)?>)`i', $content, $match ) === 1 |
|
107 | 107 | ) { |
108 | - $found = $match[1]; |
|
108 | + $found = $match[ 1 ]; |
|
109 | 109 | $data = array( |
110 | 110 | 'Script', |
111 | 111 | $found, |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | $errorCode = 'ScriptOpenTagFound'; |
114 | 114 | } |
115 | 115 | |
116 | - if (isset($errorCode, $data)) { |
|
116 | + if ( isset( $errorCode, $data ) ) { |
|
117 | 117 | $phpcsFile->addError( |
118 | 118 | '%s style opening tags have been removed in PHP 7.0. Found "%s"', |
119 | 119 | $stackPtr, |
@@ -124,13 +124,13 @@ discard block |
||
124 | 124 | } |
125 | 125 | |
126 | 126 | // If we're still here, we can't be sure if what we find was really intended as ASP open tags. |
127 | - if ($openTag['code'] === \T_INLINE_HTML && $this->aspTags === false) { |
|
128 | - if (strpos($content, '<%') !== false) { |
|
127 | + if ( $openTag[ 'code' ] === \T_INLINE_HTML && $this->aspTags === false ) { |
|
128 | + if ( strpos( $content, '<%' ) !== false ) { |
|
129 | 129 | $error = 'Possible use of ASP style opening tags detected. ASP style opening tags have been removed in PHP 7.0. Found: %s'; |
130 | - $snippet = $this->getSnippet($content, '<%'); |
|
131 | - $data = array('<%' . $snippet); |
|
130 | + $snippet = $this->getSnippet( $content, '<%' ); |
|
131 | + $data = array( '<%' . $snippet ); |
|
132 | 132 | |
133 | - $phpcsFile->addWarning($error, $stackPtr, 'MaybeASPOpenTagFound', $data); |
|
133 | + $phpcsFile->addWarning( $error, $stackPtr, 'MaybeASPOpenTagFound', $data ); |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 | } |
@@ -145,19 +145,19 @@ discard block |
||
145 | 145 | * |
146 | 146 | * @return string |
147 | 147 | */ |
148 | - protected function getSnippet($content, $startAt = '', $length = 25) |
|
148 | + protected function getSnippet( $content, $startAt = '', $length = 25 ) |
|
149 | 149 | { |
150 | 150 | $startPos = 0; |
151 | 151 | |
152 | - if ($startAt !== '') { |
|
153 | - $startPos = strpos($content, $startAt); |
|
154 | - if ($startPos !== false) { |
|
155 | - $startPos += \strlen($startAt); |
|
152 | + if ( $startAt !== '' ) { |
|
153 | + $startPos = strpos( $content, $startAt ); |
|
154 | + if ( $startPos !== false ) { |
|
155 | + $startPos += \strlen( $startAt ); |
|
156 | 156 | } |
157 | 157 | } |
158 | 158 | |
159 | - $snippet = substr($content, $startPos, $length); |
|
160 | - if ((\strlen($content) - $startPos) > $length) { |
|
159 | + $snippet = substr( $content, $startPos, $length ); |
|
160 | + if ( ( \strlen( $content ) - $startPos ) > $length ) { |
|
161 | 161 | $snippet .= '...'; |
162 | 162 | } |
163 | 163 |
@@ -63,14 +63,14 @@ discard block |
||
63 | 63 | * For PHP 5.5+ we need to look for T_YIELD. |
64 | 64 | * For PHPCS 3.1.0+, we also need to look for T_YIELD_FROM. |
65 | 65 | */ |
66 | - if (version_compare(\PHP_VERSION_ID, '50500', '<') === true |
|
67 | - && version_compare(PHPCSHelper::getVersion(), '3.1.0', '<') === true |
|
66 | + if ( version_compare( \PHP_VERSION_ID, '50500', '<' ) === true |
|
67 | + && version_compare( PHPCSHelper::getVersion(), '3.1.0', '<' ) === true |
|
68 | 68 | ) { |
69 | - $targets[] = \T_STRING; |
|
69 | + $targets[ ] = \T_STRING; |
|
70 | 70 | } |
71 | 71 | |
72 | - if (\defined('T_YIELD_FROM')) { |
|
73 | - $targets[] = \T_YIELD_FROM; |
|
72 | + if ( \defined( 'T_YIELD_FROM' ) ) { |
|
73 | + $targets[ ] = \T_YIELD_FROM; |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | return $targets; |
@@ -85,69 +85,69 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @return void|int Void or a stack pointer to skip forward. |
87 | 87 | */ |
88 | - public function process(File $phpcsFile, $stackPtr) |
|
88 | + public function process( File $phpcsFile, $stackPtr ) |
|
89 | 89 | { |
90 | - if ($this->supportsBelow('5.6') !== true) { |
|
90 | + if ( $this->supportsBelow( '5.6' ) !== true ) { |
|
91 | 91 | return; |
92 | 92 | } |
93 | 93 | |
94 | 94 | $tokens = $phpcsFile->getTokens(); |
95 | 95 | |
96 | - if ($tokens[$stackPtr]['code'] === \T_STRING |
|
97 | - && $tokens[$stackPtr]['content'] !== 'yield' |
|
96 | + if ( $tokens[ $stackPtr ][ 'code' ] === \T_STRING |
|
97 | + && $tokens[ $stackPtr ][ 'content' ] !== 'yield' |
|
98 | 98 | ) { |
99 | 99 | return; |
100 | 100 | } |
101 | 101 | |
102 | - if (empty($tokens[$stackPtr]['conditions']) === true) { |
|
102 | + if ( empty( $tokens[ $stackPtr ][ 'conditions' ] ) === true ) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | // Walk the condition from inner to outer to see if we can find a valid function/closure scope. |
107 | - $conditions = array_reverse($tokens[$stackPtr]['conditions'], true); |
|
108 | - foreach ($conditions as $ptr => $type) { |
|
109 | - if (isset($this->validConditions[$type]) === true) { |
|
107 | + $conditions = array_reverse( $tokens[ $stackPtr ][ 'conditions' ], true ); |
|
108 | + foreach ( $conditions as $ptr => $type ) { |
|
109 | + if ( isset( $this->validConditions[ $type ] ) === true ) { |
|
110 | 110 | $function = $ptr; |
111 | 111 | break; |
112 | 112 | } |
113 | 113 | } |
114 | 114 | |
115 | - if (isset($function) === false) { |
|
115 | + if ( isset( $function ) === false ) { |
|
116 | 116 | // Yield outside function scope, fatal error, but not our concern. |
117 | 117 | return; |
118 | 118 | } |
119 | 119 | |
120 | - if (isset($tokens[$function]['scope_opener'], $tokens[$function]['scope_closer']) === false) { |
|
120 | + if ( isset( $tokens[ $function ][ 'scope_opener' ], $tokens[ $function ][ 'scope_closer' ] ) === false ) { |
|
121 | 121 | // Can't reliably determine start/end of function scope. |
122 | 122 | return; |
123 | 123 | } |
124 | 124 | |
125 | - $targets = array(\T_RETURN, \T_CLOSURE, \T_FUNCTION, \T_CLASS); |
|
126 | - if (\defined('T_ANON_CLASS')) { |
|
127 | - $targets[] = \T_ANON_CLASS; |
|
125 | + $targets = array( \T_RETURN, \T_CLOSURE, \T_FUNCTION, \T_CLASS ); |
|
126 | + if ( \defined( 'T_ANON_CLASS' ) ) { |
|
127 | + $targets[ ] = \T_ANON_CLASS; |
|
128 | 128 | } |
129 | 129 | |
130 | - $current = $tokens[$function]['scope_opener']; |
|
130 | + $current = $tokens[ $function ][ 'scope_opener' ]; |
|
131 | 131 | |
132 | - while (($current = $phpcsFile->findNext($targets, ($current + 1), $tokens[$function]['scope_closer'])) !== false) { |
|
133 | - if ($tokens[$current]['code'] === \T_RETURN) { |
|
132 | + while ( ( $current = $phpcsFile->findNext( $targets, ( $current + 1 ), $tokens[ $function ][ 'scope_closer' ] ) ) !== false ) { |
|
133 | + if ( $tokens[ $current ][ 'code' ] === \T_RETURN ) { |
|
134 | 134 | $phpcsFile->addError( |
135 | 135 | 'Returning a final expression from a generator was not supported in PHP 5.6 or earlier', |
136 | 136 | $current, |
137 | 137 | 'ReturnFound' |
138 | 138 | ); |
139 | 139 | |
140 | - return $tokens[$function]['scope_closer']; |
|
140 | + return $tokens[ $function ][ 'scope_closer' ]; |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | // Found a nested scope in which return can exist without problems. |
144 | - if (isset($tokens[$current]['scope_closer'])) { |
|
144 | + if ( isset( $tokens[ $current ][ 'scope_closer' ] ) ) { |
|
145 | 145 | // Skip past the nested scope. |
146 | - $current = $tokens[$current]['scope_closer']; |
|
146 | + $current = $tokens[ $current ][ 'scope_closer' ]; |
|
147 | 147 | } |
148 | 148 | } |
149 | 149 | |
150 | 150 | // Don't examine this function again. |
151 | - return $tokens[$function]['scope_closer']; |
|
151 | + return $tokens[ $function ][ 'scope_closer' ]; |
|
152 | 152 | } |
153 | 153 | } |
@@ -54,16 +54,16 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @return void |
56 | 56 | */ |
57 | - public function process(File $phpcsFile, $stackPtr) |
|
57 | + public function process( File $phpcsFile, $stackPtr ) |
|
58 | 58 | { |
59 | - if ($this->supportsAbove('5.3') === false) { |
|
59 | + if ( $this->supportsAbove( '5.3' ) === false ) { |
|
60 | 60 | return; |
61 | 61 | } |
62 | 62 | |
63 | 63 | $tokens = $phpcsFile->getTokens(); |
64 | 64 | |
65 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); |
|
66 | - if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_STRING) { |
|
65 | + $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); |
|
66 | + if ( $nextNonEmpty === false || $tokens[ $nextNonEmpty ][ 'code' ] !== \T_STRING ) { |
|
67 | 67 | /* |
68 | 68 | * Not a method call. |
69 | 69 | * |
@@ -75,19 +75,19 @@ discard block |
||
75 | 75 | return; |
76 | 76 | } |
77 | 77 | |
78 | - if (strtolower($tokens[$nextNonEmpty]['content']) !== '__tostring') { |
|
78 | + if ( strtolower( $tokens[ $nextNonEmpty ][ 'content' ] ) !== '__tostring' ) { |
|
79 | 79 | // Not a call to the __clone() method. |
80 | 80 | return; |
81 | 81 | } |
82 | 82 | |
83 | - $openParens = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextNonEmpty + 1), null, true); |
|
84 | - if ($openParens === false || $tokens[$openParens]['code'] !== \T_OPEN_PARENTHESIS) { |
|
83 | + $openParens = $phpcsFile->findNext( Tokens::$emptyTokens, ( $nextNonEmpty + 1 ), null, true ); |
|
84 | + if ( $openParens === false || $tokens[ $openParens ][ 'code' ] !== \T_OPEN_PARENTHESIS ) { |
|
85 | 85 | // Not a method call. |
86 | 86 | return; |
87 | 87 | } |
88 | 88 | |
89 | - $closeParens = $phpcsFile->findNext(Tokens::$emptyTokens, ($openParens + 1), null, true); |
|
90 | - if ($closeParens === false || $tokens[$closeParens]['code'] === \T_CLOSE_PARENTHESIS) { |
|
89 | + $closeParens = $phpcsFile->findNext( Tokens::$emptyTokens, ( $openParens + 1 ), null, true ); |
|
90 | + if ( $closeParens === false || $tokens[ $closeParens ][ 'code' ] === \T_CLOSE_PARENTHESIS ) { |
|
91 | 91 | // Not a method call. |
92 | 92 | return; |
93 | 93 | } |
@@ -56,16 +56,16 @@ discard block |
||
56 | 56 | * |
57 | 57 | * @return void |
58 | 58 | */ |
59 | - public function process(File $phpcsFile, $stackPtr) |
|
59 | + public function process( File $phpcsFile, $stackPtr ) |
|
60 | 60 | { |
61 | - if ($this->supportsBelow('5.6') === false) { |
|
61 | + if ( $this->supportsBelow( '5.6' ) === false ) { |
|
62 | 62 | return; |
63 | 63 | } |
64 | 64 | |
65 | 65 | $tokens = $phpcsFile->getTokens(); |
66 | 66 | |
67 | - $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); |
|
68 | - if ($nextNonEmpty === false || $tokens[$nextNonEmpty]['code'] !== \T_STRING) { |
|
67 | + $nextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $stackPtr + 1 ), null, true ); |
|
68 | + if ( $nextNonEmpty === false || $tokens[ $nextNonEmpty ][ 'code' ] !== \T_STRING ) { |
|
69 | 69 | /* |
70 | 70 | * Not a method call. |
71 | 71 | * |
@@ -77,13 +77,13 @@ discard block |
||
77 | 77 | return; |
78 | 78 | } |
79 | 79 | |
80 | - if (strtolower($tokens[$nextNonEmpty]['content']) !== '__clone') { |
|
80 | + if ( strtolower( $tokens[ $nextNonEmpty ][ 'content' ] ) !== '__clone' ) { |
|
81 | 81 | // Not a call to the __clone() method. |
82 | 82 | return; |
83 | 83 | } |
84 | 84 | |
85 | - $nextNextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($nextNonEmpty + 1), null, true); |
|
86 | - if ($nextNextNonEmpty === false || $tokens[$nextNextNonEmpty]['code'] !== \T_OPEN_PARENTHESIS) { |
|
85 | + $nextNextNonEmpty = $phpcsFile->findNext( Tokens::$emptyTokens, ( $nextNonEmpty + 1 ), null, true ); |
|
86 | + if ( $nextNextNonEmpty === false || $tokens[ $nextNextNonEmpty ][ 'code' ] !== \T_OPEN_PARENTHESIS ) { |
|
87 | 87 | // Not a method call. |
88 | 88 | return; |
89 | 89 | } |