Skip to content

[12.x] Improve typehints for AbstractCursorPaginator@through() #56267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/Illuminate/Pagination/AbstractCursorPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<TKey, TThroughValue>
*
* @phpstan-this-out static<TKey, TThroughValue>
*/
public function through(callable $callback)
{
Expand Down
13 changes: 13 additions & 0 deletions types/Pagination/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, array{id: int, post: Post}>', $throughPaginator);