From ed3e3225939a1a78e2306d032aebd5cdbb173ffb Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 29 Sep 2024 15:59:25 +0700 Subject: [PATCH] [PhpParser] Use general FunctionLike instanceof check for inner scope check on BetterNodeFinder --- src/PhpParser/Node/BetterNodeFinder.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/PhpParser/Node/BetterNodeFinder.php b/src/PhpParser/Node/BetterNodeFinder.php index 41c47c6c2b..9381ae24f8 100644 --- a/src/PhpParser/Node/BetterNodeFinder.php +++ b/src/PhpParser/Node/BetterNodeFinder.php @@ -5,11 +5,11 @@ namespace Rector\PhpParser\Node; use PhpParser\Node; -use PhpParser\Node\Expr\ArrowFunction; use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Expr\Yield_; use PhpParser\Node\Expr\YieldFrom; +use PhpParser\Node\FunctionLike; use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; @@ -171,7 +171,7 @@ public function hasInstancesOfInFunctionLikeScoped( $this->simpleCallableNodeTraverser->traverseNodesWithCallable( (array) $functionLike->stmts, static function (Node $subNode) use ($types, &$isFoundNode): ?int { - if ($subNode instanceof Class_ || $subNode instanceof Function_ || $subNode instanceof Closure || $subNode instanceof ArrowFunction) { + if ($subNode instanceof Class_ || $subNode instanceof FunctionLike) { return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; } @@ -199,7 +199,7 @@ public function findReturnsScoped(ClassMethod | Function_ | Closure $functionLik $this->simpleCallableNodeTraverser->traverseNodesWithCallable( (array) $functionLike->stmts, function (Node $subNode) use (&$returns): ?int { - if ($subNode instanceof Class_ || $subNode instanceof Function_ || $subNode instanceof Closure) { + if ($subNode instanceof Class_ || $subNode instanceof FunctionLike) { return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; } @@ -233,8 +233,8 @@ public function findInstancesOfScoped(array $nodes, string|array $types): array { // here verify only pass single nodes as FunctionLike if (count($nodes) === 1 - && ($nodes[0] instanceof ClassMethod || $nodes[0] instanceof Function_ || $nodes[0] instanceof Closure)) { - $nodes = (array) $nodes[0]->stmts; + && ($nodes[0] instanceof FunctionLike)) { + $nodes = (array) $nodes[0]->getStmts(); } if (is_string($types)) { @@ -247,7 +247,7 @@ public function findInstancesOfScoped(array $nodes, string|array $types): array $this->simpleCallableNodeTraverser->traverseNodesWithCallable( $nodes, static function (Node $subNode) use ($types, &$foundNodes): ?int { - if ($subNode instanceof Class_ || $subNode instanceof Function_ || $subNode instanceof Closure || $subNode instanceof ArrowFunction) { + if ($subNode instanceof Class_ || $subNode instanceof FunctionLike) { return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; } @@ -293,7 +293,7 @@ public function findFirstInFunctionLikeScoped( return null; } - if (! $this->hasInstancesOf($functionLike->stmts, [Class_::class, Function_::class, Closure::class])) { + if (! $this->hasInstancesOf($functionLike->stmts, [Class_::class, FunctionLike::class])) { return $foundNode; } @@ -301,7 +301,7 @@ public function findFirstInFunctionLikeScoped( $this->simpleCallableNodeTraverser->traverseNodesWithCallable( $functionLike->stmts, function (Node $subNode) use (&$scopedNode, $foundNode, $filter): ?int { - if ($subNode instanceof Class_ || $subNode instanceof Function_ || $subNode instanceof Closure) { + if ($subNode instanceof Class_ || $subNode instanceof FunctionLike) { if ($foundNode instanceof $subNode && $subNode === $foundNode) { $scopedNode = $subNode; return NodeTraverser::STOP_TRAVERSAL;