Complex classes like AbstractRouteController 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 AbstractRouteController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 32 | abstract class AbstractRouteController extends AbstractController |
||
| 33 | { |
||
| 34 | /** |
||
| 35 | * This is the default action handling the main admin area called without defining arguments. |
||
| 36 | * @Cache(expires="+7 days", public=true) |
||
| 37 | * |
||
| 38 | * @param Request $request Current request instance |
||
| 39 | * |
||
| 40 | * @return Response Output |
||
| 41 | * |
||
| 42 | * @throws AccessDeniedException Thrown if the user doesn't have required permissions |
||
| 43 | */ |
||
| 44 | public function adminIndexAction(Request $request) |
||
| 48 | |||
| 49 | /** |
||
| 50 | * This is the default action handling the main area called without defining arguments. |
||
| 51 | * @Cache(expires="+7 days", public=true) |
||
| 52 | * |
||
| 53 | * @param Request $request Current request instance |
||
| 54 | * |
||
| 55 | * @return Response Output |
||
| 56 | * |
||
| 57 | * @throws AccessDeniedException Thrown if the user doesn't have required permissions |
||
| 58 | */ |
||
| 59 | public function indexAction(Request $request) |
||
| 63 | |||
| 64 | /** |
||
| 65 | * This method includes the common implementation code for adminIndex() and index(). |
||
| 66 | */ |
||
| 67 | protected function indexInternal(Request $request, $isAdmin = false) |
||
| 86 | /** |
||
| 87 | * This action provides an item list overview in the admin area. |
||
| 88 | * @Cache(expires="+2 hours", public=false) |
||
| 89 | * |
||
| 90 | * @param Request $request Current request instance |
||
| 91 | * @param string $sort Sorting field |
||
| 92 | * @param string $sortdir Sorting direction |
||
| 93 | * @param int $pos Current pager position |
||
| 94 | * @param int $num Amount of entries to display |
||
| 95 | * |
||
| 96 | * @return Response Output |
||
| 97 | * |
||
| 98 | * @throws AccessDeniedException Thrown if the user doesn't have required permissions |
||
| 99 | */ |
||
| 100 | public function adminViewAction(Request $request, $sort, $sortdir, $pos, $num) |
||
| 104 | |||
| 105 | /** |
||
| 106 | * This action provides an item list overview. |
||
| 107 | * @Cache(expires="+2 hours", public=false) |
||
| 108 | * |
||
| 109 | * @param Request $request Current request instance |
||
| 110 | * @param string $sort Sorting field |
||
| 111 | * @param string $sortdir Sorting direction |
||
| 112 | * @param int $pos Current pager position |
||
| 113 | * @param int $num Amount of entries to display |
||
| 114 | * |
||
| 115 | * @return Response Output |
||
| 116 | * |
||
| 117 | * @throws AccessDeniedException Thrown if the user doesn't have required permissions |
||
| 118 | */ |
||
| 119 | public function viewAction(Request $request, $sort, $sortdir, $pos, $num) |
||
| 123 | |||
| 124 | /** |
||
| 125 | * This method includes the common implementation code for adminView() and view(). |
||
| 126 | */ |
||
| 127 | protected function viewInternal(Request $request, $sort, $sortdir, $pos, $num, $isAdmin = false) |
||
| 179 | /** |
||
| 180 | * This action provides a item detail view in the admin area. |
||
| 181 | * @ParamConverter("route", class="ZikulaRoutesModule:RouteEntity", options = {"id" = "id", "repository_method" = "selectById"}) |
||
| 182 | * @Cache(lastModified="route.getUpdatedDate()", ETag="'Route' ~ route.getid() ~ route.getUpdatedDate().format('U')") |
||
| 183 | * |
||
| 184 | * @param Request $request Current request instance |
||
| 185 | * @param RouteEntity $route Treated route instance |
||
| 186 | * |
||
| 187 | * @return Response Output |
||
| 188 | * |
||
| 189 | * @throws AccessDeniedException Thrown if the user doesn't have required permissions |
||
| 190 | * @throws NotFoundHttpException Thrown by param converter if route to be displayed isn't found |
||
| 191 | */ |
||
| 192 | public function adminDisplayAction(Request $request, RouteEntity $route) |
||
| 196 | |||
| 197 | /** |
||
| 198 | * This action provides a item detail view. |
||
| 199 | * @ParamConverter("route", class="ZikulaRoutesModule:RouteEntity", options = {"id" = "id", "repository_method" = "selectById"}) |
||
| 200 | * @Cache(lastModified="route.getUpdatedDate()", ETag="'Route' ~ route.getid() ~ route.getUpdatedDate().format('U')") |
||
| 201 | * |
||
| 202 | * @param Request $request Current request instance |
||
| 203 | * @param RouteEntity $route Treated route instance |
||
| 204 | * |
||
| 205 | * @return Response Output |
||
| 206 | * |
||
| 207 | * @throws AccessDeniedException Thrown if the user doesn't have required permissions |
||
| 208 | * @throws NotFoundHttpException Thrown by param converter if route to be displayed isn't found |
||
| 209 | */ |
||
| 210 | public function displayAction(Request $request, RouteEntity $route) |
||
| 214 | |||
| 215 | /** |
||
| 216 | * This method includes the common implementation code for adminDisplay() and display(). |
||
| 217 | */ |
||
| 218 | protected function displayInternal(Request $request, RouteEntity $route, $isAdmin = false) |
||
| 253 | /** |
||
| 254 | * This action provides a handling of edit requests in the admin area. |
||
| 255 | * @Cache(lastModified="route.getUpdatedDate()", ETag="'Route' ~ route.getid() ~ route.getUpdatedDate().format('U')") |
||
| 256 | * |
||
| 257 | * @param Request $request Current request instance |
||
| 258 | * |
||
| 259 | * @return Response Output |
||
| 260 | * |
||
| 261 | * @throws AccessDeniedException Thrown if the user doesn't have required permissions |
||
| 262 | * @throws NotFoundHttpException Thrown by form handler if route to be edited isn't found |
||
| 263 | * @throws RuntimeException Thrown if another critical error occurs (e.g. workflow actions not available) |
||
| 264 | */ |
||
| 265 | public function adminEditAction(Request $request) |
||
| 269 | |||
| 270 | /** |
||
| 271 | * This action provides a handling of edit requests. |
||
| 272 | * @Cache(lastModified="route.getUpdatedDate()", ETag="'Route' ~ route.getid() ~ route.getUpdatedDate().format('U')") |
||
| 273 | * |
||
| 274 | * @param Request $request Current request instance |
||
| 275 | * |
||
| 276 | * @return Response Output |
||
| 277 | * |
||
| 278 | * @throws AccessDeniedException Thrown if the user doesn't have required permissions |
||
| 279 | * @throws NotFoundHttpException Thrown by form handler if route to be edited isn't found |
||
| 280 | * @throws RuntimeException Thrown if another critical error occurs (e.g. workflow actions not available) |
||
| 281 | */ |
||
| 282 | public function editAction(Request $request) |
||
| 286 | |||
| 287 | /** |
||
| 288 | * This method includes the common implementation code for adminEdit() and edit(). |
||
| 289 | */ |
||
| 290 | protected function editInternal(Request $request, $isAdmin = false) |
||
| 319 | /** |
||
| 320 | * This action provides a handling of simple delete requests in the admin area. |
||
| 321 | * @ParamConverter("route", class="ZikulaRoutesModule:RouteEntity", options = {"id" = "id", "repository_method" = "selectById"}) |
||
| 322 | * @Cache(lastModified="route.getUpdatedDate()", ETag="'Route' ~ route.getid() ~ route.getUpdatedDate().format('U')") |
||
| 323 | * |
||
| 324 | * @param Request $request Current request instance |
||
| 325 | * @param RouteEntity $route Treated route instance |
||
| 326 | * |
||
| 327 | * @return Response Output |
||
| 328 | * |
||
| 329 | * @throws AccessDeniedException Thrown if the user doesn't have required permissions |
||
| 330 | * @throws NotFoundHttpException Thrown by param converter if route to be deleted isn't found |
||
| 331 | * @throws RuntimeException Thrown if another critical error occurs (e.g. workflow actions not available) |
||
| 332 | */ |
||
| 333 | public function adminDeleteAction(Request $request, RouteEntity $route) |
||
| 337 | |||
| 338 | /** |
||
| 339 | * This action provides a handling of simple delete requests. |
||
| 340 | * @ParamConverter("route", class="ZikulaRoutesModule:RouteEntity", options = {"id" = "id", "repository_method" = "selectById"}) |
||
| 341 | * @Cache(lastModified="route.getUpdatedDate()", ETag="'Route' ~ route.getid() ~ route.getUpdatedDate().format('U')") |
||
| 342 | * |
||
| 343 | * @param Request $request Current request instance |
||
| 344 | * @param RouteEntity $route Treated route instance |
||
| 345 | * |
||
| 346 | * @return Response Output |
||
| 347 | * |
||
| 348 | * @throws AccessDeniedException Thrown if the user doesn't have required permissions |
||
| 349 | * @throws NotFoundHttpException Thrown by param converter if route to be deleted isn't found |
||
| 350 | * @throws RuntimeException Thrown if another critical error occurs (e.g. workflow actions not available) |
||
| 351 | */ |
||
| 352 | public function deleteAction(Request $request, RouteEntity $route) |
||
| 356 | |||
| 357 | /** |
||
| 358 | * This method includes the common implementation code for adminDelete() and delete(). |
||
| 359 | */ |
||
| 360 | protected function deleteInternal(Request $request, RouteEntity $route, $isAdmin = false) |
||
| 433 | |||
| 434 | /** |
||
| 435 | * Process status changes for multiple items. |
||
| 436 | * |
||
| 437 | * This function processes the items selected in the admin view page. |
||
| 438 | * Multiple items may have their state changed or be deleted. |
||
| 439 | * |
||
| 440 | * @param Request $request Current request instance |
||
| 441 | * |
||
| 442 | * @return RedirectResponse |
||
| 443 | * |
||
| 444 | * @throws RuntimeException Thrown if executing the workflow action fails |
||
| 445 | */ |
||
| 446 | public function adminHandleSelectedEntriesAction(Request $request) |
||
| 450 | |||
| 451 | /** |
||
| 452 | * Process status changes for multiple items. |
||
| 453 | * |
||
| 454 | * This function processes the items selected in the admin view page. |
||
| 455 | * Multiple items may have their state changed or be deleted. |
||
| 456 | * |
||
| 457 | * @param Request $request Current request instance |
||
| 458 | * |
||
| 459 | * @return RedirectResponse |
||
| 460 | * |
||
| 461 | * @throws RuntimeException Thrown if executing the workflow action fails |
||
| 462 | */ |
||
| 463 | public function handleSelectedEntriesAction(Request $request) |
||
| 467 | |||
| 468 | /** |
||
| 469 | * This method includes the common implementation code for adminHandleSelectedEntriesAction() and handleSelectedEntriesAction(). |
||
| 470 | * |
||
| 471 | * @param Request $request Current request instance |
||
| 472 | * @param Boolean $isAdmin Whether the admin area is used or not |
||
| 473 | */ |
||
| 474 | protected function handleSelectedEntriesActionInternal(Request $request, $isAdmin = false) |
||
| 529 | } |
||
| 530 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.