Total Complexity | 11 |
Total Lines | 96 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | class WorkcastPagination |
||
8 | { |
||
9 | protected Response $raw; |
||
10 | |||
11 | protected string $key; |
||
12 | |||
13 | |||
14 | /** |
||
15 | * WorkcastPagination constructor. |
||
16 | * |
||
17 | * @param Response $response |
||
18 | * @param string $key |
||
19 | */ |
||
20 | 4 | public function __construct(Response $response, string $key) |
|
21 | { |
||
22 | 4 | $this->raw = $response; |
|
23 | 4 | $this->key = $key; |
|
24 | } |
||
25 | |||
26 | /** |
||
27 | * @return Response |
||
28 | */ |
||
29 | 1 | public function getRawResponse(): Response |
|
30 | { |
||
31 | 1 | return $this->raw; |
|
32 | } |
||
33 | |||
34 | /** |
||
35 | * @return string |
||
36 | */ |
||
37 | 1 | public function getKey(): string |
|
38 | { |
||
39 | 1 | return $this->key; |
|
40 | } |
||
41 | |||
42 | /** |
||
43 | * @return mixed |
||
44 | */ |
||
45 | 1 | public function items(?string $key = null, $default = null) |
|
50 | } |
||
51 | |||
52 | /** |
||
53 | * @return int |
||
54 | */ |
||
55 | 1 | public function totalCount(): int |
|
56 | { |
||
57 | 1 | return $this->raw->json('totalCount', 0) ?? 0; |
|
58 | } |
||
59 | |||
60 | /** |
||
61 | * @return bool |
||
62 | */ |
||
63 | 1 | public function hasNext(): bool |
|
64 | { |
||
65 | 1 | return !empty($this->raw->json('paging.next')); |
|
66 | } |
||
67 | |||
68 | /** |
||
69 | * @return bool |
||
70 | */ |
||
71 | 1 | public function hasPrev(): bool |
|
72 | { |
||
73 | 1 | return !empty($this->raw->json('paging.previous')); |
|
74 | } |
||
75 | |||
76 | /** |
||
77 | * @return string|null |
||
78 | */ |
||
79 | 1 | public function nextLink(): ?string |
|
80 | { |
||
81 | 1 | return $this->raw->json('paging.next'); |
|
82 | } |
||
83 | |||
84 | /** |
||
85 | * @return string|null |
||
86 | */ |
||
87 | 1 | public function prevLink(): ?string |
|
90 | } |
||
91 | |||
92 | /** |
||
93 | * Dynamically proxy other methods to the underlying response. |
||
94 | * |
||
95 | * @param string $method |
||
96 | * @param array $parameters |
||
97 | * |
||
98 | * @return mixed |
||
99 | */ |
||
100 | 1 | public function __call($method, $parameters) |
|
103 | } |
||
104 | } |
||
105 |