PaginatedRequest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 76.92%

Importance

Changes 0
Metric Value
wmc 7
eloc 23
dl 0
loc 62
ccs 20
cts 26
cp 0.7692
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A perPage() 0 3 1
A setPerPage() 0 6 1
A __construct() 0 13 1
A retrieve() 0 8 1
A endpoint() 0 3 1
A currentPage() 0 3 1
A setCurrentPage() 0 6 1
1
<?php
2
3
namespace NavigaAdClient\Requests;
4
5
use NavigaAdClient\NavigaAdApi;
6
use NavigaAdClient\Responses\PaginatedResponse;
0 ignored issues
show
Bug introduced by
The type NavigaAdClient\Responses\PaginatedResponse was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
8
class PaginatedRequest
9
{
10
    protected NavigaAdApi $api;
11
12
    protected string $endpoint;
13
    protected int $perPage;
14
    protected int $currentPage;
15
16 1
    public function __construct(
17
        NavigaAdApi $api,
18
        string      $endpoint,
19
        int         $perPage = 20,
20
        int         $currentPage = 1,
21
    ) {
22 1
        $this->api = $api;
23
24 1
        throw_if(empty($endpoint));
25 1
        $this->endpoint = $endpoint;
26
27 1
        $this->setPerPage($perPage);
28 1
        $this->setCurrentPage($currentPage);
29
    }
30
31
    public function endpoint(): string
32
    {
33
        return $this->endpoint;
34
    }
35
36
    public function perPage(): int
37
    {
38
        return $this->perPage;
39
    }
40
41
    public function currentPage(): int
42
    {
43
        return $this->currentPage;
44
    }
45
46 1
    public function setPerPage(int $perPage): static
47
    {
48 1
        throw_if($perPage <= 0);
49 1
        $this->perPage = $perPage;
50
51 1
        return $this;
52
    }
53
54 1
    public function setCurrentPage(int $currentPage): static
55
    {
56 1
        throw_if($currentPage <= 0);
57 1
        $this->currentPage = $currentPage;
58
59 1
        return $this;
60
    }
61
62 1
    public function retrieve(array $query = []): PaginatedResponse
63
    {
64 1
        $response = $this->api->pendingRequest()->get($this->endpoint, array_merge($query, [
65 1
            'page'     => $this->currentPage,
66 1
            'pageSize' => $this->perPage,
67 1
        ]));
68
69 1
        return new PaginatedResponse($response, clone $this, $query);
70
    }
71
}
72