Skip to content

[DeadCode] Add RemoveReturnTagIncompatibleWithNativeTypeRector#8172

Merged
TomasVotruba merged 1 commit into
mainfrom
remove-contradicting-return-tag
Jul 11, 2026
Merged

[DeadCode] Add RemoveReturnTagIncompatibleWithNativeTypeRector#8172
TomasVotruba merged 1 commit into
mainfrom
remove-contradicting-return-tag

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Adds RemoveReturnTagIncompatibleWithNativeTypeRector to the DeadCode set.

Removes a @return docblock whose type contradicts the declared native return type — the tag is dead/wrong and misleads readers and IDEs.

 final class SomeClass
 {
-    /**
-     * @return SomeObject
-     */
     public function getName(): string
     {
         return $this->someObject->getName();
     }
 }

Safe by design

Removes only a true contradiction (nativeType->isSuperTypeOf(docType)->no()). Legitimate narrowing is kept.

native @return action
string \stdClass remove
array \stdClass remove
object \stdClass keep (narrowing)
array int[] keep (generic narrowing)
string \stdClass + description keep
(no native type) \stdClass keep

Complements RemoveUselessReturnTagRector (equal type) and RemoveMixedDocblockOverruledByNativeTypeRector (mixed); neither covers a contradicting class/scalar @return.

@TomasVotruba TomasVotruba marked this pull request as ready for review July 11, 2026 07:59
@TomasVotruba TomasVotruba merged commit 15ecbd6 into main Jul 11, 2026
65 checks passed
@TomasVotruba TomasVotruba deleted the remove-contradicting-return-tag branch July 11, 2026 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant