|
3 | 3 | namespace PHPStan\Reflection;
|
4 | 4 |
|
5 | 5 | use Attribute;
|
| 6 | +use PHPStan\Analyser\NameScope; |
6 | 7 | use PHPStan\BetterReflection\Reflection\Adapter\ReflectionClass;
|
7 | 8 | use PHPStan\Php\PhpVersion;
|
8 | 9 | use PHPStan\PhpDoc\ResolvedPhpDocBlock;
|
|
23 | 24 | use PHPStan\Type\Generic\TemplateTypeHelper;
|
24 | 25 | use PHPStan\Type\Generic\TemplateTypeMap;
|
25 | 26 | use PHPStan\Type\Generic\TemplateTypeScope;
|
26 | | -use PHPStan\Type\ObjectType; |
27 | 27 | use PHPStan\Type\Type;
|
28 | 28 | use PHPStan\Type\TypeAlias;
|
29 | 29 | use PHPStan\Type\VerbosityLevel;
|
@@ -776,22 +776,19 @@ public function getTypeAliases(): array
|
776 | 776 | $typeAliasImportTags = $resolvedPhpDoc->getTypeAliasImportTags();
|
777 | 777 | $typeAliasTags = $resolvedPhpDoc->getTypeAliasTags();
|
778 | 778 |
|
| 779 | + $nameScope = $resolvedPhpDoc->getNullableNameScope() ?? new NameScope(null, []); |
| 780 | + |
779 | 781 | // prevent circular imports
|
780 | 782 | if (array_key_exists($this->getName(), self::$resolvingTypeAliasImports)) {
|
781 | 783 | throw new \PHPStan\Type\CircularTypeAliasDefinitionException();
|
782 | 784 | }
|
783 | 785 |
|
784 | 786 | self::$resolvingTypeAliasImports[$this->getName()] = true;
|
785 | 787 |
|
786 | | - $importedAliases = array_map(function (TypeAliasImportTag $typeAliasImportTag): ?TypeAlias { |
| 788 | + $importedAliases = array_map(function (TypeAliasImportTag $typeAliasImportTag)use ($nameScope): ?TypeAlias { |
787 | 789 | $importedAlias = $typeAliasImportTag->getImportedAlias();
|
788 | | - $importedFrom = $typeAliasImportTag->getImportedFrom(); |
789 | | - |
790 | | - if (!($importedFrom instanceof ObjectType)) { |
791 | | - return null; |
792 | | - } |
| 790 | + $importedFromClassName = $nameScope->resolveStringName($typeAliasImportTag->getImportedFrom()); |
793 | 791 |
|
794 | | - $importedFromClassName = $importedFrom->getClassName(); |
795 | 792 | if (!$this->reflectionProvider->hasClass($importedFromClassName)) {
|
796 | 793 | return null;
|
797 | 794 | }
|
|
0 commit comments