Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Improves Support\Collection reduce method type definition #41272

Merged
merged 1 commit into from
Feb 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Illuminate/Collections/Enumerable.php
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ public function random($number = null);
* @template TReduceInitial
* @template TReduceReturnType
*
* @param callable(TReduceInitial|TReduceReturnType, TValue): TReduceReturnType $callback
* @param callable(TReduceInitial|TReduceReturnType, TValue, TKey): TReduceReturnType $callback
* @param TReduceInitial $initial
* @return TReduceReturnType
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Collections/Traits/EnumeratesValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ function ($carry, $callback) {
* @template TReduceInitial
* @template TReduceReturnType
*
* @param callable(TReduceInitial|TReduceReturnType, TValue): TReduceReturnType $callback
* @param callable(TReduceInitial|TReduceReturnType, TValue, TKey): TReduceReturnType $callback
* @param TReduceInitial $initial
* @return TReduceReturnType
*/
Expand Down
8 changes: 8 additions & 0 deletions types/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,14 @@ function ($collection, $count) {
assertType('User', $user);
assertType('int', $int);

return 1;
}, 0));
assertType('int', $collection
->reduce(function ($int, $user, $key) {
assertType('User', $user);
assertType('int', $int);
assertType('int', $key);

return 1;
}, 0));

Expand Down