LastPageAwarePagination::matches()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 1
b 0
f 0
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 number of the last page.
12
 */
13
class LastPageAwarePagination extends Pagination
14
{
15
    use YieldsItemsByLength;
0 ignored issues
show
introduced by
The trait Cerbero\LazyJsonPages\Concerns\YieldsItemsByLength requires some properties which are not provided by Cerbero\LazyJsonPages\Pa...LastPageAwarePagination: $attempts, $backoff, $firstPage, $async, $rateLimits
Loading history...
16
17
    /**
18
     * Determine whether this pagination matches the configuration.
19
     */
20 43
    public function matches(): bool
21
    {
22 43
        return $this->config->lastPageKey !== null;
23
    }
24
25
    /**
26
     * Yield the paginated items.
27
     *
28
     * @return Traversable<int, mixed>
29
     */
30 5
    public function getIterator(): Traversable
31
    {
32
        /** @phpstan-ignore-next-line */
33 5
        yield from $this->yieldItemsUntilKey($this->config->lastPageKey, function (int $page) {
0 ignored issues
show
Bug introduced by
It seems like $this->config->lastPageKey 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 ignore-type  annotation

33
        yield from $this->yieldItemsUntilKey(/** @scrutinizer ignore-type */ $this->config->lastPageKey, function (int $page) {
Loading history...
34 5
            return $this->config->firstPage === 0 ? $page + 1 : $page;
35 5
        });
36
    }
37
}
38