Skip to content

Commit d7df269

Browse files
authored
Change return types of through (pagination) and transform (collection) (#56105)
1 parent 677618b commit d7df269

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/Illuminate/Collections/Collection.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1729,8 +1729,10 @@ public function takeWhile($value)
17291729
/**
17301730
* Transform each item in the collection using a callback.
17311731
*
1732-
* @param callable(TValue, TKey): TValue $callback
1733-
* @return $this
1732+
* @template TMapValue
1733+
*
1734+
* @param callable(TValue, TKey): TMapValue $callback
1735+
* @return $this<TKey, TMapValue>
17341736
*/
17351737
public function transform(callable $callback)
17361738
{

src/Illuminate/Pagination/AbstractPaginator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,10 @@ public function lastItem()
353353
/**
354354
* Transform each item in the slice of items using a callback.
355355
*
356-
* @param callable $callback
357-
* @return $this
356+
* @template TMapValue
357+
*
358+
* @param callable(TValue, TKey): TMapValue $callback
359+
* @return $this<TKey, TMapValue>
358360
*/
359361
public function through(callable $callback)
360362
{

types/Support/Collection.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,13 +1049,20 @@ function ($collection, $count) {
10491049
assertType('Illuminate\Support\Collection<int, User>', $collection->splice(1));
10501050
assertType('Illuminate\Support\Collection<int, User>', $collection->splice(1, 1, [new User]));
10511051

1052-
assertType('Illuminate\Support\Collection<int, User>', $collection->transform(function ($user, $int) {
1052+
assertType('mixed', $collection->transform(function ($user, $int) {
10531053
assertType('User', $user);
10541054
assertType('int', $int);
10551055

10561056
return new User;
10571057
}));
10581058

1059+
assertType('mixed', $collection->transform(function ($user, $int): int {
1060+
assertType('User', $user);
1061+
assertType('int', $int);
1062+
1063+
return $int * 2;
1064+
}));
1065+
10591066
assertType('Illuminate\Support\Collection<int, User>', $collection->add(new User));
10601067

10611068
/**

0 commit comments

Comments
 (0)