TotalPagesAwarePagination   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 4
dl 0
loc 20
ccs 4
cts 4
cp 1
rs 10
c 3
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getIterator() 0 3 1
A matches() 0 3 1
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 pages.
12
 */
13
class TotalPagesAwarePagination 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...talPagesAwarePagination: $attempts, $backoff, $firstPage, $async, $rateLimits
Loading history...
16
17
    /**
18
     * Determine whether this pagination matches the configuration.
19
     */
20 30
    public function matches(): bool
21
    {
22 30
        return $this->config->totalPagesKey !== null;
23
    }
24
25
    /**
26
     * Yield the paginated items.
27
     *
28
     * @return Traversable<int, mixed>
29
     */
30 33
    public function getIterator(): Traversable
31
    {
32 33
        yield from $this->yieldItemsUntilKey($this->config->totalPagesKey); /** @phpstan-ignore-line */
0 ignored issues
show
Bug introduced by
It seems like $this->config->totalPagesKey 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

32
        yield from $this->yieldItemsUntilKey(/** @scrutinizer ignore-type */ $this->config->totalPagesKey); /** @phpstan-ignore-line */
Loading history...
33
    }
34
}
35