From 1bea5c79d53e06f6cdd481decba73b504fb4bec0 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Thu, 26 Sep 2024 13:17:13 +0200 Subject: [PATCH] PhpFunctionFromParserNodeReflection becomes ParametersAcceptorWithPhpDocs --- .../PhpFunctionFromParserNodeReflection.php | 42 +++++++++++++++---- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/src/Reflection/Php/PhpFunctionFromParserNodeReflection.php b/src/Reflection/Php/PhpFunctionFromParserNodeReflection.php index 8e2429016c..86ab366632 100644 --- a/src/Reflection/Php/PhpFunctionFromParserNodeReflection.php +++ b/src/Reflection/Php/PhpFunctionFromParserNodeReflection.php @@ -16,6 +16,7 @@ use PHPStan\ShouldNotHappenException; use PHPStan\TrinaryLogic; use PHPStan\Type\Generic\TemplateTypeMap; +use PHPStan\Type\Generic\TemplateTypeVarianceMap; use PHPStan\Type\MixedType; use PHPStan\Type\Type; use PHPStan\Type\TypehintHelper; @@ -26,7 +27,7 @@ /** * @api */ -class PhpFunctionFromParserNodeReflection implements FunctionReflection +class PhpFunctionFromParserNodeReflection implements FunctionReflection, ParametersAcceptorWithPhpDocs { /** @var Function_|ClassMethod */ @@ -101,12 +102,12 @@ public function getVariants(): array if ($this->variants === null) { $this->variants = [ new FunctionVariantWithPhpDocs( - $this->templateTypeMap, - null, + $this->getTemplateTypeMap(), + $this->getResolvedTemplateTypeMap(), $this->getParameters(), $this->isVariadic(), $this->getReturnType(), - $this->phpDocReturnType ?? new MixedType(), + $this->getPhpDocReturnType(), $this->realReturnType, ), ]; @@ -120,10 +121,20 @@ public function getNamedArgumentsVariants(): ?array return null; } + public function getTemplateTypeMap(): TemplateTypeMap + { + return $this->templateTypeMap; + } + + public function getResolvedTemplateTypeMap(): TemplateTypeMap + { + return TemplateTypeMap::createEmpty(); + } + /** - * @return ParameterReflectionWithPhpDocs[] + * @return array */ - private function getParameters(): array + public function getParameters(): array { $parameters = []; $isOptional = true; @@ -169,7 +180,7 @@ private function getParameters(): array return array_reverse($parameters); } - private function isVariadic(): bool + public function isVariadic(): bool { foreach ($this->functionLike->getParams() as $parameter) { if ($parameter->variadic) { @@ -180,11 +191,26 @@ private function isVariadic(): bool return false; } - protected function getReturnType(): Type + public function getReturnType(): Type { return TypehintHelper::decideType($this->realReturnType, $this->phpDocReturnType); } + public function getPhpDocReturnType(): Type + { + return $this->phpDocReturnType ?? new MixedType(); + } + + public function getNativeReturnType(): Type + { + return $this->realReturnType; + } + + public function getCallSiteVarianceMap(): TemplateTypeVarianceMap + { + return TemplateTypeVarianceMap::createEmpty(); + } + public function getDeprecatedDescription(): ?string { if ($this->isDeprecated) {