Skip to content

Commit b108609

Browse files
authored
fix AbstractCursorPaginator@through types (#56267)
1 parent 734a450 commit b108609

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/Illuminate/Pagination/AbstractCursorPaginator.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,8 +403,12 @@ public function items()
403403
/**
404404
* Transform each item in the slice of items using a callback.
405405
*
406-
* @param callable $callback
407-
* @return $this
406+
* @template TThroughValue
407+
*
408+
* @param callable(TValue, TKey): TThroughValue $callback
409+
* @return $this<TKey, TThroughValue>
410+
*
411+
* @phpstan-this-out static<TKey, TThroughValue>
408412
*/
409413
public function through(callable $callback)
410414
{

types/Pagination/Paginator.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,16 @@
4949
foreach ($cursorPaginator as $post) {
5050
assertType('Post', $post);
5151
}
52+
53+
$throughPaginator = clone $cursorPaginator;
54+
$throughPaginator->through(function ($post, $key): array {
55+
assertType('int', $key);
56+
assertType('Post', $post);
57+
58+
return [
59+
'id' => $key,
60+
'post' => $post,
61+
];
62+
});
63+
64+
assertType('Illuminate\Pagination\CursorPaginator<int, array{id: int, post: Post}>', $throughPaginator);

0 commit comments

Comments
 (0)