From d4b08a6ec3a56fc59e327a34d442c915d2912e52 Mon Sep 17 00:00:00 2001 From: Luke Kuzmish Date: Fri, 11 Jul 2025 06:31:06 -0400 Subject: [PATCH] fix AbstractCursorPaginator@through types --- .../Pagination/AbstractCursorPaginator.php | 8 ++++++-- types/Pagination/Paginator.php | 13 +++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Pagination/AbstractCursorPaginator.php b/src/Illuminate/Pagination/AbstractCursorPaginator.php index e36d07ee26e2..b1eabfb81954 100644 --- a/src/Illuminate/Pagination/AbstractCursorPaginator.php +++ b/src/Illuminate/Pagination/AbstractCursorPaginator.php @@ -403,8 +403,12 @@ public function items() /** * Transform each item in the slice of items using a callback. * - * @param callable $callback - * @return $this + * @template TThroughValue + * + * @param callable(TValue, TKey): TThroughValue $callback + * @return $this + * + * @phpstan-this-out static */ public function through(callable $callback) { diff --git a/types/Pagination/Paginator.php b/types/Pagination/Paginator.php index 697ca906101c..1413530f03f0 100644 --- a/types/Pagination/Paginator.php +++ b/types/Pagination/Paginator.php @@ -49,3 +49,16 @@ foreach ($cursorPaginator as $post) { assertType('Post', $post); } + +$throughPaginator = clone $cursorPaginator; +$throughPaginator->through(function ($post, $key): array { + assertType('int', $key); + assertType('Post', $post); + + return [ + 'id' => $key, + 'post' => $post, + ]; +}); + +assertType('Illuminate\Pagination\CursorPaginator', $throughPaginator);