diff --git a/rules/generics/src/TagValueNodeFactory/MethodTagValueNodeFactory.php b/rules/generics/src/TagValueNodeFactory/MethodTagValueNodeFactory.php index 1a2b9ff51ec..6883b081f9c 100644 --- a/rules/generics/src/TagValueNodeFactory/MethodTagValueNodeFactory.php +++ b/rules/generics/src/TagValueNodeFactory/MethodTagValueNodeFactory.php @@ -77,13 +77,16 @@ private function resolveStringParameters(array $parameterReflections): array return $stringParameters; } - private function resolveReturnTagTypeNode(ReturnTagValueNode $returnTagValueNode, TemplateTypeMap $templateTypeMap): TypeNode - { + private function resolveReturnTagTypeNode( + ReturnTagValueNode $returnTagValueNode, + TemplateTypeMap $templateTypeMap + ): TypeNode { $returnTagTypeNode = $returnTagValueNode->type; - if ($returnTagValueNode->type instanceof UnionTypeNode) { return $this->resolveUnionTypeNode($returnTagValueNode->type, $templateTypeMap); - } elseif ($returnTagValueNode->type instanceof IdentifierTypeNode) { + } + + if ($returnTagValueNode->type instanceof IdentifierTypeNode) { return $this->resolveIdentifierTypeNode( $returnTagValueNode->type, $templateTypeMap, @@ -94,22 +97,6 @@ private function resolveReturnTagTypeNode(ReturnTagValueNode $returnTagValueNode return $returnTagTypeNode; } - private function resolveIdentifierTypeNode( - IdentifierTypeNode $identifierTypeNode, - TemplateTypeMap $templateTypeMap, - TypeNode $fallbackTypeNode - ): TypeNode { - $typeName = $identifierTypeNode->name; - $genericType = $templateTypeMap->getType($typeName); - - if ($genericType instanceof Type) { - $returnTagType = $genericType; - return $this->staticTypeMapper->mapPHPStanTypeToPHPStanPhpDocTypeNode($returnTagType); - } - - return $fallbackTypeNode; - } - private function resolveUnionTypeNode(UnionTypeNode $unionTypeNode, TemplateTypeMap $templateTypeMap): UnionTypeNode { $resolvedTypes = []; @@ -133,4 +120,20 @@ private function resolveUnionTypeNode(UnionTypeNode $unionTypeNode, TemplateType return new UnionTypeNode($resolvedTypes); } + + private function resolveIdentifierTypeNode( + IdentifierTypeNode $identifierTypeNode, + TemplateTypeMap $templateTypeMap, + TypeNode $fallbackTypeNode + ): TypeNode { + $typeName = $identifierTypeNode->name; + $genericType = $templateTypeMap->getType($typeName); + + if ($genericType instanceof Type) { + $returnTagType = $genericType; + return $this->staticTypeMapper->mapPHPStanTypeToPHPStanPhpDocTypeNode($returnTagType); + } + + return $fallbackTypeNode; + } }