Total Complexity | 5 |
Total Lines | 84 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
5 | class PaginatedResponse |
||
6 | { |
||
7 | /** |
||
8 | * All of the items being paginated. |
||
9 | * |
||
10 | * @var array |
||
11 | */ |
||
12 | protected array $items; |
||
13 | |||
14 | /** |
||
15 | * The total number of items before slicing. |
||
16 | * |
||
17 | * @var int |
||
18 | */ |
||
19 | protected int $total; |
||
20 | |||
21 | /** |
||
22 | * The number of items to be shown per page. |
||
23 | * |
||
24 | * @var int |
||
25 | */ |
||
26 | protected int $perPage; |
||
27 | |||
28 | /** |
||
29 | * The current page. |
||
30 | * |
||
31 | * @var int |
||
32 | */ |
||
33 | protected int $currentPage; |
||
34 | |||
35 | /** |
||
36 | * Create a new paginated response instance. |
||
37 | * |
||
38 | * @param array $items |
||
39 | * @param int $total |
||
40 | * @param int $perPage |
||
41 | * @param int $currentPage |
||
42 | */ |
||
43 | 1 | public function __construct(array $items, int $total, int $perPage, int $currentPage = 1) |
|
44 | { |
||
45 | 1 | $this->items = $items; |
|
46 | 1 | $this->total = $total; |
|
47 | 1 | $this->perPage = $perPage; |
|
48 | 1 | $this->currentPage = $currentPage; |
|
49 | } |
||
50 | |||
51 | /** |
||
52 | * Get the items being paginated. |
||
53 | * |
||
54 | * @return array |
||
55 | */ |
||
56 | 1 | public function items(): array |
|
57 | { |
||
58 | 1 | return $this->items; |
|
59 | } |
||
60 | |||
61 | /** |
||
62 | * Get the total number of items being paginated. |
||
63 | * |
||
64 | * @return int |
||
65 | */ |
||
66 | 1 | public function total(): int |
|
67 | { |
||
68 | 1 | return $this->total; |
|
69 | } |
||
70 | |||
71 | /** |
||
72 | * Get the number of items shown per page. |
||
73 | * |
||
74 | * @return int |
||
75 | */ |
||
76 | 1 | public function perPage(): int |
|
79 | } |
||
80 | |||
81 | /** |
||
82 | * Get the current page. |
||
83 | * |
||
84 | * @return int |
||
85 | */ |
||
86 | 1 | public function currentPage(): int |
|
89 | } |
||
90 | } |
||
91 |