Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php namespace Neomerx\JsonApi\Http\Query; |
||
32 | class QueryParametersParser implements QueryParametersParserInterface, LoggerAwareInterface |
||
33 | { |
||
34 | use LoggerAwareTrait; |
||
35 | |||
36 | /** |
||
37 | * @var HttpFactoryInterface |
||
38 | */ |
||
39 | private $factory; |
||
40 | |||
41 | /** |
||
42 | * @param HttpFactoryInterface $factory |
||
43 | */ |
||
44 | 27 | public function __construct(HttpFactoryInterface $factory) |
|
48 | |||
49 | /** |
||
50 | * @inheritdoc |
||
51 | */ |
||
52 | 26 | public function parse(ServerRequestInterface $request) |
|
56 | |||
57 | /** |
||
58 | * @inheritdoc |
||
59 | */ |
||
60 | 26 | public function parseQueryParameters(array $parameters) |
|
71 | |||
72 | /** |
||
73 | * @param array $parameters |
||
74 | * |
||
75 | * @return array|null |
||
76 | */ |
||
77 | 26 | private function getIncludePaths(array $parameters) |
|
84 | |||
85 | /** |
||
86 | * @param array $parameters |
||
87 | * |
||
88 | * @return array|null |
||
89 | * |
||
90 | * @SuppressWarnings(PHPMD.StaticAccess) |
||
91 | */ |
||
92 | 25 | private function getFieldSets(array $parameters) |
|
109 | |||
110 | /** |
||
111 | * @param array $parameters |
||
112 | * |
||
113 | * @return SortParameterInterface[]|null |
||
114 | * |
||
115 | * @SuppressWarnings(PHPMD.StaticAccess) |
||
116 | */ |
||
117 | 24 | protected function getSortParameters(array $parameters) |
|
138 | |||
139 | /** |
||
140 | * @param array $parameters |
||
141 | * |
||
142 | * @return array|null |
||
143 | */ |
||
144 | 21 | private function getPagingParameters(array $parameters) |
|
148 | |||
149 | /** |
||
150 | * @param array $parameters |
||
151 | * |
||
152 | * @return array|null |
||
153 | */ |
||
154 | 20 | private function getFilteringParameters(array $parameters) |
|
158 | |||
159 | /** |
||
160 | * @param array $parameters |
||
161 | * |
||
162 | * @return array|null |
||
163 | */ |
||
164 | 19 | private function getUnrecognizedParameters(array $parameters) |
|
176 | |||
177 | /** |
||
178 | * @param array $parameters |
||
179 | * @param string $name |
||
180 | * |
||
181 | * @return array|null |
||
182 | * |
||
183 | * @SuppressWarnings(PHPMD.StaticAccess) |
||
184 | */ |
||
185 | 21 | View Code Duplication | private function getArrayParamOrNull(array $parameters, $name) |
196 | |||
197 | /** |
||
198 | * @param array $parameters |
||
199 | * @param string $name |
||
200 | * |
||
201 | * @return string|null |
||
202 | * |
||
203 | * @SuppressWarnings(PHPMD.StaticAccess) |
||
204 | */ |
||
205 | 26 | View Code Duplication | private function getStringParamOrNull(array $parameters, $name) |
216 | |||
217 | /** |
||
218 | * @param array $parameters |
||
219 | * @param string $name |
||
220 | * |
||
221 | * @return mixed |
||
222 | */ |
||
223 | 26 | private function getParamOrNull(array $parameters, $name) |
|
227 | |||
228 | /** |
||
229 | * @param string $detail |
||
230 | * |
||
231 | * @return Error[] |
||
232 | * |
||
233 | * @SuppressWarnings(PHPMD.StaticAccess) |
||
234 | */ |
||
235 | 3 | protected function createInvalidQueryErrors($detail) |
|
246 | |||
247 | /** |
||
248 | * @param string $name |
||
249 | * @param string $detail |
||
250 | * |
||
251 | * @return Error[] |
||
252 | * |
||
253 | * @SuppressWarnings(PHPMD.StaticAccess) |
||
254 | */ |
||
255 | 4 | protected function createParamErrors($name, $detail) |
|
269 | } |
||
270 |