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() |
||
82 | { |
||
83 | return $this->parameters->get('section'); |
||
84 | } |
||
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) |
||
103 | |||
104 | /** |
||
105 | * @param $name |
||
106 | * |
||
107 | * @return mixed|null |
||
108 | */ |
||
109 | public function getTemplate($name) |
||
119 | |||
120 | /** |
||
121 | * @return mixed|null |
||
122 | */ |
||
123 | public function getFormType() |
||
133 | |||
134 | /** |
||
135 | * @return mixed|null |
||
136 | */ |
||
137 | public function getFormOptions() |
||
147 | |||
148 | /** |
||
149 | * @param $name |
||
150 | * |
||
151 | * @return string |
||
152 | */ |
||
153 | public function getRouteName($name) |
||
159 | |||
160 | /** |
||
161 | * @param $name |
||
162 | * |
||
163 | * @return mixed|null|string |
||
164 | */ |
||
165 | public function getRedirectRoute($name) |
||
183 | |||
184 | /** |
||
185 | * Get url hash fragment (#text) which is you configured. |
||
186 | * |
||
187 | * @return null|string |
||
188 | */ |
||
189 | public function getRedirectHash() |
||
199 | |||
200 | /** |
||
201 | * Get redirect referer, This will detected by configuration |
||
202 | * If not exists, The `referrer` from headers will be used. |
||
203 | * |
||
204 | * @return null|string |
||
205 | */ |
||
206 | public function getRedirectReferer() |
||
221 | |||
222 | /** |
||
223 | * @param object|null $resource |
||
224 | * |
||
225 | * @return array |
||
226 | */ |
||
227 | public function getRedirectParameters($resource = null) |
||
243 | |||
244 | /** |
||
245 | * @return bool |
||
246 | */ |
||
247 | public function isLimited() |
||
251 | |||
252 | /** |
||
253 | * @return int|null |
||
254 | */ |
||
255 | public function getLimit() |
||
265 | |||
266 | /** |
||
267 | * @return bool |
||
268 | */ |
||
269 | public function isPaginated() |
||
273 | |||
274 | /** |
||
275 | * @return int |
||
276 | */ |
||
277 | public function getPaginationMaxPerPage() |
||
281 | |||
282 | /** |
||
283 | * @return bool |
||
284 | */ |
||
285 | public function isFilterable() |
||
289 | |||
290 | /** |
||
291 | * @param array $criteria |
||
292 | * |
||
293 | * @return array |
||
294 | */ |
||
295 | public function getCriteria(array $criteria = []) |
||
305 | |||
306 | /** |
||
307 | * @return bool |
||
308 | */ |
||
309 | public function isSortable() |
||
313 | |||
314 | /** |
||
315 | * @param array $sorting |
||
316 | * |
||
317 | * @return array |
||
318 | */ |
||
319 | public function getSorting(array $sorting = []) |
||
336 | |||
337 | /** |
||
338 | * @param $parameter |
||
339 | * @param array $defaults |
||
340 | * |
||
341 | * @return array |
||
342 | */ |
||
343 | public function getRequestParameter($parameter, $defaults = []) |
||
350 | |||
351 | /** |
||
352 | * @return string|null |
||
353 | */ |
||
354 | public function getRepositoryMethod() |
||
364 | |||
365 | /** |
||
366 | * @return array |
||
367 | */ |
||
368 | public function getRepositoryArguments() |
||
382 | |||
383 | /** |
||
384 | * @return string|null |
||
385 | */ |
||
386 | public function getFactoryMethod() |
||
396 | |||
397 | /** |
||
398 | * @return array |
||
399 | */ |
||
400 | public function getFactoryArguments() |
||
414 | |||
415 | /** |
||
416 | * @param null $message |
||
417 | * |
||
418 | * @return mixed|null |
||
419 | */ |
||
420 | public function getFlashMessage($message) |
||
424 | |||
425 | /** |
||
426 | * @return mixed|null |
||
427 | */ |
||
428 | public function getSortablePosition() |
||
432 | |||
433 | /** |
||
434 | * @return mixed|null |
||
435 | */ |
||
436 | public function getSerializationGroups() |
||
440 | |||
441 | /** |
||
442 | * @return mixed|null |
||
443 | */ |
||
444 | public function getSerializationVersion() |
||
448 | |||
449 | /** |
||
450 | * @return string|null |
||
451 | */ |
||
452 | public function getEvent() |
||
456 | |||
457 | /** |
||
458 | * @return bool |
||
459 | */ |
||
460 | public function hasPermission() |
||
468 | |||
469 | /** |
||
470 | * @param string $name |
||
471 | * |
||
472 | * @return string |
||
473 | * |
||
474 | * @throws \LogicException |
||
475 | */ |
||
476 | public function getPermission($name) |
||
488 | |||
489 | /** |
||
490 | * @return bool |
||
491 | */ |
||
492 | public function isHeaderRedirection() |
||
506 | |||
507 | /** |
||
508 | * @param array $parameters |
||
509 | * @param object $resource |
||
510 | * |
||
511 | * @return array |
||
512 | */ |
||
513 | private function parseResourceValues(array $parameters, $resource) |
||
533 | } |
||
534 |