Skip to content

Commit c5c02dc

Browse files
committed
ci: Generate code
1 parent 2980f05 commit c5c02dc

File tree

2 files changed

+41
-157
lines changed

2 files changed

+41
-157
lines changed

src/Paginator.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,41 @@
44

55
class Paginator
66
{
7-
private $callable;
7+
private $request;
88
private $params;
99
private $pagination_cache = [];
1010
private const FIRST_PAGE = "FIRST_PAGE";
1111

12-
public function __construct(callable $callable, array $params = [])
12+
public function __construct(callable $request, array $params = [])
1313
{
14-
$this->callable = $callable;
14+
$this->request = $request;
1515
$this->params = $params;
1616
}
1717

1818
public function firstPage(): array
1919
{
20-
$callable = $this->callable;
20+
$request = $this->request;
2121
$params = $this->params;
2222

2323
$params["on_response"] = fn($response) => $this->cachePagination(
2424
$response,
2525
self::FIRST_PAGE
2626
);
2727

28-
$data = $callable($params);
28+
$data = $request($params);
2929

3030
return [$data, $this->pagination_cache[self::FIRST_PAGE]];
3131
}
3232

3333
public function nextPage(string $next_page_cursor): array
3434
{
35-
$callable = $this->callable;
35+
if ($next_page_cursor === null) {
36+
throw new \InvalidArgumentException(
37+
"Cannot get the next page with a null next_page_cursor"
38+
);
39+
}
40+
41+
$request = $this->request;
3642
$params = $this->params;
3743

3844
$params["page_cursor"] = $next_page_cursor;
@@ -41,7 +47,7 @@ public function nextPage(string $next_page_cursor): array
4147
$next_page_cursor
4248
);
4349

44-
$data = $callable($params);
50+
$data = $request($params);
4551

4652
return [$data, $this->pagination_cache[$next_page_cursor]];
4753
}

0 commit comments

Comments
 (0)