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 |
||
| 23 | class RequestConfiguration |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * @var Request |
||
| 27 | */ |
||
| 28 | private $request; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var MetadataInterface |
||
| 32 | */ |
||
| 33 | private $metadata; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var Parameters |
||
| 37 | */ |
||
| 38 | private $parameters; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @param MetadataInterface $metadata |
||
| 42 | * @param Request $request |
||
| 43 | * @param Parameters $parameters |
||
| 44 | */ |
||
| 45 | public function __construct(MetadataInterface $metadata, Request $request, Parameters $parameters) |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @return Request |
||
| 54 | */ |
||
| 55 | public function getRequest() |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @return MetadataInterface |
||
| 62 | */ |
||
| 63 | public function getMetadata() |
||
| 67 | |||
| 68 | /** |
||
| 69 | * @return Parameters |
||
| 70 | */ |
||
| 71 | public function getParameters() |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @return string|null |
||
| 78 | */ |
||
| 79 | public function getSection() |
||
| 83 | |||
| 84 | /** |
||
| 85 | * @return bool |
||
| 86 | */ |
||
| 87 | public function isHtmlRequest() |
||
| 91 | |||
| 92 | /** |
||
| 93 | * @param $name |
||
| 94 | * |
||
| 95 | * @return null|string |
||
| 96 | */ |
||
| 97 | public function getDefaultTemplate($name) |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @param $name |
||
| 110 | * |
||
| 111 | * @return mixed|null |
||
| 112 | */ |
||
| 113 | public function getTemplate($name) |
||
| 123 | |||
| 124 | /** |
||
| 125 | * @return string |
||
| 126 | */ |
||
| 127 | public function getFormType() |
||
| 131 | |||
| 132 | /** |
||
| 133 | * @return array |
||
| 134 | */ |
||
| 135 | public function getFormOptions() |
||
| 139 | |||
| 140 | /** |
||
| 141 | * @param $name |
||
| 142 | * |
||
| 143 | * @return string |
||
| 144 | */ |
||
| 145 | public function getRouteName($name) |
||
| 151 | |||
| 152 | /** |
||
| 153 | * @param $name |
||
| 154 | * |
||
| 155 | * @return mixed|null|string |
||
| 156 | */ |
||
| 157 | public function getRedirectRoute($name) |
||
| 175 | |||
| 176 | /** |
||
| 177 | * Get url hash fragment (#text) which is you configured. |
||
| 178 | * |
||
| 179 | * @return null|string |
||
| 180 | */ |
||
| 181 | public function getRedirectHash() |
||
| 191 | |||
| 192 | /** |
||
| 193 | * Get redirect referer, This will detected by configuration |
||
| 194 | * If not exists, The `referrer` from headers will be used. |
||
| 195 | * |
||
| 196 | * @return null|string |
||
| 197 | */ |
||
| 198 | public function getRedirectReferer() |
||
| 213 | |||
| 214 | /** |
||
| 215 | * @param object|null $resource |
||
| 216 | * |
||
| 217 | * @return array |
||
| 218 | */ |
||
| 219 | public function getRedirectParameters($resource = null) |
||
| 239 | |||
| 240 | /** |
||
| 241 | * @return bool |
||
| 242 | */ |
||
| 243 | public function isLimited() |
||
| 247 | |||
| 248 | /** |
||
| 249 | * @return int|null |
||
| 250 | */ |
||
| 251 | public function getLimit() |
||
| 261 | |||
| 262 | /** |
||
| 263 | * @return bool |
||
| 264 | */ |
||
| 265 | public function isPaginated() |
||
| 269 | |||
| 270 | /** |
||
| 271 | * @return int |
||
| 272 | */ |
||
| 273 | public function getPaginationMaxPerPage() |
||
| 277 | |||
| 278 | /** |
||
| 279 | * @return bool |
||
| 280 | */ |
||
| 281 | public function isFilterable() |
||
| 285 | |||
| 286 | /** |
||
| 287 | * @param array $criteria |
||
| 288 | * |
||
| 289 | * @return array |
||
| 290 | */ |
||
| 291 | public function getCriteria(array $criteria = []) |
||
| 301 | |||
| 302 | /** |
||
| 303 | * @return bool |
||
| 304 | */ |
||
| 305 | public function isSortable() |
||
| 309 | |||
| 310 | /** |
||
| 311 | * @param array $sorting |
||
| 312 | * |
||
| 313 | * @return array |
||
| 314 | */ |
||
| 315 | public function getSorting(array $sorting = []) |
||
| 332 | |||
| 333 | /** |
||
| 334 | * @param $parameter |
||
| 335 | * @param array $defaults |
||
| 336 | * |
||
| 337 | * @return array |
||
| 338 | */ |
||
| 339 | public function getRequestParameter($parameter, $defaults = []) |
||
| 346 | |||
| 347 | /** |
||
| 348 | * @return string|null |
||
| 349 | */ |
||
| 350 | public function getRepositoryMethod() |
||
| 360 | |||
| 361 | /** |
||
| 362 | * @return array |
||
| 363 | */ |
||
| 364 | public function getRepositoryArguments() |
||
| 378 | |||
| 379 | /** |
||
| 380 | * @return string|null |
||
| 381 | */ |
||
| 382 | public function getFactoryMethod() |
||
| 392 | |||
| 393 | /** |
||
| 394 | * @return array |
||
| 395 | */ |
||
| 396 | public function getFactoryArguments() |
||
| 410 | |||
| 411 | /** |
||
| 412 | * @param null $message |
||
| 413 | * |
||
| 414 | * @return mixed|null |
||
| 415 | */ |
||
| 416 | public function getFlashMessage($message) |
||
| 420 | |||
| 421 | /** |
||
| 422 | * @return mixed|null |
||
| 423 | */ |
||
| 424 | public function getSortablePosition() |
||
| 428 | |||
| 429 | /** |
||
| 430 | * @return mixed|null |
||
| 431 | */ |
||
| 432 | public function getSerializationGroups() |
||
| 436 | |||
| 437 | /** |
||
| 438 | * @return mixed|null |
||
| 439 | */ |
||
| 440 | public function getSerializationVersion() |
||
| 444 | |||
| 445 | /** |
||
| 446 | * @return string|null |
||
| 447 | */ |
||
| 448 | public function getEvent() |
||
| 452 | |||
| 453 | /** |
||
| 454 | * @return bool |
||
| 455 | */ |
||
| 456 | public function hasPermission() |
||
| 460 | |||
| 461 | /** |
||
| 462 | * @param string $name |
||
| 463 | * |
||
| 464 | * @return string |
||
| 465 | * |
||
| 466 | * @throws \LogicException |
||
| 467 | */ |
||
| 468 | public function getPermission($name) |
||
| 482 | |||
| 483 | /** |
||
| 484 | * @return bool |
||
| 485 | */ |
||
| 486 | public function isHeaderRedirection() |
||
| 500 | |||
| 501 | public function getVars() |
||
| 505 | |||
| 506 | /** |
||
| 507 | * @param array $parameters |
||
| 508 | * @param object $resource |
||
| 509 | * |
||
| 510 | * @return array |
||
| 511 | */ |
||
| 512 | private function parseResourceValues(array $parameters, $resource) |
||
| 532 | |||
| 533 | /** |
||
| 534 | * @return bool |
||
| 535 | */ |
||
| 536 | public function hasGrid() |
||
| 540 | |||
| 541 | /** |
||
| 542 | * @return string |
||
| 543 | * |
||
| 544 | * @throws \LogicException |
||
| 545 | */ |
||
| 546 | public function getGrid() |
||
| 554 | |||
| 555 | /** |
||
| 556 | * @return bool |
||
| 557 | */ |
||
| 558 | public function hasStateMachine() |
||
| 562 | |||
| 563 | /** |
||
| 564 | * @return string |
||
| 565 | */ |
||
| 566 | public function getStateMachineGraph() |
||
| 572 | |||
| 573 | /** |
||
| 574 | * @return string |
||
| 575 | */ |
||
| 576 | public function getStateMachineTransition() |
||
| 582 | |||
| 583 | /** |
||
| 584 | * @param mixed $redirect |
||
| 585 | * |
||
| 586 | * @return bool |
||
| 587 | */ |
||
| 588 | private function areParametersIntentionallyEmptyArray($redirect) |
||
| 592 | |||
| 593 | /** |
||
| 594 | * @param string $option |
||
| 595 | * |
||
| 596 | * @return array|null|string |
||
| 597 | */ |
||
| 598 | private function getFormConfiguration($option) |
||
| 624 | } |
||
| 625 |