RequestOptions::setPage()   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 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace InvoiceNinjaModule\Options;
6
7
use InvoiceNinjaModule\Options\Interfaces\RequestOptionsInterface;
8
9
use function array_merge;
10
11
/**
12
 * Class RequestOptions
13
 */
14
final class RequestOptions implements RequestOptionsInterface
15
{
16
    private string $paramPageSize = 'per_page';
17
    private string $paramPage = 'page';
18
    private string $paramClientId = 'client_id';
19
    private string $paramUpdated = 'updated_at';
20
    private string $paramInclude = 'include';
21
    private array $additionalGetParams = [];
22
    private array $additionalPostParams = [];
23
24
/*
25
include: A comma-separated list of nested relationships to include.
26
updated_at: Timestamp used as a filter to only show recently updated records.
27
*/
28
29
    /**
30
     * @param array $params
31
     */
32 7
    public function addQueryParameters(array $params): void
33
    {
34 7
        $this->additionalGetParams = array_merge($params, $this->additionalGetParams);
35
    }
36
37
    /**
38
     * @param array $params
39
     */
40 3
    public function addPostParameters(array $params): void
41
    {
42 3
        $this->additionalPostParams = array_merge($params, $this->additionalPostParams);
43
    }
44
45
    /**
46
     * @return array
47
     */
48 2
    public function getQueryArray(): array
49
    {
50 2
        return $this->additionalGetParams;
51
    }
52
53
    /**
54
     * @return array
55
     */
56 2
    public function getPostArray(): array
57
    {
58 2
        return $this->additionalPostParams;
59
    }
60
61
62
    /**
63
     * @param int $pageSize
64
     */
65 4
    public function setPageSize(int $pageSize): void
66
    {
67 4
        $this->additionalGetParams[$this->paramPageSize] = $pageSize;
68
    }
69
70
71
    /**
72
     * @param int $page
73
     */
74 4
    public function setPage(int $page): void
75
    {
76 4
        $this->additionalGetParams[$this->paramPage] = $page;
77
    }
78
79
    /**
80
     * @param int $clientId
81
     */
82 1
    public function setClientId(int $clientId): void
83
    {
84 1
        $this->additionalGetParams[$this->paramClientId] = $clientId;
85
    }
86
87
    /**
88
     * @param int $updated
89
     */
90 1
    public function setUpdated(int $updated): void
91
    {
92 1
        $this->additionalGetParams[$this->paramUpdated] = $updated;
93
    }
94
95
    /**
96
     * @param string $include
97
     */
98 1
    public function setInclude(string $include): void
99
    {
100 1
        $this->additionalGetParams[$this->paramInclude] = $include;
101
    }
102
}
103