Skip to content

Commit 0565d94

Browse files
author
Sébastien Nikolaou
authored
[9.x] Improve Support\LazyCollection type definitions (#39506)
* Make LazyCollection generic * Remove `toBase` type test from LazyCollection
1 parent 5869c9d commit 0565d94

File tree

6 files changed

+1039
-148
lines changed

6 files changed

+1039
-148
lines changed

src/Illuminate/Collections/Collection.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function all()
6666
/**
6767
* Get a lazy collection for the items in this collection.
6868
*
69-
* @return \Illuminate\Support\LazyCollection
69+
* @return \Illuminate\Support\LazyCollection<TKey, TValue>
7070
*/
7171
public function lazy()
7272
{
@@ -366,7 +366,7 @@ public function filter(callable $callback = null)
366366
*
367367
* @template TFirstDefault
368368
*
369-
* @param (callable(TValue): bool)|null $callback
369+
* @param (callable(TValue, TKey): bool)|null $callback
370370
* @param TFirstDefault $default
371371
* @return TValue|TFirstDefault
372372
*/
@@ -1188,10 +1188,10 @@ public function sole($key = null, $operator = null, $value = null)
11881188
/**
11891189
* Get the first item in the collection but throw an exception if no matching items exist.
11901190
*
1191-
* @param mixed $key
1191+
* @param (callable(TValue, TKey): bool)|string $key
11921192
* @param mixed $operator
11931193
* @param mixed $value
1194-
* @return mixed
1194+
* @return TValue
11951195
*
11961196
* @throws \Illuminate\Support\ItemNotFoundException
11971197
*/
@@ -1216,7 +1216,7 @@ public function firstOrFail($key = null, $operator = null, $value = null)
12161216
* Chunk the collection into chunks of the given size.
12171217
*
12181218
* @param int $size
1219-
* @return static<int, static<int, TValue>>
1219+
* @return static<int, static<TKey, TValue>>
12201220
*/
12211221
public function chunk($size)
12221222
{

src/Illuminate/Collections/Enumerable.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ public function whereInstanceOf($type);
458458
*
459459
* @template TFirstDefault
460460
*
461-
* @param (callable(TValue): bool)|null $callback
461+
* @param (callable(TValue,TKey): bool)|null $callback
462462
* @param TFirstDefault $default
463463
* @return TValue|TFirstDefault
464464
*/
@@ -878,7 +878,7 @@ public function sole($key = null, $operator = null, $value = null);
878878
* Chunk the collection into chunks of the given size.
879879
*
880880
* @param int $size
881-
* @return static<int, static<int, TValue>>
881+
* @return static<int, static<TKey, TValue>>
882882
*/
883883
public function chunk($size);
884884

@@ -1047,8 +1047,10 @@ public function pad($size, $value);
10471047
/**
10481048
* Count the number of items in the collection using a given truth test.
10491049
*
1050-
* @param (callable(TValue, TKey): mixed)|string|null $callback
1051-
* @return static<TValue, int>
1050+
* @template TGroup of array-key
1051+
*
1052+
* @param (callable(TValue, TKey): TGroup)|string|null $callback
1053+
* @return static<TGroup, int>
10521054
*/
10531055
public function countBy($callback = null);
10541056

0 commit comments

Comments
 (0)