Complex classes like AdminController 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 AdminController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 42 | class AdminController extends Controller |
||
| 43 | { |
||
| 44 | public static $DEPARTMENT_ENTITY_DATA = [ |
||
| 45 | 'entity' => 'department', |
||
| 46 | 'entityClassName' => 'AppBundle\Entity\Department', |
||
| 47 | 'entityFormType' => 'AppBundle\Form\Type\DepartmentType', |
||
| 48 | 'query' => 'SELECT d FROM AppBundle:Department d LEFT JOIN d.head h LEFT JOIN h.person p', |
||
| 49 | 'defaultSortFieldName' => 'd.name', |
||
| 50 | 'columns' => [ |
||
| 51 | ['size' => '5', 'sort_field' => 'd.name', 'name' => 'department.name'], |
||
| 52 | ['size' => '4', 'sort_field' => 'p.displayName', 'name' => 'department.head'], |
||
| 53 | ], |
||
| 54 | 'data_columns' => ['name', 'head'] |
||
| 55 | ]; |
||
| 56 | |||
| 57 | public static $COMPANY_ENTITY_DATA = [ |
||
| 58 | 'entity' => 'company', |
||
| 59 | 'entityClassName' => 'AppBundle\Entity\Company', |
||
| 60 | 'entityFormType' => 'AppBundle\Form\Type\CompanyType', |
||
| 61 | 'query' => 'SELECT c FROM AppBundle:Company c', |
||
| 62 | 'defaultSortFieldName' => 'c.name', |
||
| 63 | 'columns' => [ |
||
| 64 | ['size' => '2', 'sort_field' => 'c.code', 'name' => 'company.code'], |
||
| 65 | ['size' => '7', 'sort_field' => 'c.name', 'name' => 'company.name'], |
||
| 66 | ], |
||
| 67 | 'data_columns' => ['code', 'name'] |
||
| 68 | ]; |
||
| 69 | |||
| 70 | public static $WORKCENTER_ENTITY_DATA = [ |
||
| 71 | 'entity' => 'workcenter', |
||
| 72 | 'entityClassName' => 'AppBundle\Entity\Workcenter', |
||
| 73 | 'entityFormType' => 'AppBundle\Form\Type\WorkcenterType', |
||
| 74 | 'query' => 'SELECT w FROM AppBundle:Workcenter w JOIN w.company c', |
||
| 75 | 'defaultSortFieldName' => 'c.name', |
||
| 76 | 'columns' => [ |
||
| 77 | ['size' => '4', 'sort_field' => 'c.name', 'name' => 'form.company'], |
||
| 78 | ['size' => '5', 'sort_field' => 'w.name', 'name' => 'form.name'], |
||
| 79 | ], |
||
| 80 | 'data_columns' => ['company', 'name'] |
||
| 81 | ]; |
||
| 82 | |||
| 83 | public static $GROUP_ENTITY_DATA = [ |
||
| 84 | 'entity' => 'group', |
||
| 85 | 'entityClassName' => 'AppBundle\Entity\Group', |
||
| 86 | 'entityFormType' => 'AppBundle\Form\Type\GroupType', |
||
| 87 | 'query' => 'SELECT g FROM AppBundle:Group g JOIN g.training t', |
||
| 88 | 'defaultSortFieldName' => 'g.name', |
||
| 89 | 'columns' => [ |
||
| 90 | ['size' => '4', 'sort_field' => 'g.name', 'name' => 'form.name'], |
||
| 91 | ['size' => '5', 'sort_field' => 'g.training', 'name' => 'form.training'] |
||
| 92 | ], |
||
| 93 | 'data_columns' => ['name', 'training'] |
||
| 94 | ]; |
||
| 95 | |||
| 96 | public static $TRAINING_ENTITY_DATA = [ |
||
| 97 | 'entity' => 'training', |
||
| 98 | 'entityClassName' => 'AppBundle\Entity\Training', |
||
| 99 | 'entityFormType' => 'AppBundle\Form\Type\TrainingType', |
||
| 100 | 'query' => 'SELECT t FROM AppBundle:Training t JOIN t.department d', |
||
| 101 | 'defaultSortFieldName' => 't.name', |
||
| 102 | 'columns' => [ |
||
| 103 | ['size' => '4', 'sort_field' => 't.name', 'name' => 'form.name'], |
||
| 104 | ['size' => '3', 'sort_field' => 't.department', 'name' => 'form.department'], |
||
| 105 | ['size' => '2', 'sort_field' => 't.programHours', 'name' => 'form.program_hours'] |
||
| 106 | ], |
||
| 107 | 'data_columns' => ['name', 'department', 'programHours'] |
||
| 108 | ]; |
||
| 109 | |||
| 110 | public static $NON_SCHOOL_DAY_ENTITY_DATA = [ |
||
| 111 | 'entity' => 'non_school_day', |
||
| 112 | 'entityClassName' => 'AppBundle\Entity\NonSchoolDay', |
||
| 113 | 'entityFormType' => 'AppBundle\Form\Type\NonSchoolDayType', |
||
| 114 | 'query' => 'SELECT n FROM AppBundle:NonSchoolDay n', |
||
| 115 | 'defaultSortFieldName' => 'n.date', |
||
| 116 | 'columns' => [ |
||
| 117 | ['size' => '2', 'sort_field' => 'n.date', 'name' => 'form.date'], |
||
| 118 | ['size' => '7', 'sort_field' => 'n.name', 'name' => 'form.name'] |
||
| 119 | ], |
||
| 120 | 'data_columns' => ['date', 'name'] |
||
| 121 | ]; |
||
| 122 | |||
| 123 | public static $TEACHER_ENTITY_DATA = [ |
||
| 124 | 'entity' => 'teacher', |
||
| 125 | 'entityClassName' => 'AppBundle\Entity\Teacher', |
||
| 126 | 'entityFormType' => 'AppBundle\Form\Type\TeacherType', |
||
| 127 | 'query' => 'SELECT t FROM AppBundle:Teacher t JOIN t.person p', |
||
| 128 | 'defaultSortFieldName' => 'p.lastName', |
||
| 129 | 'columns' => [ |
||
| 130 | ['size' => '5', 'sort_field' => 'p.lastName', 'name' => 'form.last_name'], |
||
| 131 | ['size' => '4', 'sort_field' => 'p.firstName', 'name' => 'form.first_name'] |
||
| 132 | ], |
||
| 133 | 'data_columns' => ['lastName', 'firstName'] |
||
| 134 | ]; |
||
| 135 | |||
| 136 | public static $STUDENT_ENTITY_DATA = [ |
||
| 137 | 'entity' => 'student', |
||
| 138 | 'entityClassName' => 'AppBundle\Entity\Student', |
||
| 139 | 'entityFormType' => 'AppBundle\Form\Type\StudentType', |
||
| 140 | 'query' => 'SELECT s FROM AppBundle:Student s JOIN s.person p', |
||
| 141 | 'defaultSortFieldName' => 'p.lastName', |
||
| 142 | 'columns' => [ |
||
| 143 | ['size' => '4', 'sort_field' => 'p.lastName', 'name' => 'form.last_name'], |
||
| 144 | ['size' => '3', 'sort_field' => 'p.firstName', 'name' => 'form.first_name'], |
||
| 145 | ['size' => '2', 'sort_field' => 's.group', 'name' => 'form.group'] |
||
| 146 | ], |
||
| 147 | 'data_columns' => ['lastName', 'firstName', 'group'] |
||
| 148 | ]; |
||
| 149 | |||
| 150 | public static $AGREEMENT_ENTITY_DATA = [ |
||
| 151 | 'entity' => 'agreement', |
||
| 152 | 'entityClassName' => 'AppBundle\Entity\Agreement', |
||
| 153 | 'entityFormType' => 'AppBundle\Form\Type\AgreementType', |
||
| 154 | 'query' => 'SELECT a FROM AppBundle:Agreement a JOIN a.student s JOIN s.person p', |
||
| 155 | 'defaultSortFieldName' => 'p.lastName', |
||
| 156 | 'columns' => [ |
||
| 157 | ['size' => '4', 'sort_field' => 'p.displayName', 'name' => 'form.student'], |
||
| 158 | ['size' => '5', 'sort_field' => 'a.workcenter', 'name' => 'form.workcenter'] |
||
| 159 | ], |
||
| 160 | 'data_columns' => ['student', 'workcenter'] |
||
| 161 | ]; |
||
| 162 | |||
| 163 | public static $WORKTUTOR_ENTITY_DATA = [ |
||
| 164 | 'entity' => 'work_tutor', |
||
| 165 | 'entityClassName' => 'AppBundle\Entity\WorkTutor', |
||
| 166 | 'entityFormType' => 'AppBundle\Form\Type\WorkTutorType', |
||
| 167 | 'query' => 'SELECT w FROM AppBundle:WorkTutor w JOIN w.person p', |
||
| 168 | 'defaultSortFieldName' => 'p.lastName', |
||
| 169 | 'columns' => [ |
||
| 170 | ['size' => '4', 'sort_field' => 'p.lastName', 'name' => 'form.last_name'], |
||
| 171 | ['size' => '5', 'sort_field' => 'w.company', 'name' => 'form.company'] |
||
| 172 | ], |
||
| 173 | 'data_columns' => ['person', 'company',] |
||
| 174 | ]; |
||
| 175 | |||
| 176 | /** |
||
| 177 | * @Route("/", name="admin_menu", methods={"GET"}) |
||
| 178 | * @Security("is_granted('ROLE_ADMIN')") |
||
| 179 | */ |
||
| 180 | public function indexAction() |
||
| 189 | |||
| 190 | public function genericIndexAction($entityData, Request $request) |
||
| 218 | |||
| 219 | public function genericFormAction($entityData, $element, Request $request) |
||
| 266 | |||
| 267 | public function genericDeleteAction($entityData, $element, Request $request) |
||
| 298 | |||
| 299 | /** |
||
| 300 | * @Route("/departamentos", name="admin_department", methods={"GET"}) |
||
| 301 | */ |
||
| 302 | public function departmentsIndexAction(Request $request) |
||
| 306 | |||
| 307 | /** |
||
| 308 | * @Route("/departamentos/nuevo", name="admin_department_new", methods={"GET", "POST"}) |
||
| 309 | * @Route("/departamentos/{id}", name="admin_department_form", methods={"GET", "POST"}, requirements={"id": "\d+"}) |
||
| 310 | */ |
||
| 311 | public function departmentsFormAction(Department $element = null, Request $request) |
||
| 315 | |||
| 316 | /** |
||
| 317 | * @Route("/departamentos/eliminar/{id}", name="admin_department_delete", methods={"GET", "POST"}, requirements={"id": "\d+"} ) |
||
| 318 | */ |
||
| 319 | public function deleteElementAction(Department $element, Request $request) |
||
| 323 | |||
| 324 | /** |
||
| 325 | * @Route("/empresas", name="admin_company", methods={"GET"}) |
||
| 326 | */ |
||
| 327 | public function companiesIndexAction(Request $request) |
||
| 331 | |||
| 332 | /** |
||
| 333 | * @Route("/empresas/nueva", name="admin_company_new", methods={"GET", "POST"}) |
||
| 334 | * @Route("/empresas/{id}", name="admin_company_form", methods={"GET", "POST"}, requirements={"id": "\d+"}) |
||
| 335 | */ |
||
| 336 | public function companyFormAction(Company $element = null, Request $request) |
||
| 340 | |||
| 341 | /** |
||
| 342 | * @Route("/empresas/eliminar/{id}", name="admin_company_delete", methods={"GET", "POST"}, requirements={"id": "\d+"} ) |
||
| 343 | */ |
||
| 344 | public function companyDeleteAction(Company $element, Request $request) |
||
| 348 | |||
| 349 | /** |
||
| 350 | * @Route("/grupos", name="admin_group", methods={"GET"}) |
||
| 351 | */ |
||
| 352 | public function groupIndexAction(Request $request) |
||
| 356 | |||
| 357 | /** |
||
| 358 | * @Route("/grupos/nuevo", name="admin_group_new", methods={"GET", "POST"}) |
||
| 359 | * @Route("/grupos/{id}", name="admin_group_form", methods={"GET", "POST"}, requirements={"id": "\d+"}) |
||
| 360 | */ |
||
| 361 | public function groupFormAction(Group $element = null, Request $request) |
||
| 365 | |||
| 366 | /** |
||
| 367 | * @Route("/grupos/eliminar/{id}", name="admin_group_delete", methods={"GET", "POST"}, requirements={"id": "\d+"} ) |
||
| 368 | */ |
||
| 369 | public function groupDeleteAction(Group $element, Request $request) |
||
| 373 | |||
| 374 | /** |
||
| 375 | * @Route("/ensenanzas", name="admin_training", methods={"GET"}) |
||
| 376 | */ |
||
| 377 | public function trainingIndexAction(Request $request) |
||
| 381 | |||
| 382 | /** |
||
| 383 | * @Route("/ensenanzas/nueva", name="admin_training_new", methods={"GET", "POST"}) |
||
| 384 | * @Route("/ensenanzas/{id}", name="admin_training_form", methods={"GET", "POST"}, requirements={"id": "\d+"}) |
||
| 385 | */ |
||
| 386 | public function trainingFormAction(Training $element = null, Request $request) |
||
| 390 | |||
| 391 | /** |
||
| 392 | * @Route("/ensenanzas/eliminar/{id}", name="admin_training_delete", methods={"GET", "POST"}, requirements={"id": "\d+"} ) |
||
| 393 | */ |
||
| 394 | public function trainingDeleteAction(Training $element, Request $request) |
||
| 398 | |||
| 399 | /** |
||
| 400 | * @Route("/diasnolectivos", name="admin_non_school_day", methods={"GET"}) |
||
| 401 | */ |
||
| 402 | public function nonSchoolDayIndexAction(Request $request) |
||
| 406 | |||
| 407 | /** |
||
| 408 | * @Route("/diasnolectivos/nuevo", name="admin_non_school_day_new", methods={"GET", "POST"}) |
||
| 409 | * @Route("/diasnolectivos/{id}", name="admin_non_school_day_form", methods={"GET", "POST"}) |
||
| 410 | */ |
||
| 411 | public function nonSchoolDayFormAction(NonSchoolDay $element = null, Request $request) |
||
| 415 | |||
| 416 | /** |
||
| 417 | * @Route("/diasnolectivos/eliminar/{id}", name="admin_non_school_day_delete", methods={"GET", "POST"}) |
||
| 418 | */ |
||
| 419 | public function workcenterDeleteAction(Workcenter $element, Request $request) |
||
| 423 | |||
| 424 | /** |
||
| 425 | * @Route("/centros", name="admin_workcenter", methods={"GET"}) |
||
| 426 | */ |
||
| 427 | public function workcenterIndexAction(Request $request) |
||
| 431 | |||
| 432 | /** |
||
| 433 | * @Route("/centros/nuevo", name="admin_workcenter_new", methods={"GET", "POST"}) |
||
| 434 | * @Route("/centros/{id}", name="admin_workcenter_form", methods={"GET", "POST"}) |
||
| 435 | */ |
||
| 436 | public function workcenterFormAction(Workcenter $element = null, Request $request) |
||
| 440 | |||
| 441 | /** |
||
| 442 | * @Route("/centros/eliminar/{id}", name="admin_workcenter_delete", methods={"GET", "POST"}) |
||
| 443 | */ |
||
| 444 | public function nonSchoolDayDeleteAction(Workcenter $element, Request $request) |
||
| 448 | |||
| 449 | /** |
||
| 450 | * @Route("/profesorado", name="admin_teacher", methods={"GET"}) |
||
| 451 | */ |
||
| 452 | public function teacherIndexAction(Request $request) |
||
| 456 | |||
| 457 | /** |
||
| 458 | * @Route("/profesorado/nuevo", name="admin_teacher_new", methods={"GET", "POST"}) |
||
| 459 | * @Route("/profesorado/{id}", name="admin_teacher_form", methods={"GET", "POST"}) |
||
| 460 | */ |
||
| 461 | public function teacherFormAction(Teacher $element = null, Request $request) |
||
| 465 | |||
| 466 | /** |
||
| 467 | * @Route("/profesorado/eliminar/{id}", name="admin_teacher_delete", methods={"GET", "POST"}) |
||
| 468 | */ |
||
| 469 | public function teacherDeleteAction(Teacher $element, Request $request) |
||
| 473 | |||
| 474 | /** |
||
| 475 | * @Route("/alumnado", name="admin_student", methods={"GET"}) |
||
| 476 | */ |
||
| 477 | public function studentIndexAction(Request $request) |
||
| 481 | |||
| 482 | /** |
||
| 483 | * @Route("/alumnado/nuevo", name="admin_student_new", methods={"GET", "POST"}) |
||
| 484 | * @Route("/alumnado/{id}", name="admin_student_form", methods={"GET", "POST"}) |
||
| 485 | */ |
||
| 486 | public function studentFormAction(Student $element = null, Request $request) |
||
| 490 | |||
| 491 | /** |
||
| 492 | * @Route("/alumnado/eliminar/{id}", name="admin_student_delete", methods={"GET", "POST"}) |
||
| 493 | */ |
||
| 494 | public function studentDeleteAction(Student $element, Request $request) |
||
| 498 | |||
| 499 | /** |
||
| 500 | * @Route("/acuerdos", name="admin_agreement", methods={"GET"}) |
||
| 501 | */ |
||
| 502 | public function agreementIndexAction(Request $request) |
||
| 506 | |||
| 507 | /** |
||
| 508 | * @Route("/acuerdos/nuevo", name="admin_agreement_new", methods={"GET", "POST"}) |
||
| 509 | * @Route("/acuerdos/{id}", name="admin_agreement_form", methods={"GET", "POST"}) |
||
| 510 | */ |
||
| 511 | public function agreementFormAction(Agreement $element = null, Request $request) |
||
| 515 | |||
| 516 | /** |
||
| 517 | * @Route("/acuerdos/eliminar/{id}", name="admin_agreement_delete", methods={"GET", "POST"}) |
||
| 518 | */ |
||
| 519 | public function agreementDeleteAction(Agreement $element, Request $request) |
||
| 523 | |||
| 524 | /** |
||
| 525 | * @Route("/tutorialaboral", name="admin_work_tutor", methods={"GET"}) |
||
| 526 | */ |
||
| 527 | public function workTutorIndexAction(Request $request) |
||
| 531 | |||
| 532 | /** |
||
| 533 | * @Route("/tutorialaboral/nuevo", name="admin_work_tutor_new", methods={"GET", "POST"}) |
||
| 534 | * @Route("/tutorialaboral/{id}", name="admin_work_tutor_form", methods={"GET", "POST"}) |
||
| 535 | */ |
||
| 536 | public function workTutorFormAction(Agreement $element = null, Request $request) |
||
| 540 | |||
| 541 | /** |
||
| 542 | * @Route("/tutorialaboral/eliminar/{id}", name="admin_work_tutor_delete", methods={"GET", "POST"}) |
||
| 543 | */ |
||
| 544 | public function workTutorDeleteAction(Agreement $element, Request $request) |
||
| 548 | } |
||
| 549 |