From 553c4b141b62244f629b22fe7e8054196cd73a58 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Thu, 13 Jul 2023 09:11:16 +0200 Subject: [PATCH] Fix result cache bug with imported type aliases --- src/Dependency/DependencyResolver.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Dependency/DependencyResolver.php b/src/Dependency/DependencyResolver.php index 9a8d0b95ac..deba626f86 100644 --- a/src/Dependency/DependencyResolver.php +++ b/src/Dependency/DependencyResolver.php @@ -14,6 +14,7 @@ use PHPStan\File\FileHelper; use PHPStan\Node\ClassPropertyNode; use PHPStan\Node\InClassMethodNode; +use PHPStan\Node\InClassNode; use PHPStan\Node\InFunctionNode; use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\FunctionReflection; @@ -44,6 +45,22 @@ public function resolveDependencies(Node $node, Scope $scope): NodeDependencies { $dependenciesReflections = []; + if ($node instanceof InClassNode) { + $docComment = $node->getDocComment(); + if ($docComment !== null) { + $phpDoc = $this->fileTypeMapper->getResolvedPhpDoc( + $scope->getFile(), + $scope->isInClass() ? $scope->getClassReflection()->getName() : null, + $scope->isInTrait() ? $scope->getTraitReflection()->getName() : null, + null, + $docComment->getText(), + ); + foreach ($phpDoc->getTypeAliasImportTags() as $importTag) { + $this->addClassToDependencies($importTag->getImportedFrom(), $dependenciesReflections); + } + } + } + if ($node instanceof Node\Stmt\Class_) { if ($node->namespacedName !== null) { $this->addClassToDependencies($node->namespacedName->toString(), $dependenciesReflections);