Skip to content

Commit

Permalink
PHPCS 4.x | File::isReference(): simplify code
Browse files Browse the repository at this point in the history
Commit 08824f3 added support for `T_USE` tokens for closures being parentheses owners.

As the `File::getMethodParameters()` method also supports closure `use` parameters already, the code in the `File::isReference()` method can now be simplified.

The existing unit tests already cover this.
  • Loading branch information
jrfnl committed Dec 7, 2023
1 parent a949e13 commit 573d41d
Showing 1 changed file with 1 addition and 13 deletions.
14 changes: 1 addition & 13 deletions src/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -2061,6 +2061,7 @@ public function isReference($stackPtr)
if ($owner['code'] === T_FUNCTION
|| $owner['code'] === T_CLOSURE
|| $owner['code'] === T_FN
|| $owner['code'] === T_USE
) {
$params = $this->getMethodParameters($this->tokens[$lastBracket]['parenthesis_owner']);
foreach ($params as $param) {
Expand All @@ -2070,19 +2071,6 @@ public function isReference($stackPtr)
}
}
}//end if
} else {
$prev = false;
for ($t = ($this->tokens[$lastBracket]['parenthesis_opener'] - 1); $t >= 0; $t--) {
if ($this->tokens[$t]['code'] !== T_WHITESPACE) {
$prev = $t;
break;
}
}

if ($prev !== false && $this->tokens[$prev]['code'] === T_USE) {
// Closure use by reference.
return true;
}
}//end if
}//end if

Expand Down

0 comments on commit 573d41d

Please sign in to comment.