Skip to content

[TypeDeclarationDocblocks] Add NarrowArrayCollectionUnionReturnDocblockRector#8136

Merged
TomasVotruba merged 1 commit into
mainfrom
add-array-collection-generic-docblock-rule
Jul 1, 2026
Merged

[TypeDeclarationDocblocks] Add NarrowArrayCollectionUnionReturnDocblockRector#8136
TomasVotruba merged 1 commit into
mainfrom
add-array-collection-generic-docblock-rule

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Adds a docblock rule that rewrites a Type[]|ArrayCollection @return union into a generic collection type.

Before

/**
 * @return LeadEventLog[]|ArrayCollection
 */
public function getSuccessful(): ArrayCollection
{
    return $this->successful;
}

After

/**
 * @return ArrayCollection<int, LeadEventLog>
 */
public function getSuccessful(): ArrayCollection
{
    return $this->successful;
}
  • Matches a 2-type @return union of an array shape (Type[]) and a collection identifier (Collection / ArrayCollection, in any order).
  • Key type is assumed int.
  • Registered in TypeDeclarationDocblocksLevel.
  • Covered with fixtures (transform, reversed order, skip already-generic, skip non-collection union).

…ckRector to turn Type[]|ArrayCollection @return union into generic ArrayCollection<int, Type>
@TomasVotruba TomasVotruba merged commit 233056b into main Jul 1, 2026
65 checks passed
@TomasVotruba TomasVotruba deleted the add-array-collection-generic-docblock-rule branch July 1, 2026 21:57
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