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|null |
||
126 | */ |
||
127 | public function getFormType() |
||
145 | |||
146 | /** |
||
147 | * @return array |
||
148 | */ |
||
149 | public function getFormOptions() |
||
158 | |||
159 | /** |
||
160 | * @param $name |
||
161 | * |
||
162 | * @return string |
||
163 | */ |
||
164 | public function getRouteName($name) |
||
170 | |||
171 | /** |
||
172 | * @param $name |
||
173 | * |
||
174 | * @return mixed|null|string |
||
175 | */ |
||
176 | public function getRedirectRoute($name) |
||
194 | |||
195 | /** |
||
196 | * Get url hash fragment (#text) which is you configured. |
||
197 | * |
||
198 | * @return null|string |
||
199 | */ |
||
200 | public function getRedirectHash() |
||
210 | |||
211 | /** |
||
212 | * Get redirect referer, This will detected by configuration |
||
213 | * If not exists, The `referrer` from headers will be used. |
||
214 | * |
||
215 | * @return null|string |
||
216 | */ |
||
217 | public function getRedirectReferer() |
||
232 | |||
233 | /** |
||
234 | * @param object|null $resource |
||
235 | * |
||
236 | * @return array |
||
237 | */ |
||
238 | public function getRedirectParameters($resource = null) |
||
258 | |||
259 | /** |
||
260 | * @return bool |
||
261 | */ |
||
262 | public function isLimited() |
||
266 | |||
267 | /** |
||
268 | * @return int|null |
||
269 | */ |
||
270 | public function getLimit() |
||
280 | |||
281 | /** |
||
282 | * @return bool |
||
283 | */ |
||
284 | public function isPaginated() |
||
288 | |||
289 | /** |
||
290 | * @return int |
||
291 | */ |
||
292 | public function getPaginationMaxPerPage() |
||
296 | |||
297 | /** |
||
298 | * @return bool |
||
299 | */ |
||
300 | public function isFilterable() |
||
304 | |||
305 | /** |
||
306 | * @param array $criteria |
||
307 | * |
||
308 | * @return array |
||
309 | */ |
||
310 | public function getCriteria(array $criteria = []) |
||
320 | |||
321 | /** |
||
322 | * @return bool |
||
323 | */ |
||
324 | public function isSortable() |
||
328 | |||
329 | /** |
||
330 | * @param array $sorting |
||
331 | * |
||
332 | * @return array |
||
333 | */ |
||
334 | public function getSorting(array $sorting = []) |
||
351 | |||
352 | /** |
||
353 | * @param $parameter |
||
354 | * @param array $defaults |
||
355 | * |
||
356 | * @return array |
||
357 | */ |
||
358 | public function getRequestParameter($parameter, $defaults = []) |
||
365 | |||
366 | /** |
||
367 | * @return string|null |
||
368 | */ |
||
369 | public function getRepositoryMethod() |
||
379 | |||
380 | /** |
||
381 | * @return array |
||
382 | */ |
||
383 | public function getRepositoryArguments() |
||
397 | |||
398 | /** |
||
399 | * @return string|null |
||
400 | */ |
||
401 | public function getFactoryMethod() |
||
411 | |||
412 | /** |
||
413 | * @return array |
||
414 | */ |
||
415 | public function getFactoryArguments() |
||
429 | |||
430 | /** |
||
431 | * @param null $message |
||
432 | * |
||
433 | * @return mixed|null |
||
434 | */ |
||
435 | public function getFlashMessage($message) |
||
439 | |||
440 | /** |
||
441 | * @return mixed|null |
||
442 | */ |
||
443 | public function getSortablePosition() |
||
447 | |||
448 | /** |
||
449 | * @return mixed|null |
||
450 | */ |
||
451 | public function getSerializationGroups() |
||
455 | |||
456 | /** |
||
457 | * @return mixed|null |
||
458 | */ |
||
459 | public function getSerializationVersion() |
||
463 | |||
464 | /** |
||
465 | * @return string|null |
||
466 | */ |
||
467 | public function getEvent() |
||
471 | |||
472 | /** |
||
473 | * @return bool |
||
474 | */ |
||
475 | public function hasPermission() |
||
479 | |||
480 | /** |
||
481 | * @param string $name |
||
482 | * |
||
483 | * @return string |
||
484 | * |
||
485 | * @throws \LogicException |
||
486 | */ |
||
487 | public function getPermission($name) |
||
501 | |||
502 | /** |
||
503 | * @return bool |
||
504 | */ |
||
505 | public function isHeaderRedirection() |
||
519 | |||
520 | public function getVars() |
||
524 | |||
525 | /** |
||
526 | * @param array $parameters |
||
527 | * @param object $resource |
||
528 | * |
||
529 | * @return array |
||
530 | */ |
||
531 | private function parseResourceValues(array $parameters, $resource) |
||
551 | |||
552 | /** |
||
553 | * @return bool |
||
554 | */ |
||
555 | public function hasGrid() |
||
559 | |||
560 | /** |
||
561 | * @return string |
||
562 | * |
||
563 | * @throws \LogicException |
||
564 | */ |
||
565 | public function getGrid() |
||
573 | |||
574 | /** |
||
575 | * @return bool |
||
576 | */ |
||
577 | public function hasStateMachine() |
||
581 | |||
582 | /** |
||
583 | * @return string |
||
584 | */ |
||
585 | public function getStateMachineGraph() |
||
591 | |||
592 | /** |
||
593 | * @return string |
||
594 | */ |
||
595 | public function getStateMachineTransition() |
||
601 | |||
602 | /** |
||
603 | * @return bool |
||
604 | */ |
||
605 | public function isCsrfProtectionEnabled() |
||
609 | |||
610 | /** |
||
611 | * @param mixed $redirect |
||
612 | * |
||
613 | * @return bool |
||
614 | */ |
||
615 | private function areParametersIntentionallyEmptyArray($redirect) |
||
619 | } |
||
620 |