Skip to content

[TypeDeclaration] Skip noisy array-shape union return docblock in ReturnTypeFromStrictNewArrayRector - #8422

Merged
TomasVotruba merged 1 commit into
mainfrom
skip-noisy-array-shape-union-return-doc
Aug 31, 2026
Merged

[TypeDeclaration] Skip noisy array-shape union return docblock in ReturnTypeFromStrictNewArrayRector#8422
TomasVotruba merged 1 commit into
mainfrom
skip-noisy-array-shape-union-return-doc

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

When a method has multiple returns that produce a union of distinct array shapes, ReturnTypeFromStrictNewArrayRector added an unreadable @return docblock, e.g.:

/**
 * @return array{amount: 1, cash_register_id: 2, text: 't'}[]|array{amount: 1, date: 'd', text: 't'}[]
 */
public function getRowFormatBookEntry($abe, $onlyCashRegister = false): array

Such a union of array shapes is noise and adds nothing over the native : array type.

This adds a complexity guard: when the resolved type contains (at any nesting) a union of 2+ distinct non-empty array variants, only the native : array type is added and the docblock is skipped. Simple cases (list<int>, mixed[], non-empty-array<array{c: mixed}>[]) are unaffected, and the mixed[] fallback (empty [] collapsing into a sibling variant) is preserved.

…urnTypeFromStrictNewArrayRector

When multiple returns produce a union of distinct array shapes, the added
@return docblock becomes an unreadable union of array shapes. Add the native
: array type only and skip the docblock in that case.

Claude-Session: https://claude.ai/code/session_019V3LiG3bWd4EyrzsJ5jhAT
@TomasVotruba
TomasVotruba merged commit 42f8514 into main Aug 31, 2026
44 checks passed
@TomasVotruba
TomasVotruba deleted the skip-noisy-array-shape-union-return-doc branch August 31, 2026 13:45
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