Skip to content

[DeadCode] Skip static/$this union @return in RemoveUselessUnionReturnDocblockRector - #8649

Merged
TomasVotruba merged 1 commit into
mainfrom
skip-static-union-return-docblock
Oct 13, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
skip-static-union-return-docblock

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

static and $this denote the runtime subclass, which a native return type like ?SomeInterface cannot express. Removing such a @return static|null docblock loses information, so it must be kept.

Reported on a Mautic trait:

/**
 * @return static|null
 */
public function getVariantParent(): ?VariantEntityInterface
{
    return $this->variantParent;
}

When static cannot resolve to a concrete class (e.g. a trait or free function in the analyzed reflection scope), it degrades to mixed, which is broader than the native type and the rule wrongly stripped the docblock.

Fix: skip the union @return when it contains static or $this. Added skip fixtures for both the trait and the degraded (free-function) case.

@TomasVotruba
TomasVotruba merged commit 8a2590d into main Oct 13, 2026
49 checks passed
@TomasVotruba
TomasVotruba deleted the skip-static-union-return-docblock branch October 13, 2026 08:46
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