Skip to content

Commit a36f6b5

Browse files
committed
Fix
1 parent 0f6f1b0 commit a36f6b5

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

rules-tests/DowngradePhp80/Rector/FunctionLike/DowngradeUnionTypeDeclarationRector/Fixture/not_match_return_doc_with_native.php.inc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ namespace Rector\Tests\DowngradePhp80\Rector\FunctionLike\DowngradeUnionTypeDecl
2020

2121
final class NotMatchReturnDocWithNative
2222
{
23-
/**
24-
* @return \stdClass[]|null
25-
*/
2623
public function run($value)
2724
{
2825
}

src/PhpDocDecorator/PhpDocFromTypeDeclarationDecorator.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,13 @@ public function decorateReturn(ClassMethod|Function_|Closure|ArrowFunction $func
9090
return;
9191
}
9292

93-
$this->phpDocTypeChanger->changeReturnType($functionLike, $phpDocInfo, $returnDocType);
93+
if (! $this->isMatchingType($returnType, [$returnDocType])) {
94+
// not match between @return and native return type, just remove the doc
95+
$phpDocInfo->removeByName(ReturnTagValueNode::class);
96+
} else {
97+
$this->phpDocTypeChanger->changeReturnType($functionLike, $phpDocInfo, $returnDocType);
98+
}
99+
94100

95101
$functionLike->returnType = null;
96102
if (! $functionLike instanceof ClassMethod) {

0 commit comments

Comments
 (0)