Skip to content

Implement TODO: handle multiple type nodes in AddReturnDocblockForDimFetchArrayFromAssignsRector#7991

Closed
TomasVotruba wants to merge 3 commits into
mainfrom
claude/implement-todo-item-GavnU
Closed

Implement TODO: handle multiple type nodes in AddReturnDocblockForDimFetchArrayFromAssignsRector#7991
TomasVotruba wants to merge 3 commits into
mainfrom
claude/implement-todo-item-GavnU

Conversation

@TomasVotruba
Copy link
Copy Markdown
Member

When a method returns a variable whose PHPStan-inferred type is a union
of multiple distinct ConstantArrayTypes, the rector previously only used
the first generalized type node and discarded the rest. Now it correctly
creates a BracketsAwareUnionTypeNode from all non-empty type nodes,
producing a union @return docblock (e.g. array<string, int>|array<string, string>).

Also adds a guard for the case where all union members are empty arrays
(would previously crash with an undefined index on $genericUnionedTypeNodes[0]).

https://claude.ai/code/session_01L2wfcmkihik6MVWq5qwEfw

claude added 3 commits May 17, 2026 20:01
…FetchArrayFromAssignsRector

When a method returns a variable whose PHPStan-inferred type is a union
of multiple distinct ConstantArrayTypes, the rector previously only used
the first generalized type node and discarded the rest. Now it correctly
creates a BracketsAwareUnionTypeNode from all non-empty type nodes,
producing a union @return docblock (e.g. array<string, int>|array<string, string>).

Also adds a guard for the case where all union members are empty arrays
(would previously crash with an undefined index on $genericUnionedTypeNodes[0]).

https://claude.ai/code/session_01L2wfcmkihik6MVWq5qwEfw
PHPStan may return union type members in different order depending on the
PHP binary version used during analysis. Sorting by string representation
ensures the generated @return docblock is consistent regardless of the
PHP version running the tests.

https://claude.ai/code/session_01L2wfcmkihik6MVWq5qwEfw
PHPStan level 8 requires typed closure parameters. Rector's analysis
flagged the missing types in the sorting callback.

https://claude.ai/code/session_01L2wfcmkihik6MVWq5qwEfw
@TomasVotruba TomasVotruba force-pushed the claude/implement-todo-item-GavnU branch from ef26090 to d2715ed Compare May 17, 2026 20:02
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.

2 participants