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 |
||
| 20 | class WidgetController extends Controller |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * Show a widget. |
||
| 24 | * |
||
| 25 | * @param Request $request |
||
| 26 | * @param Widget $widget |
||
| 27 | * @param int $viewReferenceId |
||
| 28 | * |
||
| 29 | * @Route("/victoire-dcms-public/widget/show/{id}/{viewReferenceId}", name="victoire_core_widget_show", options={"expose"=true}) |
||
| 30 | * @Template() |
||
| 31 | * @ParamConverter("id", class="VictoireWidgetBundle:Widget") |
||
| 32 | * |
||
| 33 | * @throws Exception |
||
| 34 | * |
||
| 35 | * @return Response |
||
| 36 | */ |
||
| 37 | public function showAction(Request $request, Widget $widget, $viewReferenceId) |
||
| 55 | |||
| 56 | /** |
||
| 57 | * API widgets function. |
||
| 58 | * |
||
| 59 | * @param string $widgetIds the widget ids to fetch in json |
||
| 60 | * @param int $viewReferenceId |
||
| 61 | * |
||
| 62 | * @Route("/victoire-dcms-public/api/widgets/{widgetIds}/{viewReferenceId}", name="victoire_core_widget_apiWidgets", options={"expose"=true}) |
||
| 63 | * |
||
| 64 | * @return JsonResponse |
||
| 65 | */ |
||
| 66 | public function apiWidgetsAction($widgetIds, $viewReferenceId) |
||
| 79 | |||
| 80 | /** |
||
| 81 | * New Widget. |
||
| 82 | * |
||
| 83 | * @param string $type The type of the widget we edit |
||
| 84 | * @param int $viewReference The view reference where attach the widget |
||
| 85 | * @param string $slot The slot where attach the widget |
||
| 86 | * @param int $positionReference The positionReference in the widgetMap |
||
| 87 | * |
||
| 88 | * @return JsonResponse |
||
| 89 | * |
||
| 90 | * @Route("/victoire-dcms/widget/new/{type}/{viewReference}/{slot}/{position}/{widgetMapReference}", name="victoire_core_widget_new", defaults={"slot":null, "position":null, "widgetMapReference":null}, options={"expose"=true}) |
||
| 91 | * @Template() |
||
| 92 | */ |
||
| 93 | public function newAction($type, $viewReference, $slot = null, $position = null, $widgetMapReference = null) |
||
| 125 | |||
| 126 | /** |
||
| 127 | * Create a widget. |
||
| 128 | * |
||
| 129 | * @param string $type The type of the widget we edit |
||
| 130 | * @param int $viewReference The view reference where attach the widget |
||
| 131 | * @param string $slot The slot where attach the widget |
||
| 132 | * @param int $positionReference Position of the widget |
||
| 133 | * @param string $businessEntityId The BusinessEntity::id (can be null if the submitted form is in static mode) |
||
| 134 | * |
||
| 135 | * @return JsonResponse |
||
| 136 | * @Route("/victoire-dcms/widget/create/static/{type}/{viewReference}/{slot}/{position}/{widgetMapReference}", name="victoire_core_widget_create_static", defaults={"mode":"static", "slot":null, "businessEntityId":null, "position":null, "widgetMapReference":null, "_format": "json"}) |
||
| 137 | * @Route("/victoire-dcms/widget/create/{mode}/{type}/{viewReference}/{slot}/{businessEntityId}/{position}/{widgetMapReference}", name="victoire_core_widget_create", defaults={"slot":null, "businessEntityId":null, "position":null, "widgetMapReference":null, "_format": "json"}) |
||
| 138 | * @Template() |
||
| 139 | */ |
||
| 140 | public function createAction($mode, $type, $viewReference, $slot = null, $position = null, $widgetMapReference = null, $businessEntityId = null) |
||
| 177 | |||
| 178 | /** |
||
| 179 | * Edit a widget. |
||
| 180 | * |
||
| 181 | * @param Widget $widget The widget to edit |
||
| 182 | * @param int $viewReference The current view |
||
| 183 | * @param string $businessEntityId The BusinessEntity::id (can be null if the submitted form is in static mode) |
||
| 184 | * |
||
| 185 | * @return JsonResponse |
||
| 186 | * |
||
| 187 | * @Route("/victoire-dcms/widget/edit/{id}/{viewReference}/{mode}/{businessEntityId}", name="victoire_core_widget_edit", options={"expose"=true}) |
||
| 188 | * @Route("/victoire-dcms/widget/update/{id}/{viewReference}/{mode}/{businessEntityId}", name="victoire_core_widget_update", defaults={"businessEntityId": null}) |
||
| 189 | * @Template() |
||
| 190 | */ |
||
| 191 | public function editAction(Widget $widget, $viewReference, $mode = Widget::MODE_STATIC, $businessEntityId = null) |
||
| 221 | |||
| 222 | /** |
||
| 223 | * Stylize a widget. |
||
| 224 | * |
||
| 225 | * @param Widget $widget The widget to stylize |
||
| 226 | * @param int $viewReference The current view |
||
| 227 | * |
||
| 228 | * @return JsonResponse |
||
| 229 | * |
||
| 230 | * @Route("/victoire-dcms/widget/stylize/{id}/{viewReference}", name="victoire_core_widget_stylize", options={"expose"=true}) |
||
| 231 | * @Template() |
||
| 232 | */ |
||
| 233 | public function stylizeAction(Request $request, Widget $widget, $viewReference) |
||
| 293 | |||
| 294 | /** |
||
| 295 | * Delete a Widget. |
||
| 296 | * |
||
| 297 | * @param Widget $widget The widget to delete |
||
| 298 | * @param int $viewReference The current view |
||
| 299 | * |
||
| 300 | * @return JsonResponse response |
||
| 301 | * @Route("/victoire-dcms/widget/delete/{id}/{viewReference}", name="victoire_core_widget_delete", defaults={"_format": "json"}) |
||
| 302 | * @Template() |
||
| 303 | */ |
||
| 304 | public function deleteAction(Widget $widget, $viewReference) |
||
| 321 | |||
| 322 | /** |
||
| 323 | * Unlink a Widget by id |
||
| 324 | * -> used to unlink an invalid widget after a bad widget unplug. |
||
| 325 | * |
||
| 326 | * @param int $id The widgetId to unlink |
||
| 327 | * @param int $viewReference The current viewReference |
||
| 328 | * |
||
| 329 | * @return JsonResponse response |
||
| 330 | * @Route("/victoire-dcms/widget/unlink/{id}/{viewReference}", name="victoire_core_widget_unlink", defaults={"_format": "json"}, options={"expose"=true}) |
||
| 331 | * @Template() |
||
| 332 | */ |
||
| 333 | public function unlinkAction($id, $viewReference) |
||
| 361 | |||
| 362 | /** |
||
| 363 | * Update widget positions accross the view. If moved widget is a Reference, ask to detach the view from template. |
||
| 364 | * |
||
| 365 | * @param int $viewReference The current viewReference |
||
| 366 | * |
||
| 367 | * @return JsonResponse |
||
| 368 | * @Route("/victoire-dcms/widget/updatePosition/{viewReference}", name="victoire_core_widget_update_position", options={"expose"=true}) |
||
| 369 | */ |
||
| 370 | public function updatePositionAction(Request $request, $viewReference) |
||
| 397 | |||
| 398 | /** |
||
| 399 | * Update widget positions accross the view. If moved widget is a Reference, ask to detach the view from template. |
||
| 400 | * |
||
| 401 | * @param int $viewReference The current viewReference |
||
| 402 | * |
||
| 403 | * @return JsonResponse |
||
| 404 | * @Route("/victoire-dcms/widget/get-available-positions/{viewReference}", name="victoire_core_widget_get_available_positions", options={"expose"=true}) |
||
| 405 | */ |
||
| 406 | public function getAvailablePositions(Request $request, $viewReference) |
||
| 415 | |||
| 416 | /** |
||
| 417 | * Get the json response by the exception and the current user. |
||
| 418 | * |
||
| 419 | * @param Exception $ex |
||
| 420 | * |
||
| 421 | * @return JsonResponse |
||
| 422 | */ |
||
| 423 | protected function getJsonReponseFromException(Exception $ex) |
||
| 455 | |||
| 456 | /** |
||
| 457 | * @param int $referenceId |
||
| 458 | */ |
||
| 459 | protected function getViewByReferenceId($referenceId) |
||
| 463 | } |
||
| 464 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.