cerbero90 /
lazy-json-pages
| 1 | <?php |
||||
| 2 | |||||
| 3 | declare(strict_types=1); |
||||
| 4 | |||||
| 5 | namespace Cerbero\LazyJsonPages\Paginations; |
||||
| 6 | |||||
| 7 | use Cerbero\LazyJsonPages\Concerns\YieldsItemsByCursor; |
||||
| 8 | use Psr\Http\Message\ResponseInterface; |
||||
| 9 | use Traversable; |
||||
| 10 | |||||
| 11 | /** |
||||
| 12 | * The pagination aware of the cursor of the next page. |
||||
| 13 | */ |
||||
| 14 | class CursorAwarePagination extends Pagination |
||||
| 15 | { |
||||
| 16 | use YieldsItemsByCursor; |
||||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||||
| 17 | |||||
| 18 | /** |
||||
| 19 | * Determine whether this pagination matches the configuration. |
||||
| 20 | */ |
||||
| 21 | 50 | public function matches(): bool |
|||
| 22 | { |
||||
| 23 | 50 | return $this->config->cursorKey !== null |
|||
| 24 | 50 | && $this->config->totalItemsKey === null |
|||
| 25 | 50 | && $this->config->totalPagesKey === null |
|||
| 26 | 50 | && $this->config->lastPageKey === null; |
|||
| 27 | } |
||||
| 28 | |||||
| 29 | /** |
||||
| 30 | * Yield the paginated items. |
||||
| 31 | * |
||||
| 32 | * @return Traversable<int, mixed> |
||||
| 33 | */ |
||||
| 34 | 2 | public function getIterator(): Traversable |
|||
| 35 | { |
||||
| 36 | 2 | yield from $this->yieldItemsByCursor(function (ResponseInterface $response) { |
|||
| 37 | /** @phpstan-ignore-next-line */ |
||||
| 38 | 1 | yield from $generator = $this->yieldItemsAndGetKey($response, $this->config->cursorKey); |
|||
|
0 ignored issues
–
show
It seems like
$this->config->cursorKey can also be of type null; however, parameter $key of Cerbero\LazyJsonPages\Pa...::yieldItemsAndGetKey() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 39 | |||||
| 40 | 1 | return $generator->getReturn(); |
|||
| 41 | 2 | }); |
|||
| 42 | } |
||||
| 43 | } |
||||
| 44 |