Skip to content

[13.x] Improve collection return types for methods that mutate - #61571

Merged
taylorotwell merged 3 commits into
laravel:13.xfrom
axlon:collection-this-out
Sep 13, 2026
Merged

taylorotwell merged 3 commits into
laravel:13.xfrom
axlon:collection-this-out

Conversation

@axlon

@axlon axlon commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

PHPStan 2.2.14 ships a bugfix that fixes that PHPStan could not understand (T of array-key)|int. Since this is now fixed some Collection methods that mutate the collection directly can have their types improved.

Before:

collect(['foo' => 'bar'])->push('baz'); // Collection<string, string>

After:

collect(['foo' => 'bar'])->push('baz'); // Collection<int|string, string>

@taylorotwell
taylorotwell merged commit 6b2357c into laravel:13.x Sep 13, 2026
56 checks passed
@axlon
axlon deleted the collection-this-out branch September 14, 2026 19:49
binaryfire added a commit to hypervel/components-backup that referenced this pull request Oct 1, 2026
Handle string outer keys in collapseWithKeys and describe receiver types after collection mutation, including nullable keys. Return base collections for Eloquent duplicate attribute or callback values; keep model collections when no callback is supplied.

Correct mapped duplicate and sum types, annotate empty builders and Wayfinder defaults, and preserve explicit null-key behavior without PHP 8.5 deprecations. Consolidate overlapping coverage. Collection tests and full type analysis pass.

Upstream:
laravel/framework#61539
laravel/framework#61571
laravel/framework#61572
laravel/framework#61578
laravel/framework#61597
laravel/framework#61611
laravel/framework#61621

Source: laravel/framework at 7068848dfe48fc3a433598e09ce798799d442a52.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants