Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 22 | class WidgetController extends Controller |
||
| 23 | { |
||
| 24 | use VictoireAlertifyControllerTrait; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Show a widget. |
||
| 28 | * |
||
| 29 | * @param Request $request |
||
| 30 | * @param Widget $widget |
||
| 31 | * @param int $viewReferenceId |
||
| 32 | * |
||
| 33 | * @Route("/victoire-dcms-public/widget/show/{id}/{viewReferenceId}", name="victoire_core_widget_show", options={"expose"=true}) |
||
| 34 | * @Template() |
||
| 35 | * @ParamConverter("id", class="VictoireWidgetBundle:Widget") |
||
| 36 | * |
||
| 37 | * @throws Exception |
||
| 38 | * |
||
| 39 | * @return Response |
||
| 40 | */ |
||
| 41 | public function showAction(Request $request, Widget $widget, $viewReferenceId) |
||
| 59 | |||
| 60 | /** |
||
| 61 | * API widgets function. |
||
| 62 | * |
||
| 63 | * @param string $widgetIds the widget ids to fetch in json |
||
| 64 | * @param int $viewReferenceId |
||
| 65 | * |
||
| 66 | * @Route("/victoire-dcms-public/api/widgets/{widgetIds}/{viewReferenceId}", name="victoire_core_widget_apiWidgets", options={"expose"=true}) |
||
| 67 | * |
||
| 68 | * @return JsonResponse |
||
| 69 | */ |
||
| 70 | public function apiWidgetsAction($widgetIds, $viewReferenceId) |
||
| 83 | |||
| 84 | /** |
||
| 85 | * New Widget. |
||
| 86 | * |
||
| 87 | * @param string $type The type of the widget we edit |
||
| 88 | * @param int $viewReference The view reference where attach the widget |
||
| 89 | * @param string $slot The slot where attach the widget |
||
| 90 | * |
||
| 91 | * @return JsonResponse |
||
| 92 | * |
||
| 93 | * @Route("/victoire-dcms/widget/new/{type}/{viewReference}/{slot}/{position}/{parentWidgetMap}", name="victoire_core_widget_new", defaults={"slot":null, "position":null, "parentWidgetMap":null}, options={"expose"=true}) |
||
| 94 | * @Template() |
||
| 95 | */ |
||
| 96 | public function newAction($type, $viewReference, $slot = null, $position = null, $parentWidgetMap = null) |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Create a widget. |
||
| 120 | * This action needs 2 routes to handle the presence or not of "businessEntityId" and 'parentWidgetMap' |
||
| 121 | * that are both integers but "businessEntityId" present only in !static mode |
||
| 122 | * |
||
| 123 | * @param string $type The type of the widget we edit |
||
| 124 | * @param int $viewReference The view reference where attach the widget |
||
| 125 | * @param string $slot The slot where attach the widget |
||
| 126 | * @param string $businessEntityId The BusinessEntity::id (can be null if the submitted form is in static mode) |
||
| 127 | * |
||
| 128 | * @return JsonResponse |
||
| 129 | * @Route("/victoire-dcms/widget/create/static/{type}/{viewReference}/{slot}/{position}/{parentWidgetMap}", name="victoire_core_widget_create_static", defaults={"mode":"static", "slot":null, "businessEntityId":null, "position":null, "parentWidgetMap":null, "_format": "json"}) |
||
| 130 | * @Route("/victoire-dcms/widget/create/{mode}/{type}/{viewReference}/{slot}/{businessEntityId}/{position}/{parentWidgetMap}", name="victoire_core_widget_create", defaults={"slot":null, "businessEntityId":null, "position":null, "parentWidgetMap":null, "_format": "json"}) |
||
| 131 | * @Template() |
||
| 132 | */ |
||
| 133 | public function createAction($mode, $type, $viewReference, $slot = null, $position = null, $parentWidgetMap = null, $businessEntityId = null) |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Edit a widget. |
||
| 174 | * |
||
| 175 | * @param Widget $widget The widget to edit |
||
| 176 | * @param int $viewReference The current view |
||
| 177 | * @param string $businessEntityId The BusinessEntity::id (can be null if the submitted form is in static mode) |
||
| 178 | * |
||
| 179 | * @return JsonResponse |
||
| 180 | * |
||
| 181 | * @Route("/victoire-dcms/widget/edit/{id}/{viewReference}/{mode}/{businessEntityId}", name="victoire_core_widget_edit", options={"expose"=true}) |
||
| 182 | * @Route("/victoire-dcms/widget/update/{id}/{viewReference}/{mode}/{businessEntityId}", name="victoire_core_widget_update", defaults={"businessEntityId": null}) |
||
| 183 | * @Template() |
||
| 184 | */ |
||
| 185 | public function editAction(Widget $widget, $viewReference, $mode = Widget::MODE_STATIC, $businessEntityId = null) |
||
| 217 | |||
| 218 | /** |
||
| 219 | * Stylize a widget. |
||
| 220 | * |
||
| 221 | * @param Widget $widget The widget to stylize |
||
| 222 | * @param int $viewReference The current view |
||
| 223 | * |
||
| 224 | * @return JsonResponse |
||
| 225 | * |
||
| 226 | * @Route("/victoire-dcms/widget/stylize/{id}/{viewReference}", name="victoire_core_widget_stylize", options={"expose"=true}) |
||
| 227 | * @Template() |
||
| 228 | */ |
||
| 229 | public function stylizeAction(Request $request, Widget $widget, $viewReference) |
||
| 290 | |||
| 291 | /** |
||
| 292 | * Delete a Widget. |
||
| 293 | * |
||
| 294 | * @param Widget $widget The widget to delete |
||
| 295 | * @param int $viewReference The current view |
||
| 296 | * |
||
| 297 | * @return JsonResponse response |
||
| 298 | * @Route("/victoire-dcms/widget/delete/{id}/{viewReference}", name="victoire_core_widget_delete", defaults={"_format": "json"}) |
||
| 299 | * @Template() |
||
| 300 | */ |
||
| 301 | public function deleteAction(Widget $widget, $viewReference) |
||
| 318 | |||
| 319 | /** |
||
| 320 | * Unlink a Widget by id |
||
| 321 | * -> used to unlink an invalid widget after a bad widget unplug. |
||
| 322 | * |
||
| 323 | * @param int $id The widgetId to unlink |
||
| 324 | * @param int $viewReference The current viewReference |
||
| 325 | * |
||
| 326 | * @return JsonResponse response |
||
| 327 | * @Route("/victoire-dcms/widget/unlink/{id}/{viewReference}", name="victoire_core_widget_unlink", defaults={"_format": "json"}, options={"expose"=true}) |
||
| 328 | * @Template() |
||
| 329 | */ |
||
| 330 | public function unlinkAction($id, $viewReference) |
||
| 358 | |||
| 359 | /** |
||
| 360 | * Update widget positions accross the view. If moved widget is a Reference, ask to detach the view from template. |
||
| 361 | * |
||
| 362 | * @param int $viewReference The current viewReference |
||
| 363 | * |
||
| 364 | * @return JsonResponse |
||
| 365 | * @Route("/victoire-dcms/widget/updatePosition/{viewReference}", name="victoire_core_widget_update_position", options={"expose"=true}) |
||
| 366 | */ |
||
| 367 | public function updatePositionAction(Request $request, $viewReference) |
||
| 394 | |||
| 395 | /** |
||
| 396 | * Update widget positions accross the view. If moved widget is a Reference, ask to detach the view from template. |
||
| 397 | * |
||
| 398 | * @param int $viewReference The current viewReference |
||
| 399 | * |
||
| 400 | * @return JsonResponse |
||
| 401 | * @Route("/victoire-dcms/widget/get-available-positions/{viewReference}", name="victoire_core_widget_get_available_positions", options={"expose"=true}) |
||
| 402 | */ |
||
| 403 | public function getAvailablePositionsAction(Request $request, $viewReference) |
||
| 412 | |||
| 413 | /** |
||
| 414 | * Get the json response by the exception and the current user. |
||
| 415 | * |
||
| 416 | * @param Exception $ex |
||
| 417 | * |
||
| 418 | * @return JsonResponse |
||
| 419 | */ |
||
| 420 | protected function getJsonReponseFromException(Exception $ex) |
||
| 452 | |||
| 453 | /** |
||
| 454 | * @param int $referenceId |
||
| 455 | */ |
||
| 456 | protected function getViewByReferenceId($referenceId) |
||
| 460 | } |
||
| 461 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.