Complex classes like Pool 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 Pool, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
25 | class Pool |
||
26 | { |
||
27 | /** |
||
28 | * @var ContainerInterface |
||
29 | */ |
||
30 | protected $container; |
||
31 | |||
32 | /** |
||
33 | * @var string[] |
||
34 | */ |
||
35 | protected $adminServiceIds = []; |
||
36 | |||
37 | /** |
||
38 | * @var array |
||
39 | */ |
||
40 | protected $adminGroups = []; |
||
41 | |||
42 | /** |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $adminClasses = []; |
||
46 | |||
47 | /** |
||
48 | * @deprecated since 3.34, will be dropped in 4.0. Use TemplateRegistry "sonata.admin.global_template_registry" instead |
||
49 | * |
||
50 | * @var array |
||
51 | */ |
||
52 | protected $templates = []; |
||
53 | |||
54 | /** |
||
55 | * @var array |
||
56 | */ |
||
57 | protected $assets = []; |
||
58 | |||
59 | /** |
||
60 | * @var string |
||
61 | */ |
||
62 | protected $title; |
||
63 | |||
64 | /** |
||
65 | * @var string |
||
66 | */ |
||
67 | protected $titleLogo; |
||
68 | |||
69 | /** |
||
70 | * @var array |
||
71 | */ |
||
72 | protected $options; |
||
73 | |||
74 | /** |
||
75 | * @var PropertyAccessorInterface |
||
76 | */ |
||
77 | protected $propertyAccessor; |
||
78 | |||
79 | /** |
||
80 | * @var MutableTemplateRegistryInterface |
||
81 | */ |
||
82 | private $templateRegistry; |
||
83 | |||
84 | /** |
||
85 | * @param string $title |
||
86 | * @param string $logoTitle |
||
87 | * @param array $options |
||
88 | */ |
||
89 | public function __construct( |
||
102 | |||
103 | /** |
||
104 | * @return array |
||
105 | */ |
||
106 | public function getGroups() |
||
118 | |||
119 | /** |
||
120 | * Returns whether an admin group exists or not. |
||
121 | * |
||
122 | * @param string $group |
||
123 | * |
||
124 | * @return bool |
||
125 | */ |
||
126 | public function hasGroup($group) |
||
130 | |||
131 | /** |
||
132 | * @return array |
||
133 | */ |
||
134 | public function getDashboardGroups() |
||
163 | |||
164 | /** |
||
165 | * Returns all admins related to the given $group. |
||
166 | * |
||
167 | * @param string $group |
||
168 | * |
||
169 | * @throws \InvalidArgumentException |
||
170 | * |
||
171 | * @return AdminInterface[] |
||
172 | */ |
||
173 | public function getAdminsByGroup($group) |
||
191 | |||
192 | /** |
||
193 | * Return the admin related to the given $class. |
||
194 | * |
||
195 | * @param string $class |
||
196 | * |
||
197 | * @return \Sonata\AdminBundle\Admin\AdminInterface|null |
||
198 | */ |
||
199 | public function getAdminByClass($class) |
||
219 | |||
220 | /** |
||
221 | * @param string $class |
||
222 | * |
||
223 | * @return bool |
||
224 | */ |
||
225 | public function hasAdminByClass($class) |
||
229 | |||
230 | /** |
||
231 | * Returns an admin class by its Admin code |
||
232 | * ie : sonata.news.admin.post|sonata.news.admin.comment => return the child class of post. |
||
233 | * |
||
234 | * @param string $adminCode |
||
235 | * |
||
236 | * @throws \InvalidArgumentException if the root admin code is an empty string |
||
237 | * |
||
238 | * @return \Sonata\AdminBundle\Admin\AdminInterface|false |
||
239 | */ |
||
240 | public function getAdminByAdminCode($adminCode) |
||
293 | |||
294 | /** |
||
295 | * Returns a new admin instance depends on the given code. |
||
296 | * |
||
297 | * @param string $id |
||
298 | * |
||
299 | * @throws \InvalidArgumentException |
||
300 | * |
||
301 | * @return AdminInterface |
||
302 | */ |
||
303 | public function getInstance($id) |
||
341 | |||
342 | /** |
||
343 | * @return ContainerInterface|null |
||
344 | */ |
||
345 | public function getContainer() |
||
349 | |||
350 | public function setAdminGroups(array $adminGroups) |
||
354 | |||
355 | /** |
||
356 | * @return array |
||
357 | */ |
||
358 | public function getAdminGroups() |
||
362 | |||
363 | public function setAdminServiceIds(array $adminServiceIds) |
||
367 | |||
368 | /** |
||
369 | * @return array |
||
370 | */ |
||
371 | public function getAdminServiceIds() |
||
375 | |||
376 | public function setAdminClasses(array $adminClasses) |
||
380 | |||
381 | /** |
||
382 | * @return array |
||
383 | */ |
||
384 | public function getAdminClasses() |
||
388 | |||
389 | final public function setTemplateRegistry(MutableTemplateRegistryInterface $templateRegistry) |
||
393 | |||
394 | /** |
||
395 | * @deprecated since 3.34, will be dropped in 4.0. Use TemplateRegistry "sonata.admin.global_template_registry" instead |
||
396 | */ |
||
397 | public function setTemplates(array $templates) |
||
404 | |||
405 | /** |
||
406 | * @deprecated since 3.34, will be dropped in 4.0. Use TemplateRegistry "sonata.admin.global_template_registry" instead |
||
407 | * |
||
408 | * @return array |
||
409 | */ |
||
410 | public function getTemplates() |
||
414 | |||
415 | /** |
||
416 | * @deprecated since 3.34, will be dropped in 4.0. Use TemplateRegistry "sonata.admin.global_template_registry" instead |
||
417 | * |
||
418 | * @param string $name |
||
419 | * |
||
420 | * @return string|null |
||
421 | */ |
||
422 | public function getTemplate($name) |
||
426 | |||
427 | /** |
||
428 | * @return string |
||
429 | */ |
||
430 | public function getTitleLogo() |
||
434 | |||
435 | /** |
||
436 | * @return string |
||
437 | */ |
||
438 | public function getTitle() |
||
442 | |||
443 | /** |
||
444 | * @param string $name |
||
445 | * @param mixed $default |
||
446 | * |
||
447 | * @return mixed |
||
448 | */ |
||
449 | public function getOption($name, $default = null) |
||
457 | |||
458 | public function getPropertyAccessor() |
||
466 | } |
||
467 |
If you suppress an error, we recommend checking for the error condition explicitly: