Skip to content

Commit 0d1887e

Browse files
authored
fix: Collection::transform() and Paginator::through() return types (#56273)
1 parent afa4214 commit 0d1887e

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

src/Illuminate/Collections/Collection.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1732,7 +1732,9 @@ public function takeWhile($value)
17321732
* @template TMapValue
17331733
*
17341734
* @param callable(TValue, TKey): TMapValue $callback
1735-
* @return $this<TKey, TMapValue>
1735+
* @return $this
1736+
*
1737+
* @phpstan-this-out static<TKey, TMapValue>
17361738
*/
17371739
public function transform(callable $callback)
17381740
{

src/Illuminate/Pagination/AbstractCursorPaginator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ public function items()
406406
* @template TThroughValue
407407
*
408408
* @param callable(TValue, TKey): TThroughValue $callback
409-
* @return $this<TKey, TThroughValue>
409+
* @return $this
410410
*
411411
* @phpstan-this-out static<TKey, TThroughValue>
412412
*/

src/Illuminate/Pagination/AbstractPaginator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,9 @@ public function lastItem()
356356
* @template TMapValue
357357
*
358358
* @param callable(TValue, TKey): TMapValue $callback
359-
* @return $this<TKey, TMapValue>
359+
* @return $this
360+
*
361+
* @phpstan-this-out static<TKey, TMapValue>
360362
*/
361363
public function through(callable $callback)
362364
{

types/Support/Collection.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,18 +1049,18 @@ 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('mixed', $collection->transform(function ($user, $int) {
1052+
assertType('Illuminate\Support\Collection<int, int>', $collection->transform(function ($user, $int): int {
10531053
assertType('User', $user);
10541054
assertType('int', $int);
10551055

1056-
return new User;
1056+
return $int * 2;
10571057
}));
10581058

1059-
assertType('mixed', $collection->transform(function ($user, $int): int {
1060-
assertType('User', $user);
1061-
assertType('int', $int);
1059+
assertType('Illuminate\Support\Collection<int, User>', $collection->transform(function ($value, $key) {
1060+
assertType('int', $value);
1061+
assertType('int', $key);
10621062

1063-
return $int * 2;
1063+
return new User;
10641064
}));
10651065

10661066
assertType('Illuminate\Support\Collection<int, User>', $collection->add(new User));

0 commit comments

Comments
 (0)