1 | <?php |
||
2 | declare(strict_types=1); |
||
3 | |||
4 | namespace Level23\Druid\Limits; |
||
5 | |||
6 | use Level23\Druid\OrderBy\OrderByInterface; |
||
7 | use Level23\Druid\Collections\OrderByCollection; |
||
8 | |||
9 | class Limit implements LimitInterface |
||
10 | { |
||
11 | protected ?int $limit; |
||
12 | |||
13 | protected ?OrderByCollection $orderBy; |
||
14 | |||
15 | protected ?int $offset; |
||
16 | |||
17 | 35 | public function __construct(?int $limit = null, ?OrderByCollection $orderBy = null, ?int $offset = null) |
|
18 | { |
||
19 | 35 | $this->limit = $limit; |
|
20 | 35 | $this->orderBy = $orderBy; |
|
21 | 35 | $this->offset = $offset; |
|
22 | } |
||
23 | |||
24 | /** |
||
25 | * Return the limit in array format so that it can be used in a druid query. |
||
26 | * |
||
27 | * @return array<string,string|array<array<string,string>>|int> |
||
28 | */ |
||
29 | 2 | public function toArray(): array |
|
30 | { |
||
31 | 2 | $result = [ |
|
32 | 2 | 'type' => 'default', |
|
33 | 2 | 'columns' => ($this->orderBy ? $this->orderBy->toArray() : []), |
|
34 | 2 | ]; |
|
35 | 2 | if ($this->limit !== null) { |
|
36 | 2 | $result['limit'] = $this->limit; |
|
37 | } |
||
38 | 2 | if ($this->offset !== null) { |
|
39 | 2 | $result['offset'] = $this->offset; |
|
40 | } |
||
41 | |||
42 | 2 | return $result; |
|
43 | } |
||
44 | |||
45 | /** |
||
46 | * @param int $limit |
||
47 | */ |
||
48 | 4 | public function setLimit(int $limit): void |
|
49 | { |
||
50 | 4 | $this->limit = $limit; |
|
51 | } |
||
52 | |||
53 | /** |
||
54 | * Add an order by field to the collection. |
||
55 | * |
||
56 | * @param \Level23\Druid\OrderBy\OrderByInterface $orderBy |
||
57 | */ |
||
58 | 15 | public function addOrderBy(OrderByInterface $orderBy): void |
|
59 | { |
||
60 | 15 | if ($this->orderBy === null) { |
|
61 | 15 | $this->orderBy = new OrderByCollection(); |
|
62 | } |
||
63 | 15 | $this->orderBy->add($orderBy); |
|
0 ignored issues
–
show
|
|||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Get the limit which is currently configured. |
||
68 | * |
||
69 | * @return int|null |
||
70 | */ |
||
71 | 28 | public function getLimit(): ?int |
|
72 | { |
||
73 | 28 | return $this->limit; |
|
74 | } |
||
75 | |||
76 | /** |
||
77 | * Return the fields which are used to sort the result by. |
||
78 | * |
||
79 | * @return \Level23\Druid\Collections\OrderByCollection |
||
80 | */ |
||
81 | 16 | public function getOrderByCollection(): OrderByCollection |
|
82 | { |
||
83 | 16 | if (is_null($this->orderBy)) { |
|
84 | 5 | return new OrderByCollection(); |
|
85 | } |
||
86 | |||
87 | 11 | return $this->orderBy; |
|
88 | } |
||
89 | |||
90 | /** |
||
91 | * @param int $offset |
||
92 | */ |
||
93 | 6 | public function setOffset(int $offset): void |
|
94 | { |
||
95 | 6 | $this->offset = $offset; |
|
96 | } |
||
97 | |||
98 | /** |
||
99 | * @return int|null |
||
100 | */ |
||
101 | 8 | public function getOffset(): ?int |
|
102 | { |
||
103 | 8 | return $this->offset; |
|
104 | } |
||
105 | } |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.