Implement TODO: handle multiple type nodes in AddReturnDocblockForDimFetchArrayFromAssignsRector#7991
Closed
TomasVotruba wants to merge 3 commits into
Closed
Implement TODO: handle multiple type nodes in AddReturnDocblockForDimFetchArrayFromAssignsRector#7991TomasVotruba wants to merge 3 commits into
TomasVotruba wants to merge 3 commits into
Conversation
…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
ef26090 to
d2715ed
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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