1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Lampager\Cake; |
6
|
|
|
|
7
|
|
|
use Cake\Datasource\Paging\PaginatedInterface; |
8
|
|
|
use Countable; |
9
|
|
|
use JsonSerializable; |
10
|
|
|
use Lampager\PaginationResult as LampagerPaginationResult; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Class PaginationResult |
14
|
|
|
*/ |
15
|
|
|
class PaginationResult extends LampagerPaginationResult implements JsonSerializable, PaginatedInterface |
16
|
|
|
{ |
17
|
|
|
protected ?iterable $iterator = null; |
18
|
|
|
|
19
|
|
|
protected int $limit; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
*/ |
24
|
|
|
public function currentPage(): int |
25
|
|
|
{ |
26
|
|
|
return 0; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
*/ |
32
|
|
|
public function perPage(): int |
33
|
|
|
{ |
34
|
|
|
return $this->limit; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* {@inheritdoc} |
39
|
|
|
*/ |
40
|
|
|
public function totalCount(): ?int |
41
|
|
|
{ |
42
|
|
|
return null; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* {@inheritdoc} |
47
|
|
|
*/ |
48
|
|
|
public function pageCount(): ?int |
49
|
|
|
{ |
50
|
|
|
return null; |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* {@inheritdoc} |
55
|
|
|
*/ |
56
|
|
|
public function hasPrevPage(): bool |
57
|
|
|
{ |
58
|
|
|
return (bool)$this->hasPrevious; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* {@inheritdoc} |
63
|
|
|
*/ |
64
|
|
|
public function hasNextPage(): bool |
65
|
|
|
{ |
66
|
|
|
return (bool)$this->hasNext; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* {@inheritdoc} |
71
|
|
|
*/ |
72
|
|
|
public function items(): iterable |
73
|
|
|
{ |
74
|
|
|
if (!$this->iterator) { |
75
|
|
|
$this->iterator = $this->getIterator(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
return $this->iterator; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* {@inheritdoc} |
83
|
|
|
*/ |
84
|
|
|
public function pagingParam(string $name): mixed |
85
|
|
|
{ |
86
|
|
|
return $this->pagingParams()[$name] ?? null; |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* {@inheritdoc} |
91
|
|
|
*/ |
92
|
|
|
public function pagingParams(): array |
93
|
|
|
{ |
94
|
|
|
return [ |
95
|
|
|
'count' => $this->count(), |
96
|
|
|
'totalCount' => $this->totalCount(), |
|
|
|
|
97
|
|
|
'perPage' => $this->perPage(), |
98
|
|
|
'pageCount' => $this->pageCount(), |
|
|
|
|
99
|
|
|
'currentPage' => $this->currentPage(), |
100
|
|
|
'hasPrevPage' => $this->hasPrevPage(), |
101
|
|
|
'hasNextPage' => $this->hasNextPage(), |
102
|
|
|
]; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* {@inheritdoc} |
107
|
|
|
*/ |
108
|
|
|
public function jsonSerialize(): array |
109
|
|
|
{ |
110
|
|
|
$items = $this->items(); |
111
|
|
|
$array = get_object_vars($this); |
112
|
|
|
$array['records'] = is_array($items) ? $items : iterator_to_array($items); |
113
|
|
|
unset($array['iterator']); |
114
|
|
|
unset($array['limit']); |
115
|
|
|
|
116
|
|
|
return $array; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* {@inheritdoc} |
121
|
|
|
*/ |
122
|
|
|
public function count(): int |
123
|
|
|
{ |
124
|
|
|
$items = $this->items(); |
125
|
|
|
return $items instanceof Countable ? count($items) : iterator_count($items); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Returns an array that can be used to describe the internal state of this |
130
|
|
|
* object. |
131
|
|
|
*/ |
132
|
|
|
public function __debugInfo(): array |
133
|
|
|
{ |
134
|
|
|
return [ |
135
|
|
|
'(help)' => 'This is a Lampager Pagination Result object.', |
136
|
|
|
] + $this->jsonSerialize(); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.