1 | <?php |
||||||
2 | |||||||
3 | declare(strict_types=1); |
||||||
4 | |||||||
5 | namespace Cerbero\LazyJsonPages\Concerns; |
||||||
6 | |||||||
7 | use Closure; |
||||||
8 | use Generator; |
||||||
9 | use Psr\Http\Message\ResponseInterface; |
||||||
10 | |||||||
11 | /** |
||||||
12 | * The trait to yield items from cursor-aware paginations. |
||||||
13 | */ |
||||||
14 | trait YieldsItemsByCursor |
||||||
15 | { |
||||||
16 | use RespectsRateLimits; |
||||||
17 | use RetriesHttpRequests; |
||||||
18 | |||||||
19 | /** |
||||||
20 | * Yield the paginated items by following the cursor of each page. |
||||||
21 | * |
||||||
22 | * @param Closure(ResponseInterface): Generator<int, mixed> $callback |
||||||
23 | * @return Generator<int, mixed> |
||||||
24 | */ |
||||||
25 | 3 | protected function yieldItemsByCursor(Closure $callback): Generator |
|||||
26 | { |
||||||
27 | 3 | $request = clone $this->source->request(); |
|||||
28 | |||||||
29 | 2 | yield from $generator = $callback($this->source->pullResponse()); |
|||||
30 | |||||||
31 | 2 | yield from $this->retry(function () use ($callback, $request, $generator) { |
|||||
32 | 2 | while ($cursor = $this->toPage($generator->getReturn(), onlyNumerics: false)) { |
|||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||||
33 | 2 | $this->respectRateLimits(); |
|||||
34 | |||||||
35 | 2 | $uri = $this->uriForPage($request->getUri(), (string) $cursor); |
|||||
0 ignored issues
–
show
It seems like
uriForPage() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||||
36 | 2 | $response = $this->client->send($request->withUri($uri)); |
|||||
37 | |||||||
38 | 2 | yield from $generator = $callback($response); |
|||||
39 | } |
||||||
40 | 2 | }); |
|||||
41 | } |
||||||
42 | } |
||||||
43 |