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 |
||
| 25 | class QueryParameters implements EncodingParametersInterface |
||
| 26 | { |
||
| 27 | const INVALID_INCLUDE_PATHS = '9f4922b8-8e8b-4847-baf2-5831adfd6813'; |
||
| 28 | const INVALID_FIELD_SET = 'ec7d2c6b-97d1-4f94-ba94-d141d985fc6f'; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var string[]|null |
||
| 32 | * @API\Property(path="[include]", parser="parseIncludePaths") |
||
| 33 | * @Assert\Type(type="array") |
||
| 34 | * @Assert\All({@Assert\Type(type="string")}) |
||
| 35 | */ |
||
| 36 | protected $includePaths; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var array[]|null |
||
| 40 | * @API\Property(path="[fields]", parser="parseFieldSets") |
||
| 41 | * @Assert\Type(type="array") |
||
| 42 | * @Assert\All({@Assert\Type(type="string")}) |
||
| 43 | */ |
||
| 44 | protected $fieldSets; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @inheritdoc |
||
| 48 | */ |
||
| 49 | 2 | public function getIncludePaths() |
|
| 53 | |||
| 54 | /** |
||
| 55 | * Sets include paths |
||
| 56 | * |
||
| 57 | * @param string[]|null $paths |
||
| 58 | * @return $this |
||
| 59 | */ |
||
| 60 | 3 | public function setIncludePaths(array $paths = null) |
|
| 66 | |||
| 67 | /** |
||
| 68 | * @inheritdoc |
||
| 69 | */ |
||
| 70 | 1 | public function getFieldSets() |
|
| 74 | |||
| 75 | /** |
||
| 76 | * @inheritdoc |
||
| 77 | */ |
||
| 78 | 1 | public function getFieldSet($type) |
|
| 82 | |||
| 83 | /** |
||
| 84 | * @param \array[]|null $fieldSets |
||
| 85 | * @return $this |
||
| 86 | */ |
||
| 87 | 3 | public function setFieldSets(array $fieldSets = null) |
|
| 93 | |||
| 94 | /** |
||
| 95 | * @inheritdoc |
||
| 96 | */ |
||
| 97 | 1 | public function getSortParameters() |
|
| 101 | |||
| 102 | /** |
||
| 103 | * @inheritdoc |
||
| 104 | */ |
||
| 105 | 1 | public function getPaginationParameters() |
|
| 109 | |||
| 110 | /** |
||
| 111 | * @inheritdoc |
||
| 112 | */ |
||
| 113 | 1 | public function getFilteringParameters() |
|
| 117 | |||
| 118 | /** |
||
| 119 | * @inheritdoc |
||
| 120 | */ |
||
| 121 | public function getUnrecognizedParameters() |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @inheritdoc |
||
| 128 | */ |
||
| 129 | 1 | public function isEmpty() |
|
| 142 | |||
| 143 | /** |
||
| 144 | * Parse value of parameter that store include paths |
||
| 145 | * which should be included into response |
||
| 146 | * |
||
| 147 | * @param string|null $value |
||
| 148 | * @return array|null |
||
| 149 | */ |
||
| 150 | 2 | public function parseIncludePaths($value = null) { |
|
| 161 | |||
| 162 | /** |
||
| 163 | * Parse value of parameter that store fields which |
||
| 164 | * should be included into response |
||
| 165 | * |
||
| 166 | * @param array|null $value |
||
| 167 | * @return array|null |
||
| 168 | */ |
||
| 169 | 2 | public function parseFieldSets($value = null) { |
|
| 184 | |||
| 185 | /** |
||
| 186 | * Validate specified include paths |
||
| 187 | * |
||
| 188 | * @param ExecutionContextInterface $context |
||
| 189 | * @Assert\Callback() |
||
| 190 | */ |
||
| 191 | 1 | public function validateIncludePaths(ExecutionContextInterface $context) |
|
| 209 | |||
| 210 | /** |
||
| 211 | * Validate specified fields sets |
||
| 212 | * |
||
| 213 | * @param ExecutionContextInterface $context |
||
| 214 | * @Assert\Callback() |
||
| 215 | */ |
||
| 216 | 1 | public function validateFieldSets(ExecutionContextInterface $context) |
|
| 237 | |||
| 238 | /** |
||
| 239 | * Returns list of allowed include paths |
||
| 240 | * |
||
| 241 | * @return string[] |
||
| 242 | */ |
||
| 243 | 1 | protected function getAllowedIncludePaths() |
|
| 247 | |||
| 248 | /** |
||
| 249 | * Returns list of fields available in specified resource |
||
| 250 | * |
||
| 251 | * @param string $resource |
||
| 252 | * @return array[] |
||
| 253 | */ |
||
| 254 | 1 | protected function getAllowedFields($resource) |
|
| 258 | } |
||
| 259 |