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 | private $request; |
||
31 | |||
32 | /** |
||
33 | * @var MetadataInterface |
||
34 | */ |
||
35 | private $metadata; |
||
36 | |||
37 | /** |
||
38 | * @var Parameters |
||
39 | */ |
||
40 | private $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 | * |
||
97 | * @return null|string |
||
98 | */ |
||
99 | public function getDefaultTemplate($name) |
||
100 | { |
||
101 | $templatesNamespace = (string) $this->metadata->getTemplatesNamespace(); |
||
102 | |||
103 | if (false !== strpos($templatesNamespace, ':')) { |
||
104 | return sprintf('%s:%s.%s', $templatesNamespace ?: ':', $name, 'twig'); |
||
105 | } |
||
106 | |||
107 | return sprintf('%s/%s.%s', $templatesNamespace, $name, 'twig'); |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * @param $name |
||
112 | * |
||
113 | * @return mixed|null |
||
114 | */ |
||
115 | public function getTemplate($name) |
||
125 | |||
126 | /** |
||
127 | * @return string|null |
||
128 | */ |
||
129 | public function getFormType() |
||
147 | |||
148 | /** |
||
149 | * @return array |
||
150 | */ |
||
151 | public function getFormOptions() |
||
160 | |||
161 | /** |
||
162 | * @param $name |
||
163 | * |
||
164 | * @return string |
||
165 | */ |
||
166 | public function getRouteName($name) |
||
172 | |||
173 | /** |
||
174 | * @param $name |
||
175 | * |
||
176 | * @return mixed|null|string |
||
177 | */ |
||
178 | public function getRedirectRoute($name) |
||
196 | |||
197 | /** |
||
198 | * Get url hash fragment (#text) which is you configured. |
||
199 | * |
||
200 | * @return string |
||
201 | */ |
||
202 | public function getRedirectHash() |
||
212 | |||
213 | /** |
||
214 | * Get redirect referer, This will detected by configuration |
||
215 | * If not exists, The `referrer` from headers will be used. |
||
216 | * |
||
217 | * @return string |
||
218 | */ |
||
219 | public function getRedirectReferer() |
||
234 | |||
235 | /** |
||
236 | * @param object|null $resource |
||
237 | * |
||
238 | * @return array |
||
239 | */ |
||
240 | public function getRedirectParameters($resource = null) |
||
261 | |||
262 | /** |
||
263 | * @param array $parameters |
||
264 | * |
||
265 | * @return array |
||
266 | */ |
||
267 | private function addExtraRedirectParameters($parameters) |
||
282 | |||
283 | /** |
||
284 | * @return bool |
||
285 | */ |
||
286 | public function isLimited() |
||
290 | |||
291 | /** |
||
292 | * @return int|null |
||
293 | */ |
||
294 | public function getLimit() |
||
304 | |||
305 | /** |
||
306 | * @return bool |
||
307 | */ |
||
308 | public function isPaginated() |
||
312 | |||
313 | /** |
||
314 | * @return int |
||
315 | */ |
||
316 | public function getPaginationMaxPerPage() |
||
320 | |||
321 | /** |
||
322 | * @return bool |
||
323 | */ |
||
324 | public function isFilterable() |
||
328 | |||
329 | /** |
||
330 | * @param array $criteria |
||
331 | * |
||
332 | * @return array |
||
333 | */ |
||
334 | public function getCriteria(array $criteria = []) |
||
344 | |||
345 | /** |
||
346 | * @return bool |
||
347 | */ |
||
348 | public function isSortable() |
||
352 | |||
353 | /** |
||
354 | * @param array $sorting |
||
355 | * |
||
356 | * @return array |
||
357 | */ |
||
358 | public function getSorting(array $sorting = []) |
||
375 | |||
376 | /** |
||
377 | * @param $parameter |
||
378 | * @param array $defaults |
||
379 | * |
||
380 | * @return array |
||
381 | */ |
||
382 | public function getRequestParameter($parameter, $defaults = []) |
||
389 | |||
390 | /** |
||
391 | * @return string|null |
||
392 | */ |
||
393 | public function getRepositoryMethod() |
||
403 | |||
404 | /** |
||
405 | * @return array |
||
406 | */ |
||
407 | public function getRepositoryArguments() |
||
421 | |||
422 | /** |
||
423 | * @return string|null |
||
424 | */ |
||
425 | public function getFactoryMethod() |
||
435 | |||
436 | /** |
||
437 | * @return array |
||
438 | */ |
||
439 | public function getFactoryArguments() |
||
453 | |||
454 | /** |
||
455 | * @param null $message |
||
456 | * |
||
457 | * @return mixed|null |
||
458 | */ |
||
459 | public function getFlashMessage($message) |
||
463 | |||
464 | /** |
||
465 | * @return mixed|null |
||
466 | */ |
||
467 | public function getSortablePosition() |
||
471 | |||
472 | /** |
||
473 | * @return mixed|null |
||
474 | */ |
||
475 | public function getSerializationGroups() |
||
479 | |||
480 | /** |
||
481 | * @return mixed|null |
||
482 | */ |
||
483 | public function getSerializationVersion() |
||
487 | |||
488 | /** |
||
489 | * @return string|null |
||
490 | */ |
||
491 | public function getEvent() |
||
495 | |||
496 | /** |
||
497 | * @return bool |
||
498 | */ |
||
499 | public function hasPermission() |
||
503 | |||
504 | /** |
||
505 | * @param string $name |
||
506 | * |
||
507 | * @return string |
||
508 | * |
||
509 | * @throws \LogicException |
||
510 | */ |
||
511 | public function getPermission($name) |
||
525 | |||
526 | /** |
||
527 | * @return bool |
||
528 | */ |
||
529 | public function isHeaderRedirection() |
||
543 | |||
544 | public function getVars() |
||
548 | |||
549 | /** |
||
550 | * @param array $parameters |
||
551 | * @param object $resource |
||
552 | * |
||
553 | * @return array |
||
554 | */ |
||
555 | private function parseResourceValues(array $parameters, $resource) |
||
575 | |||
576 | /** |
||
577 | * @return bool |
||
578 | */ |
||
579 | public function hasGrid() |
||
583 | |||
584 | /** |
||
585 | * @return string |
||
586 | * |
||
587 | * @throws \LogicException |
||
588 | */ |
||
589 | public function getGrid() |
||
597 | |||
598 | /** |
||
599 | * @return bool |
||
600 | */ |
||
601 | public function hasStateMachine() |
||
605 | |||
606 | /** |
||
607 | * @return string |
||
608 | */ |
||
609 | public function getStateMachineGraph() |
||
615 | |||
616 | /** |
||
617 | * @return string |
||
618 | */ |
||
619 | public function getStateMachineTransition() |
||
625 | |||
626 | /** |
||
627 | * @return bool |
||
628 | */ |
||
629 | public function isCsrfProtectionEnabled() |
||
633 | |||
634 | /** |
||
635 | * @param mixed $redirect |
||
636 | * |
||
637 | * @return bool |
||
638 | */ |
||
639 | private function areParametersIntentionallyEmptyArray($redirect) |
||
643 | } |
||
644 |