diff --git a/rules-tests/DowngradePhp80/Rector/FunctionLike/DowngradeUnionTypeDeclarationRector/Fixture/match_return_doc_with_native.php.inc b/rules-tests/DowngradePhp80/Rector/FunctionLike/DowngradeUnionTypeDeclarationRector/Fixture/match_return_doc_with_native.php.inc new file mode 100644 index 00000000..b05fbe8e --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/FunctionLike/DowngradeUnionTypeDeclarationRector/Fixture/match_return_doc_with_native.php.inc @@ -0,0 +1,31 @@ + +----- + diff --git a/rules-tests/DowngradePhp80/Rector/FunctionLike/DowngradeUnionTypeDeclarationRector/Fixture/not_match_return_doc_with_native.php.inc b/rules-tests/DowngradePhp80/Rector/FunctionLike/DowngradeUnionTypeDeclarationRector/Fixture/not_match_return_doc_with_native.php.inc new file mode 100644 index 00000000..e31bdd03 --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/FunctionLike/DowngradeUnionTypeDeclarationRector/Fixture/not_match_return_doc_with_native.php.inc @@ -0,0 +1,31 @@ + +----- + diff --git a/src/PhpDocDecorator/PhpDocFromTypeDeclarationDecorator.php b/src/PhpDocDecorator/PhpDocFromTypeDeclarationDecorator.php index 927411fc..df2ac01f 100644 --- a/src/PhpDocDecorator/PhpDocFromTypeDeclarationDecorator.php +++ b/src/PhpDocDecorator/PhpDocFromTypeDeclarationDecorator.php @@ -56,7 +56,7 @@ public function __construct( private readonly ReflectionResolver $reflectionResolver, private readonly PhpAttributeAnalyzer $phpAttributeAnalyzer, private readonly PhpVersionProvider $phpVersionProvider, - private readonly AstResolver $astResolver, + private readonly AstResolver $astResolver ) { $this->classMethodWillChangeReturnTypes = [ // @todo how to make list complete? is the method list needed or can we use just class names? @@ -74,7 +74,9 @@ public function decorateReturn(ClassMethod|Function_|Closure|ArrowFunction $func $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($functionLike); $returnTagValueNode = $phpDocInfo->getReturnTagValue(); - $returnType = $returnTagValueNode instanceof ReturnTagValueNode + + $returnType = $this->staticTypeMapper->mapPhpParserNodePHPStanType($functionLike->returnType); + $returnDocType = $returnTagValueNode instanceof ReturnTagValueNode ? $this->staticTypeMapper->mapPHPStanPhpDocTypeToPHPStanType($returnTagValueNode, $functionLike->returnType) : $this->staticTypeMapper->mapPhpParserNodePHPStanType($functionLike->returnType); @@ -88,7 +90,7 @@ public function decorateReturn(ClassMethod|Function_|Closure|ArrowFunction $func return; } - $this->phpDocTypeChanger->changeReturnType($functionLike, $phpDocInfo, $returnType); + $this->phpDocTypeChanger->changeReturnType($functionLike, $phpDocInfo, $returnDocType); $functionLike->returnType = null; if (! $functionLike instanceof ClassMethod) {