Skip to content

Add generic template to same param-return union methods - #799

Merged
TomasVotruba merged 1 commit into
mainfrom
tv-generic-template-methods
Oct 12, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
tv-generic-template-methods

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Satisfies the new PreferGenericTemplateOnSameUnionTypeRule (symplify/phpstan-rules).

Methods that take a MethodCall|StaticCall param and return the same union now declare a @template generic, so the return type narrows to the passed node type:

  • methods that return the passed node -> @return TCall (or TCall|null)
  • factory methods that build a new node -> explicit conditional return type @return ($node is MethodCall ? MethodCall : StaticCall), since a plain @template return would not hold for a freshly built node

No behavior change - docblocks only.

…turn union

Narrows the return type to the passed node type via @template, or an explicit conditional return type for factory methods that build a new node. Satisfies the new PreferGenericTemplateOnSameUnionTypeRule from symplify/phpstan-rules.
@TomasVotruba
TomasVotruba merged commit 518faec into main Oct 12, 2026
8 checks passed
@TomasVotruba
TomasVotruba deleted the tv-generic-template-methods branch October 12, 2026 10:58
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