CursorAwarePagination   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 27
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A matches() 0 6 4
A getIterator() 0 7 1
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
The trait Cerbero\LazyJsonPages\Concerns\YieldsItemsByCursor requires some properties which are not provided by Cerbero\LazyJsonPages\Pa...s\CursorAwarePagination: $attempts, $backoff, $rateLimits
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
Bug introduced by
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 ignore-type  annotation

38
            yield from $generator = $this->yieldItemsAndGetKey($response, /** @scrutinizer ignore-type */ $this->config->cursorKey);
Loading history...
39
40 1
            return $generator->getReturn();
41 2
        });
42
    }
43
}
44