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 Nov 11, 2023
1 parent 7027990 commit fd448c0
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 @@ -2024,6 +2024,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 @@ -2033,19 +2034,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 fd448c0

Please sign in to comment.