Skip to content

[DeadCode] Add RemoveUselessUnionReturnDocblockRector#8126

Merged
TomasVotruba merged 1 commit into
mainfrom
dead-code/remove-useless-union-return-docblock
Jun 30, 2026
Merged

[DeadCode] Add RemoveUselessUnionReturnDocblockRector#8126
TomasVotruba merged 1 commit into
mainfrom
dead-code/remove-useless-union-return-docblock

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Adds a dead-code rule that removes a @return union docblock when a more specific, non-array native return type already covers it.

The docblock adds nothing once the native type is narrower-or-equal, so it is dead.

Before

/**
 * @return bool|mixed|string
 */
protected function setContactToSync($checkEmailsInSF, $lead): false|string

After

protected function setContactToSync($checkEmailsInSF, $lead): false|string

Also handles a union docblock over a single native type, e.g. @return bool|float|mixed|string over : string.

Trigger

  • @return type is a union node
  • native return type is declared and not array/iterable (kept, may carry element types)
  • the docblock type is a supertype of the native type (broader-or-equal)
  • empty description (descriptions are kept)

Requires PHP 8.0 (MinPhpVersionInterface -> UNION_TYPES). Registered in the dead-code set via DeadCodeLevel.

Remove @return union docblock when a more specific, non-array native return type already covers it, e.g. @return bool|mixed|string over false|string.
@TomasVotruba TomasVotruba merged commit 0dbbde8 into main Jun 30, 2026
64 of 65 checks passed
@TomasVotruba TomasVotruba deleted the dead-code/remove-useless-union-return-docblock branch June 30, 2026 15:31
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