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 |
||
21 | class Pool |
||
22 | { |
||
23 | /** |
||
24 | * @var ContainerInterface |
||
25 | */ |
||
26 | protected $container; |
||
27 | |||
28 | /** |
||
29 | * @var string[] |
||
30 | */ |
||
31 | protected $adminServiceIds = array(); |
||
32 | |||
33 | /** |
||
34 | * @var array |
||
35 | */ |
||
36 | protected $adminGroups = array(); |
||
37 | |||
38 | /** |
||
39 | * @var array |
||
40 | */ |
||
41 | protected $adminClasses = array(); |
||
42 | |||
43 | /** |
||
44 | * @var string[] |
||
45 | */ |
||
46 | protected $templates = array(); |
||
47 | |||
48 | /** |
||
49 | * @var array |
||
50 | */ |
||
51 | protected $assets = array(); |
||
52 | |||
53 | /** |
||
54 | * @var string |
||
55 | */ |
||
56 | protected $title; |
||
57 | |||
58 | /** |
||
59 | * @var string |
||
60 | */ |
||
61 | protected $titleLogo; |
||
62 | |||
63 | /** |
||
64 | * @var array |
||
65 | */ |
||
66 | protected $options; |
||
67 | |||
68 | /** |
||
69 | * @var PropertyAccessorInterface |
||
70 | */ |
||
71 | protected $propertyAccessor; |
||
72 | |||
73 | /** |
||
74 | * @param ContainerInterface $container |
||
75 | * @param string $title |
||
76 | * @param string $logoTitle |
||
77 | * @param array $options |
||
78 | */ |
||
79 | public function __construct(ContainerInterface $container, $title, $logoTitle, $options = array(), PropertyAccessorInterface $propertyAccessor = null) |
||
87 | |||
88 | /** |
||
89 | * @return array |
||
90 | */ |
||
91 | public function getGroups() |
||
103 | |||
104 | /** |
||
105 | * Returns whether an admin group exists or not. |
||
106 | * |
||
107 | * @param string $group |
||
108 | * |
||
109 | * @return bool |
||
110 | */ |
||
111 | public function hasGroup($group) |
||
115 | |||
116 | /** |
||
117 | * @return array |
||
118 | */ |
||
119 | public function getDashboardGroups() |
||
148 | |||
149 | /** |
||
150 | * Returns all admins related to the given $group. |
||
151 | * |
||
152 | * @param string $group |
||
153 | * |
||
154 | * @return array |
||
155 | * |
||
156 | * @throws \InvalidArgumentException |
||
157 | */ |
||
158 | public function getAdminsByGroup($group) |
||
176 | |||
177 | /** |
||
178 | * Return the admin related to the given $class. |
||
179 | * |
||
180 | * @param string $class |
||
181 | * |
||
182 | * @return \Sonata\AdminBundle\Admin\AdminInterface|null |
||
183 | */ |
||
184 | public function getAdminByClass($class) |
||
204 | |||
205 | /** |
||
206 | * @param string $class |
||
207 | * |
||
208 | * @return bool |
||
209 | */ |
||
210 | public function hasAdminByClass($class) |
||
214 | |||
215 | /** |
||
216 | * Returns an admin class by its Admin code |
||
217 | * ie : sonata.news.admin.post|sonata.news.admin.comment => return the child class of post. |
||
218 | * |
||
219 | * @param string $adminCode |
||
220 | * |
||
221 | * @return \Sonata\AdminBundle\Admin\AdminInterface|false|null |
||
222 | */ |
||
223 | public function getAdminByAdminCode($adminCode) |
||
248 | |||
249 | /** |
||
250 | * Returns a new admin instance depends on the given code. |
||
251 | * |
||
252 | * @param string $id |
||
253 | * |
||
254 | * @return AdminInterface |
||
255 | * |
||
256 | * @throws \InvalidArgumentException |
||
257 | */ |
||
258 | public function getInstance($id) |
||
266 | |||
267 | /** |
||
268 | * @return ContainerInterface|null |
||
269 | */ |
||
270 | public function getContainer() |
||
274 | |||
275 | /** |
||
276 | * @param array $adminGroups |
||
277 | */ |
||
278 | public function setAdminGroups(array $adminGroups) |
||
282 | |||
283 | /** |
||
284 | * @return array |
||
285 | */ |
||
286 | public function getAdminGroups() |
||
290 | |||
291 | /** |
||
292 | * @param array $adminServiceIds |
||
293 | */ |
||
294 | public function setAdminServiceIds(array $adminServiceIds) |
||
298 | |||
299 | /** |
||
300 | * @return array |
||
301 | */ |
||
302 | public function getAdminServiceIds() |
||
306 | |||
307 | /** |
||
308 | * @param array $adminClasses |
||
309 | */ |
||
310 | public function setAdminClasses(array $adminClasses) |
||
314 | |||
315 | /** |
||
316 | * @return array |
||
317 | */ |
||
318 | public function getAdminClasses() |
||
322 | |||
323 | /** |
||
324 | * @param array $templates |
||
325 | */ |
||
326 | public function setTemplates(array $templates) |
||
330 | |||
331 | /** |
||
332 | * @return array |
||
333 | */ |
||
334 | public function getTemplates() |
||
338 | |||
339 | /** |
||
340 | * @param string $name |
||
341 | * |
||
342 | * @return null|string |
||
343 | */ |
||
344 | public function getTemplate($name) |
||
350 | |||
351 | /** |
||
352 | * @return string |
||
353 | */ |
||
354 | public function getTitleLogo() |
||
358 | |||
359 | /** |
||
360 | * @return string |
||
361 | */ |
||
362 | public function getTitle() |
||
366 | |||
367 | /** |
||
368 | * @param string $name |
||
369 | * @param mixed $default |
||
370 | * |
||
371 | * @return mixed |
||
372 | */ |
||
373 | public function getOption($name, $default = null) |
||
381 | |||
382 | public function getPropertyAccessor() |
||
390 | } |
||
391 |