Complex classes like AbstractController 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 AbstractController, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
29 | abstract class AbstractController extends Controller |
||
30 | { |
||
31 | /** |
||
32 | * Lists all items entity. |
||
33 | * |
||
34 | * @param string $entityName Name of Entity |
||
35 | * @param string $prefixRoute prefix_route |
||
36 | * @param \Symfony\Component\HttpFoundation\Request $request Sort request |
||
37 | * @return array |
||
38 | */ |
||
39 | public function abstractIndexAction($entityName, $prefixRoute, Request $request = null) |
||
53 | |||
54 | /** |
||
55 | * Finds and displays an item entity. |
||
56 | * |
||
57 | * @param Object $entity Entity |
||
58 | * @param string $prefixRoute prefix_route |
||
59 | * @return array |
||
60 | */ |
||
61 | public function abstractShowAction($entity, $prefixRoute) |
||
70 | |||
71 | /** |
||
72 | * Displays a form to create a new item entity. |
||
73 | * |
||
74 | * @param string $entityName Name of Entity |
||
75 | * @param string $entityPath Path of Entity |
||
76 | * @param string $typePath Path of FormType |
||
77 | * @param string $prefixRoute Prefix of Route |
||
78 | * @return array |
||
79 | */ |
||
80 | public function abstractNewAction($entityName, $entityPath, $typePath, $prefixRoute) |
||
102 | |||
103 | /** |
||
104 | * Creates a new item entity. |
||
105 | * |
||
106 | * @param \Symfony\Component\HttpFoundation\Request $request Request in progress |
||
107 | * @param string $entityName Entity name <i>First letter Upper</i> |
||
108 | * @param string $entityPath Path of Entity |
||
109 | * @param string $typePath Path of FormType |
||
110 | * @param string $prefixRoute Prefix of route |
||
111 | * @return array |
||
112 | */ |
||
113 | public function abstractCreateAction(Request $request, $entityName, $entityPath, $typePath, $prefixRoute) |
||
140 | |||
141 | /** |
||
142 | * Displays a form to edit an existing item entity. |
||
143 | * |
||
144 | * @param Object $entity Entity |
||
145 | * @param string $prefixRoute Prefix of Route |
||
146 | * @param string $typePath Path of FormType |
||
147 | * @return array |
||
148 | */ |
||
149 | public function abstractEditAction($entity, $prefixRoute, $typePath) |
||
167 | |||
168 | /** |
||
169 | * Edits an existing item entity. |
||
170 | * |
||
171 | * @param Object $entity Entity |
||
172 | * @param \Symfony\Component\HttpFoundation\Request $request Request in progress |
||
173 | * @param string $prefixRoute Prefix of Route |
||
174 | * @param string $typePath Path of FormType |
||
175 | * @return array |
||
176 | */ |
||
177 | public function abstractUpdateAction($entity, Request $request, $prefixRoute, $typePath) |
||
204 | |||
205 | /** |
||
206 | * Deletes an item entity. |
||
207 | * |
||
208 | * @param Object $entity Entity |
||
209 | * @param \Symfony\Component\HttpFoundation\Request $request Request in progress |
||
210 | * @param string $prefixRoute Prefix of Route |
||
211 | * @return array |
||
212 | */ |
||
213 | public function abstractDeleteAction($entity, Request $request, $prefixRoute) |
||
222 | |||
223 | /** |
||
224 | * Deletes a item entity with Articles. |
||
225 | * |
||
226 | * @param Object $entity Entity |
||
227 | * @param \Symfony\Component\HttpFoundation\Request $request Request in progress |
||
228 | * @param string $entityName Name of Entity |
||
229 | * @param string $prefixRoute Prefix of Route |
||
230 | * @return array |
||
231 | */ |
||
232 | public function abstractDeleteWithArticlesAction($entity, Request $request, $entityName, $prefixRoute) |
||
250 | |||
251 | /** |
||
252 | * AddQueryBuilderSort for the SortAction in views. |
||
253 | * |
||
254 | * @param QueryBuilder $qbd |
||
255 | * @param string $name |
||
256 | */ |
||
257 | protected function addQueryBuilderSort(QueryBuilder $qbd, $name) |
||
275 | |||
276 | /** |
||
277 | * Create Delete form. |
||
278 | * |
||
279 | * @param int $id |
||
280 | * @param string $route |
||
281 | * |
||
282 | * @return \Symfony\Component\Form\Form |
||
283 | */ |
||
284 | protected function createDeleteForm($id, $route) |
||
292 | |||
293 | /** |
||
294 | * Test paramters to return. |
||
295 | * |
||
296 | * @param object $entity Entity to return |
||
297 | * @param string $prefixRoute Entity name to test |
||
298 | * @return array Parameters to return |
||
299 | */ |
||
300 | protected function testReturnParam($entity, $prefixRoute) |
||
311 | |||
312 | /** |
||
313 | * Get the existing roles |
||
314 | * |
||
315 | * @return array Array of roles |
||
316 | */ |
||
317 | private function getExistingRoles() |
||
328 | |||
329 | /** |
||
330 | * Add roles to form |
||
331 | * |
||
332 | * @param \Symfony\Component\Form\Form $form The form in which to insert the roles |
||
333 | * @param \AppBundle\Entity\Group $group The entity to deal |
||
334 | * @return \Symfony\Component\Form\Form The form |
||
335 | */ |
||
336 | public function addRolesAction($form, $group) |
||
350 | |||
351 | /** |
||
352 | * Get the entity. |
||
353 | * |
||
354 | * @param string $entityName Name of Entity |
||
355 | * @param \Doctrine\Common\Persistence\ObjectManager $etm ObjectManager instances |
||
356 | * @return array|\Doctrine\ORM\QueryBuilder|null Entity elements |
||
357 | */ |
||
358 | private function getEntity($entityName, ObjectManager $etm) |
||
392 | } |
||
393 |