-
-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor BetterNodeFinder::findFirstInFunctionLikeScoped() to work wi…
…th SilentVoidResolver (#4931) * Refactor findFirstInFunctionLikeScoped * Fix
- Loading branch information
1 parent
54799fc
commit fa28385
Showing
2 changed files
with
14 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -246,7 +246,7 @@ public function findFirstInFunctionLikeScoped( | |
$scopedNode = null; | ||
$this->simpleCallableNodeTraverser->traverseNodesWithCallable( | ||
$functionLike->stmts, | ||
static function (Node $subNode) use (&$scopedNode, $foundNode): ?int { | ||
function (Node $subNode) use (&$scopedNode, $foundNode, $filter): ?int { | ||
if ($subNode instanceof Class_ || $subNode instanceof Function_ || $subNode instanceof Closure) { | ||
if ($foundNode instanceof $subNode && $subNode === $foundNode) { | ||
$scopedNode = $subNode; | ||
|
@@ -256,7 +256,14 @@ static function (Node $subNode) use (&$scopedNode, $foundNode): ?int { | |
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; | ||
} | ||
|
||
if ($foundNode instanceof $subNode && $subNode === $foundNode) { | ||
if (! $foundNode instanceof $subNode) { | ||
return null; | ||
} | ||
|
||
// handle after Closure | ||
// @see https://github.com/rectorphp/rector-src/pull/4931 | ||
$scopedFoundNode = $this->findFirst($subNode, $filter); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
samsonasik
Author
Member
|
||
if ($scopedFoundNode === $subNode) { | ||
$scopedNode = $subNode; | ||
return NodeTraverser::STOP_TRAVERSAL; | ||
} | ||
|
I am not sure this is a good idea. doesn't it mean on every
findFirstInFunctionLikeScoped
invocatin, we will traverse the AST twice now?I think we should instead not do the "optimization" in
SilentVoidResolver
when it requires an additional AST traversal for all operations in the system and revertSilentVoidResolver
to what we had before then