cerbero90 /
lazy-json-pages
| 1 | <?php |
||||
| 2 | |||||
| 3 | declare(strict_types=1); |
||||
| 4 | |||||
| 5 | namespace Cerbero\LazyJsonPages\Paginations; |
||||
| 6 | |||||
| 7 | use Cerbero\LazyJsonPages\Concerns\YieldsItemsByLength; |
||||
| 8 | use Traversable; |
||||
| 9 | |||||
| 10 | /** |
||||
| 11 | * The pagination aware of the total number of items. |
||||
| 12 | */ |
||||
| 13 | class TotalItemsAwarePagination extends Pagination |
||||
| 14 | { |
||||
| 15 | use YieldsItemsByLength; |
||||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||||
| 16 | |||||
| 17 | /** |
||||
| 18 | * Determine whether this pagination matches the configuration. |
||||
| 19 | */ |
||||
| 20 | 34 | public function matches(): bool |
|||
| 21 | { |
||||
| 22 | 34 | return $this->config->totalItemsKey !== null |
|||
| 23 | 34 | && $this->config->totalPagesKey === null |
|||
| 24 | 34 | && $this->config->lastPageKey === null; |
|||
| 25 | } |
||||
| 26 | |||||
| 27 | /** |
||||
| 28 | * Yield the paginated items. |
||||
| 29 | * |
||||
| 30 | * @return Traversable<int, mixed> |
||||
| 31 | */ |
||||
| 32 | 4 | public function getIterator(): Traversable |
|||
| 33 | { |
||||
| 34 | /** @phpstan-ignore-next-line */ |
||||
| 35 | 4 | yield from $this->yieldItemsUntilKey($this->config->totalItemsKey, function (int $totalItems) { |
|||
|
0 ignored issues
–
show
It seems like
$this->config->totalItemsKey can also be of type null; however, parameter $key of Cerbero\LazyJsonPages\Pa...n::yieldItemsUntilKey() 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...
|
|||||
| 36 | 4 | return $this->itemsPerPage > 0 ? (int) ceil($totalItems / $this->itemsPerPage) : 0; |
|||
| 37 | 4 | }); |
|||
| 38 | } |
||||
| 39 | } |
||||
| 40 |