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) |
|
| 65 | |||
| 66 | /** |
||
| 67 | * @param array $parameters |
||
| 68 | * |
||
| 69 | * @return array|null |
||
| 70 | */ |
||
| 71 | 26 | private function getIncludePaths(array $parameters) |
|
| 78 | |||
| 79 | /** |
||
| 80 | * @param array $parameters |
||
| 81 | * |
||
| 82 | * @return array|null |
||
| 83 | * |
||
| 84 | * @SuppressWarnings(PHPMD.StaticAccess) |
||
| 85 | * @SuppressWarnings(PHPMD.ElseExpression) |
||
| 86 | */ |
||
| 87 | 25 | private function getFieldSets(array $parameters) |
|
| 106 | |||
| 107 | /** |
||
| 108 | * @param array $parameters |
||
| 109 | * |
||
| 110 | * @return SortParameterInterface[]|null |
||
| 111 | * |
||
| 112 | * @SuppressWarnings(PHPMD.StaticAccess) |
||
| 113 | */ |
||
| 114 | 24 | protected function getSortParameters(array $parameters) |
|
| 135 | |||
| 136 | /** |
||
| 137 | * @param array $parameters |
||
| 138 | * |
||
| 139 | * @return array|null |
||
| 140 | */ |
||
| 141 | 21 | private function getPagingParameters(array $parameters) |
|
| 145 | |||
| 146 | /** |
||
| 147 | * @param array $parameters |
||
| 148 | * |
||
| 149 | * @return array|null |
||
| 150 | */ |
||
| 151 | 20 | private function getFilteringParameters(array $parameters) |
|
| 155 | |||
| 156 | /** |
||
| 157 | * @param array $parameters |
||
| 158 | * |
||
| 159 | * @return array|null |
||
| 160 | */ |
||
| 161 | 19 | private function getUnrecognizedParameters(array $parameters) |
|
| 173 | |||
| 174 | /** |
||
| 175 | * @param array $parameters |
||
| 176 | * @param string $name |
||
| 177 | * |
||
| 178 | * @return array|null |
||
| 179 | * |
||
| 180 | * @SuppressWarnings(PHPMD.StaticAccess) |
||
| 181 | */ |
||
| 182 | 21 | View Code Duplication | private function getArrayParamOrNull(array $parameters, $name) |
| 193 | |||
| 194 | /** |
||
| 195 | * @param array $parameters |
||
| 196 | * @param string $name |
||
| 197 | * |
||
| 198 | * @return string|null |
||
| 199 | * |
||
| 200 | * @SuppressWarnings(PHPMD.StaticAccess) |
||
| 201 | */ |
||
| 202 | 26 | View Code Duplication | private function getStringParamOrNull(array $parameters, $name) |
| 213 | |||
| 214 | /** |
||
| 215 | * @param array $parameters |
||
| 216 | * @param string $name |
||
| 217 | * |
||
| 218 | * @return mixed |
||
| 219 | */ |
||
| 220 | 26 | private function getParamOrNull(array $parameters, $name) |
|
| 224 | |||
| 225 | /** |
||
| 226 | * @param string $detail |
||
| 227 | * |
||
| 228 | * @return Error[] |
||
| 229 | * |
||
| 230 | * @SuppressWarnings(PHPMD.StaticAccess) |
||
| 231 | */ |
||
| 232 | 3 | protected function createInvalidQueryErrors($detail) |
|
| 243 | |||
| 244 | /** |
||
| 245 | * @param string $name |
||
| 246 | * @param string $detail |
||
| 247 | * |
||
| 248 | * @return Error[] |
||
| 249 | * |
||
| 250 | * @SuppressWarnings(PHPMD.StaticAccess) |
||
| 251 | */ |
||
| 252 | 4 | protected function createParamErrors($name, $detail) |
|
| 266 | } |
||
| 267 |