diff --git a/src/Illuminate/Collections/Traits/EnumeratesValues.php b/src/Illuminate/Collections/Traits/EnumeratesValues.php index 9fa86d5bac05..aee186f0c209 100644 --- a/src/Illuminate/Collections/Traits/EnumeratesValues.php +++ b/src/Illuminate/Collections/Traits/EnumeratesValues.php @@ -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) { diff --git a/types/Support/Collection.php b/types/Support/Collection.php index 05a5b79fcd46..c6733fa5d331 100644 --- a/types/Support/Collection.php +++ b/types/Support/Collection.php @@ -873,10 +873,10 @@ function ($collection, $count) { assertType('Illuminate\Support\Collection', $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', $collection->make([1])->take(1)); diff --git a/types/Support/LazyCollection.php b/types/Support/LazyCollection.php index 7c1359f58a40..4e96ba431f70 100644 --- a/types/Support/LazyCollection.php +++ b/types/Support/LazyCollection.php @@ -732,10 +732,10 @@ public function toArray(): array assertType('Illuminate\Support\LazyCollection', $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', $collection->make([1])->take(1));