Skip to content

Commit

Permalink
PHPCS 4.x | BCFile::getMethodParameters(): T_USE is now a parenthesis…
Browse files Browse the repository at this point in the history
… owner

`T_USE` tokens used for closure use statements are parentheses owners as of PHPCS 4.x.

This fixes compatibility of the `BCFile::getMethodParameters()` method with PHPCS 4.x.

The existing unit tests already cover this.

Refs:
* squizlabs/PHP_CodeSniffer 2593
* squizlabs/PHP_CodeSniffer@08824f3
* squizlabs/PHP_CodeSniffer 3104
  • Loading branch information
jrfnl committed May 12, 2021
1 parent 6e377c0 commit ff705f0
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion PHPCSUtils/BackCompat/BCFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,11 @@ public static function getMethodParameters(File $phpcsFile, $stackPtr)

if ($tokens[$stackPtr]['code'] === T_USE) {
$opener = $phpcsFile->findNext(T_OPEN_PARENTHESIS, ($stackPtr + 1));
if ($opener === false || isset($tokens[$opener]['parenthesis_owner']) === true) {
if ($opener === false
|| (isset($tokens[$opener]['parenthesis_owner']) === true
// BC: as of PHPCS 4.x, closure use tokens are parentheses owners.
&& $tokens[$opener]['parenthesis_owner'] !== $stackPtr)
) {
throw new RuntimeException('$stackPtr was not a valid T_USE');
}
} elseif ($arrowOpenClose !== false) {
Expand Down

0 comments on commit ff705f0

Please sign in to comment.