1 | <?php |
||
27 | class ListQueryParameters extends QueryParameters |
||
28 | { |
||
29 | const INVALID_PAGE_SIZE = '400b395f-ee4f-4138-aad8-89f9a1872291'; |
||
30 | const INVALID_SORTING = 'e57fef44-21e4-48c4-a30d-b92009a0c16a'; |
||
31 | |||
32 | /** |
||
33 | * @var integer|null |
||
34 | * @API\Property(type="integer", path="[page][number]") |
||
35 | * @Assert\Type(type="integer") |
||
36 | * @Assert\GreaterThan(value=0) |
||
37 | */ |
||
38 | protected $pageNumber; |
||
39 | |||
40 | /** |
||
41 | * @var integer|null |
||
42 | * @API\Property(type="integer", path="[page][size]") |
||
43 | * @Assert\Type(type="integer") |
||
44 | * @Assert\GreaterThan(value=0) |
||
45 | */ |
||
46 | protected $pageSize; |
||
47 | |||
48 | /** |
||
49 | * @var SortParameterInterface[]|null |
||
50 | * @API\Property(path="[sort]", parser="parseSortingParameters") |
||
51 | * @Assert\Type(type="array") |
||
52 | */ |
||
53 | protected $sortParameters; |
||
54 | |||
55 | /** |
||
56 | * @param int|null $pageNumber |
||
57 | * @return $this |
||
58 | */ |
||
59 | 1 | public function setPageNumber($pageNumber = null) |
|
65 | |||
66 | /** |
||
67 | * @param int|null $pageSize |
||
68 | * @return $this |
||
69 | */ |
||
70 | 2 | public function setPageSize($pageSize = null) |
|
76 | |||
77 | /** |
||
78 | * @inheritdoc |
||
79 | */ |
||
80 | 2 | public function getPaginationParameters() |
|
87 | |||
88 | /** |
||
89 | * Sets sorting parameters |
||
90 | * |
||
91 | * @param SortParameterInterface[]|null $sorting |
||
92 | * @return $this |
||
93 | */ |
||
94 | 2 | public function setSortParameters(array $sorting = null) |
|
100 | |||
101 | /** |
||
102 | * @inheritdoc |
||
103 | */ |
||
104 | 1 | public function getSortParameters() |
|
108 | |||
109 | /** |
||
110 | * Parse sorting parameters string |
||
111 | * |
||
112 | * @param string $value |
||
113 | * @return array |
||
114 | */ |
||
115 | 3 | public function parseSortingParameters($value) |
|
139 | |||
140 | /** |
||
141 | * Validate sort parameters |
||
142 | * |
||
143 | * @param ExecutionContextInterface $context |
||
144 | * @Assert\Callback() |
||
145 | */ |
||
146 | 1 | public function validateSortParameters(ExecutionContextInterface $context) |
|
170 | |||
171 | /** |
||
172 | * Validate page size |
||
173 | * |
||
174 | * @param ExecutionContextInterface $context |
||
175 | * @Assert\Callback() |
||
176 | */ |
||
177 | 1 | public function validatePageSize(ExecutionContextInterface $context) |
|
193 | |||
194 | /** |
||
195 | * Returns default page size |
||
196 | * |
||
197 | * @return int|null |
||
198 | */ |
||
199 | 1 | protected function getDefaultPageSize() |
|
203 | |||
204 | /** |
||
205 | * Returns max page size |
||
206 | * |
||
207 | * @return int|null |
||
208 | */ |
||
209 | 1 | protected function getMaxPageSize() |
|
213 | |||
214 | /** |
||
215 | * Returns list of supported sorting fields |
||
216 | * |
||
217 | * @return string[] |
||
218 | */ |
||
219 | 1 | protected function getSortableFields() |
|
223 | } |
||
224 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.