Skip to content

[12.x] Types: EnumeratesValues Sum #55044

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

Merged
merged 4 commits into from
Mar 16, 2025
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
6 changes: 4 additions & 2 deletions src/Illuminate/Collections/Traits/EnumeratesValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,10 @@ public function percentage(callable $callback, int $precision = 2)
/**
* Get the sum of the given values.
*
* @param (callable(TValue): mixed)|string|null $callback
* @return mixed
* @template TReturnType
*
* @param (callable(TValue): TReturnType)|string|null $callback
* @return ($callback is callable ? TReturnType : mixed)
*/
public function sum($callback = null)
{
Expand Down
4 changes: 2 additions & 2 deletions types/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -873,10 +873,10 @@ function ($collection, $count) {
assertType('Illuminate\Support\Collection<string, string>', $collection->make(['string' => 'string'])->sortKeysDesc(1));

assertType('mixed', $collection->make([1])->sum('string'));
assertType('mixed', $collection->make(['string'])->sum(function ($string) {
assertType('int<1, 2>', $collection->make(['string'])->sum(function ($string) {
assertType('string', $string);

return 1;
return rand(1, 2);
}));

assertType('Illuminate\Support\Collection<int, int>', $collection->make([1])->take(1));
Expand Down
4 changes: 2 additions & 2 deletions types/Support/LazyCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -732,10 +732,10 @@ public function toArray(): array
assertType('Illuminate\Support\LazyCollection<string, string>', $collection->make(['string' => 'string'])->sortKeysDesc(1));

assertType('mixed', $collection->make([1])->sum('string'));
assertType('mixed', $collection->make(['string'])->sum(function ($string) {
assertType('int<1, 2>', $collection->make(['string'])->sum(function ($string) {
assertType('string', $string);

return 1;
return rand(1, 2);
}));

assertType('Illuminate\Support\LazyCollection<int, int>', $collection->make([1])->take(1));
Expand Down
Loading