From 900645a7f22f80229bcb4e0a92cef1e3a1821ea0 Mon Sep 17 00:00:00 2001 From: Valentin Udaltsov Date: Thu, 21 Sep 2023 22:14:27 +0300 Subject: [PATCH] Fixed static resolution --- src/Reflector/PhpParserReflector.php | 8 +++++++- src/TypeResolver/ClassTemplateResolver.php | 2 +- src/TypeResolver/StaticResolver.php | 6 ++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Reflector/PhpParserReflector.php b/src/Reflector/PhpParserReflector.php index 3e36d42..0115aae 100644 --- a/src/Reflector/PhpParserReflector.php +++ b/src/Reflector/PhpParserReflector.php @@ -490,7 +490,13 @@ private function reflectNativeType(?Node $node): ?Type\Type } if ($node instanceof Name) { - return types::object($this->nameContext->resolveNameAsClass($node->toCodeString())); + $resolvedName = $this->nameContext->resolveNameAsClass($node->toCodeString()); + + if ($node->toString() === 'static') { + return types::static($resolvedName); + } + + return types::object($resolvedName); } throw new ReflectionException(sprintf('%s is not supported.', $node::class)); diff --git a/src/TypeResolver/ClassTemplateResolver.php b/src/TypeResolver/ClassTemplateResolver.php index 1fc7475..9d37c0e 100644 --- a/src/TypeResolver/ClassTemplateResolver.php +++ b/src/TypeResolver/ClassTemplateResolver.php @@ -215,7 +215,7 @@ public function visitNamedObject(Type\NamedObjectType $type): mixed public function visitStatic(Type\StaticType $type): mixed { /** @psalm-suppress ImpureFunctionCall */ - return types::object($type->declaringClass, ...array_map( + return types::static($type->declaringClass, ...array_map( fn (Type\Type $type): Type\Type => $type->accept($this), $type->templateArguments, )); diff --git a/src/TypeResolver/StaticResolver.php b/src/TypeResolver/StaticResolver.php index fb5c0a8..a6149ef 100644 --- a/src/TypeResolver/StaticResolver.php +++ b/src/TypeResolver/StaticResolver.php @@ -213,12 +213,10 @@ public function visitNamedObject(Type\NamedObjectType $type): mixed public function visitStatic(Type\StaticType $type): mixed { /** @psalm-suppress ImpureFunctionCall */ - $templateArguments = array_map( + return types::object($this->class, ...array_map( fn (Type\Type $type): Type\Type => $type->accept($this), $type->templateArguments, - ); - - return types::object($this->class, ...$templateArguments); + )); } public function visitObject(Type\ObjectType $type): mixed