Passed
Branch feature/first-release (57b0a8)
by Andrea Marco
13:40
created

LastPageHandler::matches()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Cerbero\LazyJsonPages\Handlers;
4
5
use Cerbero\LazyJsonPages\Concerns\HandlesTotalPages;
6
use Traversable;
7
8
/**
9
 * The last page handler.
10
 *
11
 */
12
class LastPageHandler extends AbstractHandler
13
{
14
    use HandlesTotalPages;
0 ignored issues
show
introduced by
The trait Cerbero\LazyJsonPages\Concerns\HandlesTotalPages requires some properties which are not provided by Cerbero\LazyJsonPages\Handlers\LastPageHandler: $chunk, $source, $request, $path, $firstPage, $concurrency, $pageName, $timeout
Loading history...
15
16
    /**
17
     * Determine whether the handler can handle the APIs configuration
18
     *
19
     * @return bool
20
     */
21
    public function matches(): bool
22
    {
23
        return $this->config->lastPage > 0 && $this->config->perPageQuery === null;
24
    }
25
26
    /**
27
     * Handle the APIs configuration
28
     *
29
     * @return Traversable
30
     */
31
    public function handle(): Traversable
32
    {
33
        $pages = $this->config->firstPage == 0 ? $this->config->lastPage + 1 : $this->config->lastPage;
34
35
        yield from $this->handleByTotalPages($pages);
36
    }
37
}
38