WorkcastPagination::totalCount()   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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace LaravelWorkcast;
4
5
use Illuminate\Http\Client\Response;
6
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)
46
    {
47 1
        $key = $this->key . ($key ? ".{$key}" : '');
48
49 1
        return $this->raw->json($key, $default);
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
88
    {
89 1
        return $this->raw->json('paging.previous');
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)
101
    {
102 1
        return $this->raw->{$method}(...$parameters);
103
    }
104
}
105