Skip to content

Commit 90012de

Browse files
authored
[perf] Skip scope fetch in RemoveUnusedNonEmptyArrayBeforeForeachRector unless if-with-only-foreach (#8581)
1 parent ccb3f43 commit 90012de

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

‎rules/DeadCode/Rector/If_/RemoveUnusedNonEmptyArrayBeforeForeachRector.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ public function getNodeTypes(): array
9393
public function refactor(Node $node): Node|null
9494
{
9595
if ($node instanceof If_) {
96+
// cheap structural bail before pulling the scope
97+
if (! $this->ifManipulator->isIfWithOnly($node, Foreach_::class)) {
98+
return null;
99+
}
100+
96101
$scope = ScopeFetcher::fetch($node);
97102
return $this->refactorIf($node, $scope);
98103
}

0 commit comments

Comments
 (0)