diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index e1f158a2c28..f74bc71e9f1 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = 'df255c0db4dbfce78ad3fc5bbdb9997490c2ec6d'; + public const PACKAGE_VERSION = '69c22013f6d127aca89b2c18070a4e27119d94bf'; /** * @api * @var string */ - public const RELEASE_DATE = '2024-12-20 14:23:58'; + public const RELEASE_DATE = '2024-12-20 14:29:40'; /** * @var int */ diff --git a/src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ByRefReturnNodeVisitor.php b/src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ByRefReturnNodeVisitor.php index e47fdfc074e..e18714fe1bc 100644 --- a/src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ByRefReturnNodeVisitor.php +++ b/src/NodeTypeResolver/PHPStan/Scope/NodeVisitor/ByRefReturnNodeVisitor.php @@ -5,15 +5,23 @@ namespace Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor; use PhpParser\Node; use PhpParser\Node\FunctionLike; -use PhpParser\Node\Stmt; +use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\Return_; -use PhpParser\Node\Stmt\Switch_; +use PhpParser\NodeVisitor; use PhpParser\NodeVisitorAbstract; -use Rector\Contract\PhpParser\Node\StmtsAwareInterface; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\NodeTypeResolver\PHPStan\Scope\Contract\NodeVisitor\ScopeResolverNodeVisitorInterface; +use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser; final class ByRefReturnNodeVisitor extends NodeVisitorAbstract implements ScopeResolverNodeVisitorInterface { + /** + * @readonly + */ + private SimpleCallableNodeTraverser $simpleCallableNodeTraverser; + public function __construct(SimpleCallableNodeTraverser $simpleCallableNodeTraverser) + { + $this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser; + } public function enterNode(Node $node) : ?Node { if (!$node instanceof FunctionLike) { @@ -26,31 +34,16 @@ final class ByRefReturnNodeVisitor extends NodeVisitorAbstract implements ScopeR if ($stmts === null) { return null; } - $this->setByRefAttribute($stmts); + $this->simpleCallableNodeTraverser->traverseNodesWithCallable($stmts, static function (Node $node) { + if ($node instanceof Class_ || $node instanceof FunctionLike) { + return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN; + } + if (!$node instanceof Return_) { + return null; + } + $node->setAttribute(AttributeKey::IS_BYREF_RETURN, \true); + return $node; + }); return null; } - /** - * @param Stmt[] $stmts - */ - private function setByRefAttribute(array $stmts) : void - { - foreach ($stmts as $stmt) { - if ($stmt instanceof FunctionLike) { - continue; - } - if ($stmt instanceof StmtsAwareInterface && $stmt->stmts !== null) { - $this->setByRefAttribute($stmt->stmts); - continue; - } - if ($stmt instanceof Switch_) { - foreach ($stmt->cases as $case) { - $this->setByRefAttribute($case->stmts); - } - continue; - } - if ($stmt instanceof Return_) { - $stmt->setAttribute(AttributeKey::IS_BYREF_RETURN, \true); - } - } - } }