Complex classes like RequestConfiguration often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use RequestConfiguration, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 25 | class RequestConfiguration |
||
| 26 | { |
||
| 27 | /** |
||
| 28 | * @var Request |
||
| 29 | */ |
||
| 30 | protected $request; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var MetadataInterface |
||
| 34 | */ |
||
| 35 | protected $metadata; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var Parameters |
||
| 39 | */ |
||
| 40 | protected $parameters; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @param MetadataInterface $metadata |
||
| 44 | * @param Request $request |
||
| 45 | * @param Parameters $parameters |
||
| 46 | */ |
||
| 47 | public function __construct(MetadataInterface $metadata, Request $request, Parameters $parameters) |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @return Request |
||
| 56 | */ |
||
| 57 | public function getRequest() |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @return MetadataInterface |
||
| 64 | */ |
||
| 65 | public function getMetadata() |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @return Parameters |
||
| 72 | */ |
||
| 73 | public function getParameters() |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @return string|null |
||
| 80 | */ |
||
| 81 | public function getSection() |
||
| 85 | |||
| 86 | /** |
||
| 87 | * @return bool |
||
| 88 | */ |
||
| 89 | public function isHtmlRequest() |
||
| 93 | |||
| 94 | /** |
||
| 95 | * @param $name |
||
| 96 | * @return null|string |
||
| 97 | */ |
||
| 98 | public function getDefaultTemplate($name) |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @param $name |
||
| 105 | * @return mixed|null |
||
| 106 | */ |
||
| 107 | public function getTemplate($name) |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @return mixed|null |
||
| 120 | */ |
||
| 121 | public function getFormType() |
||
| 125 | |||
| 126 | /** |
||
| 127 | * @param $name |
||
| 128 | * @return string |
||
| 129 | */ |
||
| 130 | public function getRouteName($name) |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @param $name |
||
| 139 | * |
||
| 140 | * @return mixed|null|string |
||
| 141 | */ |
||
| 142 | public function getRedirectRoute($name) |
||
| 160 | |||
| 161 | /** |
||
| 162 | * Get url hash fragment (#text) which is you configured. |
||
| 163 | * |
||
| 164 | * @return null|string |
||
| 165 | */ |
||
| 166 | public function getRedirectHash() |
||
| 176 | |||
| 177 | /** |
||
| 178 | * Get redirect referer, This will detected by configuration |
||
| 179 | * If not exists, The `referrer` from headers will be used. |
||
| 180 | * |
||
| 181 | * @return null|string |
||
| 182 | */ |
||
| 183 | public function getRedirectReferer() |
||
| 198 | |||
| 199 | /** |
||
| 200 | * @param object|null $resource |
||
| 201 | * |
||
| 202 | * @return array |
||
| 203 | */ |
||
| 204 | public function getRedirectParameters($resource = null) |
||
| 220 | |||
| 221 | /** |
||
| 222 | * @return bool |
||
| 223 | */ |
||
| 224 | public function isLimited() |
||
| 228 | |||
| 229 | /** |
||
| 230 | * @return int|null |
||
| 231 | */ |
||
| 232 | public function getLimit() |
||
| 242 | |||
| 243 | /** |
||
| 244 | * @return bool |
||
| 245 | */ |
||
| 246 | public function isPaginated() |
||
| 250 | |||
| 251 | /** |
||
| 252 | * @return int |
||
| 253 | */ |
||
| 254 | public function getPaginationMaxPerPage() |
||
| 258 | |||
| 259 | /** |
||
| 260 | * @return bool |
||
| 261 | */ |
||
| 262 | public function isFilterable() |
||
| 266 | |||
| 267 | /** |
||
| 268 | * @param array $criteria |
||
| 269 | * |
||
| 270 | * @return array |
||
| 271 | */ |
||
| 272 | public function getCriteria(array $criteria = array()) |
||
| 282 | |||
| 283 | /** |
||
| 284 | * @return bool |
||
| 285 | */ |
||
| 286 | public function isSortable() |
||
| 290 | |||
| 291 | /** |
||
| 292 | * @param array $sorting |
||
| 293 | * @return array |
||
| 294 | */ |
||
| 295 | public function getSorting(array $sorting = array()) |
||
| 312 | |||
| 313 | /** |
||
| 314 | * @param $parameter |
||
| 315 | * @param array $defaults |
||
| 316 | * |
||
| 317 | * @return array |
||
| 318 | */ |
||
| 319 | public function getRequestParameter($parameter, $defaults = array()) |
||
| 326 | |||
| 327 | /** |
||
| 328 | * @return string|null |
||
| 329 | */ |
||
| 330 | public function getRepositoryMethod() |
||
| 340 | |||
| 341 | /** |
||
| 342 | * @return array |
||
| 343 | */ |
||
| 344 | public function getRepositoryArguments() |
||
| 358 | |||
| 359 | /** |
||
| 360 | * @return string|null |
||
| 361 | */ |
||
| 362 | public function getFactoryMethod() |
||
| 372 | |||
| 373 | /** |
||
| 374 | * @return array |
||
| 375 | */ |
||
| 376 | public function getFactoryArguments() |
||
| 390 | |||
| 391 | /** |
||
| 392 | * @param null $message |
||
| 393 | * @return mixed|null |
||
| 394 | */ |
||
| 395 | public function getFlashMessage($message) |
||
| 399 | |||
| 400 | /** |
||
| 401 | * @return mixed|null |
||
| 402 | */ |
||
| 403 | public function getSortablePosition() |
||
| 407 | |||
| 408 | /** |
||
| 409 | * @return mixed|null |
||
| 410 | */ |
||
| 411 | public function getSerializationGroups() |
||
| 415 | |||
| 416 | /** |
||
| 417 | * @return mixed|null |
||
| 418 | */ |
||
| 419 | public function getSerializationVersion() |
||
| 423 | |||
| 424 | /** |
||
| 425 | * @return string|null |
||
| 426 | */ |
||
| 427 | public function getEvent() |
||
| 431 | |||
| 432 | /** |
||
| 433 | * @return bool |
||
| 434 | */ |
||
| 435 | public function hasPermission() |
||
| 443 | |||
| 444 | /** |
||
| 445 | * @param string $name |
||
| 446 | * |
||
| 447 | * @return string |
||
| 448 | * |
||
| 449 | * @throws \LogicException |
||
| 450 | */ |
||
| 451 | public function getPermission($name) |
||
| 463 | |||
| 464 | /** |
||
| 465 | * @return bool |
||
| 466 | */ |
||
| 467 | public function isHeaderRedirection() |
||
| 481 | |||
| 482 | /** |
||
| 483 | * @param array $parameters |
||
| 484 | * @param object $resource |
||
| 485 | * |
||
| 486 | * @return array |
||
| 487 | */ |
||
| 488 | private function parseResourceValues(array $parameters, $resource) |
||
| 508 | } |
||
| 509 |