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 |
||
20 | class RequestConfiguration |
||
21 | { |
||
22 | /** |
||
23 | * @var Request |
||
24 | */ |
||
25 | private $request; |
||
26 | |||
27 | /** |
||
28 | * @var MetadataInterface |
||
29 | */ |
||
30 | private $metadata; |
||
31 | |||
32 | /** |
||
33 | * @var Parameters |
||
34 | */ |
||
35 | private $parameters; |
||
36 | |||
37 | /** |
||
38 | * @param MetadataInterface $metadata |
||
39 | * @param Request $request |
||
40 | * @param Parameters $parameters |
||
41 | */ |
||
42 | public function __construct(MetadataInterface $metadata, Request $request, Parameters $parameters) |
||
48 | |||
49 | /** |
||
50 | * @return Request |
||
51 | */ |
||
52 | public function getRequest() |
||
56 | |||
57 | /** |
||
58 | * @return MetadataInterface |
||
59 | */ |
||
60 | public function getMetadata() |
||
64 | |||
65 | /** |
||
66 | * @return Parameters |
||
67 | */ |
||
68 | public function getParameters() |
||
72 | |||
73 | /** |
||
74 | * @return string|null |
||
75 | */ |
||
76 | public function getSection() |
||
80 | |||
81 | /** |
||
82 | * @return bool |
||
83 | */ |
||
84 | public function isHtmlRequest() |
||
88 | |||
89 | /** |
||
90 | * @param string $name |
||
91 | * |
||
92 | * @return string|null |
||
93 | */ |
||
94 | public function getDefaultTemplate($name) |
||
104 | |||
105 | /** |
||
106 | * @param string $name |
||
107 | * |
||
108 | * @return mixed|null |
||
109 | */ |
||
110 | public function getTemplate($name) |
||
120 | |||
121 | /** |
||
122 | * @return string|null |
||
123 | */ |
||
124 | public function getFormType() |
||
142 | |||
143 | /** |
||
144 | * @return array |
||
145 | */ |
||
146 | public function getFormOptions() |
||
155 | |||
156 | /** |
||
157 | * @param string $name |
||
158 | * |
||
159 | * @return string |
||
160 | */ |
||
161 | public function getRouteName($name) |
||
167 | |||
168 | /** |
||
169 | * @param string $name |
||
170 | * |
||
171 | * @return mixed|string|null |
||
172 | */ |
||
173 | public function getRedirectRoute($name) |
||
191 | |||
192 | /** |
||
193 | * Get url hash fragment (#text) which is you configured. |
||
194 | * |
||
195 | * @return string |
||
196 | */ |
||
197 | public function getRedirectHash() |
||
207 | |||
208 | /** |
||
209 | * Get redirect referer, This will detected by configuration |
||
210 | * If not exists, The `referrer` from headers will be used. |
||
211 | * |
||
212 | * @return string |
||
213 | */ |
||
214 | public function getRedirectReferer() |
||
229 | |||
230 | /** |
||
231 | * @param object|null $resource |
||
232 | * |
||
233 | * @return array |
||
234 | */ |
||
235 | public function getRedirectParameters($resource = null) |
||
256 | |||
257 | /** |
||
258 | * @param array $parameters |
||
259 | * |
||
260 | * @return array |
||
261 | */ |
||
262 | private function addExtraRedirectParameters($parameters): array |
||
277 | |||
278 | /** |
||
279 | * @return bool |
||
280 | */ |
||
281 | public function isLimited() |
||
285 | |||
286 | /** |
||
287 | * @return int|null |
||
288 | */ |
||
289 | public function getLimit() |
||
299 | |||
300 | /** |
||
301 | * @return bool |
||
302 | */ |
||
303 | public function isPaginated() |
||
309 | |||
310 | /** |
||
311 | * @return int |
||
312 | */ |
||
313 | public function getPaginationMaxPerPage() |
||
317 | |||
318 | /** |
||
319 | * @return bool |
||
320 | */ |
||
321 | public function isFilterable() |
||
325 | |||
326 | /** |
||
327 | * @param array $criteria |
||
328 | * |
||
329 | * @return array |
||
330 | */ |
||
331 | public function getCriteria(array $criteria = []) |
||
341 | |||
342 | /** |
||
343 | * @return bool |
||
344 | */ |
||
345 | public function isSortable() |
||
349 | |||
350 | /** |
||
351 | * @param array $sorting |
||
352 | * |
||
353 | * @return array |
||
354 | */ |
||
355 | public function getSorting(array $sorting = []) |
||
372 | |||
373 | /** |
||
374 | * @param string $parameter |
||
375 | * @param array $defaults |
||
376 | * |
||
377 | * @return array |
||
378 | */ |
||
379 | public function getRequestParameter($parameter, $defaults = []) |
||
386 | |||
387 | /** |
||
388 | * @return array|string|null |
||
389 | */ |
||
390 | public function getRepositoryMethod() |
||
400 | |||
401 | /** |
||
402 | * @return array |
||
403 | */ |
||
404 | public function getRepositoryArguments() |
||
418 | |||
419 | /** |
||
420 | * @return array|string|null |
||
421 | */ |
||
422 | public function getFactoryMethod() |
||
432 | |||
433 | /** |
||
434 | * @return array |
||
435 | */ |
||
436 | public function getFactoryArguments() |
||
450 | |||
451 | /** |
||
452 | * @param null $message |
||
453 | * |
||
454 | * @return mixed|null |
||
455 | */ |
||
456 | public function getFlashMessage($message) |
||
460 | |||
461 | /** |
||
462 | * @return mixed|null |
||
463 | */ |
||
464 | public function getSortablePosition() |
||
468 | |||
469 | /** |
||
470 | * @return mixed|null |
||
471 | */ |
||
472 | public function getSerializationGroups() |
||
476 | |||
477 | /** |
||
478 | * @return mixed|null |
||
479 | */ |
||
480 | public function getSerializationVersion() |
||
484 | |||
485 | /** |
||
486 | * @return string|null |
||
487 | */ |
||
488 | public function getEvent() |
||
492 | |||
493 | /** |
||
494 | * @return bool |
||
495 | */ |
||
496 | public function hasPermission() |
||
500 | |||
501 | /** |
||
502 | * @param string $name |
||
503 | * |
||
504 | * @return string |
||
505 | * |
||
506 | * @throws \LogicException |
||
507 | */ |
||
508 | public function getPermission($name) |
||
522 | |||
523 | /** |
||
524 | * @return bool |
||
525 | */ |
||
526 | public function isHeaderRedirection() |
||
540 | |||
541 | public function getVars() |
||
545 | |||
546 | /** |
||
547 | * @param array $parameters |
||
548 | * @param object $resource |
||
549 | * |
||
550 | * @return array |
||
551 | */ |
||
552 | private function parseResourceValues(array $parameters, $resource): array |
||
572 | |||
573 | /** |
||
574 | * @return bool |
||
575 | */ |
||
576 | public function hasGrid() |
||
580 | |||
581 | /** |
||
582 | * @return string |
||
583 | * |
||
584 | * @throws \LogicException |
||
585 | */ |
||
586 | public function getGrid() |
||
594 | |||
595 | /** |
||
596 | * @return bool |
||
597 | */ |
||
598 | public function hasStateMachine() |
||
602 | |||
603 | /** |
||
604 | * @return string |
||
605 | */ |
||
606 | public function getStateMachineGraph() |
||
612 | |||
613 | /** |
||
614 | * @return string |
||
615 | */ |
||
616 | public function getStateMachineTransition() |
||
622 | |||
623 | /** |
||
624 | * @return bool |
||
625 | */ |
||
626 | public function isCsrfProtectionEnabled() |
||
630 | |||
631 | /** |
||
632 | * @param mixed $redirect |
||
633 | * |
||
634 | * @return bool |
||
635 | */ |
||
636 | private function areParametersIntentionallyEmptyArray($redirect): bool |
||
640 | } |
||
641 |