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 |
||
| 28 | class RouteController extends AbstractRouteController |
||
| 29 | { |
||
| 30 | /** |
||
| 31 | * {@inheritdoc} |
||
| 32 | * |
||
| 33 | * @Route("/admin/routes", |
||
| 34 | * methods = {"GET"} |
||
| 35 | * ) |
||
| 36 | * @Theme("admin") |
||
| 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 | * {@inheritdoc} |
||
| 51 | * |
||
| 52 | * @Route("/routes", |
||
| 53 | * methods = {"GET"} |
||
| 54 | * ) |
||
| 55 | * |
||
| 56 | * @param Request $request Current request instance |
||
| 57 | * |
||
| 58 | * @return Response Output |
||
| 59 | * |
||
| 60 | * @throws AccessDeniedException Thrown if the user doesn't have required permissions |
||
| 61 | */ |
||
| 62 | public function indexAction(Request $request) |
||
| 66 | /** |
||
| 67 | * {@inheritdoc} |
||
| 68 | * |
||
| 69 | * @Route("/admin/routes/view/{sort}/{sortdir}/{pos}/{num}.{_format}", |
||
| 70 | * requirements = {"sortdir" = "asc|desc|ASC|DESC", "pos" = "\d+", "num" = "\d+", "_format" = "html|kml"}, |
||
| 71 | * defaults = {"sort" = "", "sortdir" = "asc", "pos" = 1, "num" = 10, "_format" = "html"}, |
||
| 72 | * methods = {"GET"} |
||
| 73 | * ) |
||
| 74 | * @Theme("admin") |
||
| 75 | * |
||
| 76 | * @param Request $request Current request instance |
||
| 77 | * @param string $sort Sorting field |
||
| 78 | * @param string $sortdir Sorting direction |
||
| 79 | * @param int $pos Current pager position |
||
| 80 | * @param int $num Amount of entries to display |
||
| 81 | * |
||
| 82 | * @return Response Output |
||
| 83 | * |
||
| 84 | * @throws AccessDeniedException Thrown if the user doesn't have required permissions |
||
| 85 | */ |
||
| 86 | public function adminViewAction(Request $request, $sort, $sortdir, $pos, $num) |
||
| 90 | |||
| 91 | /** |
||
| 92 | * {@inheritdoc} |
||
| 93 | * |
||
| 94 | * @Route("/routes/view/{sort}/{sortdir}/{pos}/{num}.{_format}", |
||
| 95 | * requirements = {"sortdir" = "asc|desc|ASC|DESC", "pos" = "\d+", "num" = "\d+", "_format" = "html|kml"}, |
||
| 96 | * defaults = {"sort" = "", "sortdir" = "asc", "pos" = 1, "num" = 10, "_format" = "html"}, |
||
| 97 | * methods = {"GET"} |
||
| 98 | * ) |
||
| 99 | * |
||
| 100 | * @param Request $request Current request instance |
||
| 101 | * @param string $sort Sorting field |
||
| 102 | * @param string $sortdir Sorting direction |
||
| 103 | * @param int $pos Current pager position |
||
| 104 | * @param int $num Amount of entries to display |
||
| 105 | * |
||
| 106 | * @return Response Output |
||
| 107 | * |
||
| 108 | * @throws AccessDeniedException Thrown if the user doesn't have required permissions |
||
| 109 | */ |
||
| 110 | public function viewAction(Request $request, $sort, $sortdir, $pos, $num) |
||
| 114 | /** |
||
| 115 | * {@inheritdoc} |
||
| 116 | * |
||
| 117 | * @Route("/admin/route/{id}.{_format}", |
||
| 118 | * requirements = {"id" = "\d+", "_format" = "html|kml|ics"}, |
||
| 119 | * defaults = {"_format" = "html"}, |
||
| 120 | * methods = {"GET"} |
||
| 121 | * ) |
||
| 122 | * @Theme("admin") |
||
| 123 | * |
||
| 124 | * @param Request $request Current request instance |
||
| 125 | * @param RouteEntity $route Treated route instance |
||
| 126 | * |
||
| 127 | * @return Response Output |
||
| 128 | * |
||
| 129 | * @throws AccessDeniedException Thrown if the user doesn't have required permissions |
||
| 130 | * @throws NotFoundHttpException Thrown by param converter if item to be displayed isn't found |
||
| 131 | */ |
||
| 132 | public function adminDisplayAction(Request $request, RouteEntity $route) |
||
| 136 | |||
| 137 | /** |
||
| 138 | * {@inheritdoc} |
||
| 139 | * |
||
| 140 | * @Route("/route/{id}.{_format}", |
||
| 141 | * requirements = {"id" = "\d+", "_format" = "html|kml|ics"}, |
||
| 142 | * defaults = {"_format" = "html"}, |
||
| 143 | * methods = {"GET"} |
||
| 144 | * ) |
||
| 145 | * |
||
| 146 | * @param Request $request Current request instance |
||
| 147 | * @param RouteEntity $route Treated route instance |
||
| 148 | * |
||
| 149 | * @return Response Output |
||
| 150 | * |
||
| 151 | * @throws AccessDeniedException Thrown if the user doesn't have required permissions |
||
| 152 | * @throws NotFoundHttpException Thrown by param converter if item to be displayed isn't found |
||
| 153 | */ |
||
| 154 | public function displayAction(Request $request, RouteEntity $route) |
||
| 158 | /** |
||
| 159 | * {@inheritdoc} |
||
| 160 | * |
||
| 161 | * @Route("/admin/route/edit/{id}.{_format}", |
||
| 162 | * requirements = {"id" = "\d+", "_format" = "html"}, |
||
| 163 | * defaults = {"id" = "0", "_format" = "html"}, |
||
| 164 | * methods = {"GET", "POST"} |
||
| 165 | * ) |
||
| 166 | * @Theme("admin") |
||
| 167 | * |
||
| 168 | * @param Request $request Current request instance |
||
| 169 | * |
||
| 170 | * @return Response Output |
||
| 171 | * |
||
| 172 | * @throws AccessDeniedException Thrown if the user doesn't have required permissions |
||
| 173 | * @throws NotFoundHttpException Thrown by form handler if item to be edited isn't found |
||
| 174 | * @throws RuntimeException Thrown if another critical error occurs (e.g. workflow actions not available) |
||
| 175 | */ |
||
| 176 | public function adminEditAction(Request $request) |
||
| 180 | |||
| 181 | /** |
||
| 182 | * {@inheritdoc} |
||
| 183 | * |
||
| 184 | * @Route("/route/edit/{id}.{_format}", |
||
| 185 | * requirements = {"id" = "\d+", "_format" = "html"}, |
||
| 186 | * defaults = {"id" = "0", "_format" = "html"}, |
||
| 187 | * methods = {"GET", "POST"} |
||
| 188 | * ) |
||
| 189 | * |
||
| 190 | * @param Request $request Current request instance |
||
| 191 | * |
||
| 192 | * @return Response Output |
||
| 193 | * |
||
| 194 | * @throws AccessDeniedException Thrown if the user doesn't have required permissions |
||
| 195 | * @throws NotFoundHttpException Thrown by form handler if item to be edited isn't found |
||
| 196 | * @throws RuntimeException Thrown if another critical error occurs (e.g. workflow actions not available) |
||
| 197 | */ |
||
| 198 | public function editAction(Request $request) |
||
| 202 | /** |
||
| 203 | * {@inheritdoc} |
||
| 204 | * |
||
| 205 | * @Route("/admin/route/delete/{id}.{_format}", |
||
| 206 | * requirements = {"id" = "\d+", "_format" = "html"}, |
||
| 207 | * defaults = {"_format" = "html"}, |
||
| 208 | * methods = {"GET", "POST"} |
||
| 209 | * ) |
||
| 210 | * @Theme("admin") |
||
| 211 | * |
||
| 212 | * @param Request $request Current request instance |
||
| 213 | * @param RouteEntity $route Treated route instance |
||
| 214 | * |
||
| 215 | * @return Response Output |
||
| 216 | * |
||
| 217 | * @throws AccessDeniedException Thrown if the user doesn't have required permissions |
||
| 218 | * @throws NotFoundHttpException Thrown by param converter if item to be deleted isn't found |
||
| 219 | * @throws RuntimeException Thrown if another critical error occurs (e.g. workflow actions not available) |
||
| 220 | */ |
||
| 221 | public function adminDeleteAction(Request $request, RouteEntity $route) |
||
| 225 | |||
| 226 | /** |
||
| 227 | * {@inheritdoc} |
||
| 228 | * |
||
| 229 | * @Route("/route/delete/{id}.{_format}", |
||
| 230 | * requirements = {"id" = "\d+", "_format" = "html"}, |
||
| 231 | * defaults = {"_format" = "html"}, |
||
| 232 | * methods = {"GET", "POST"} |
||
| 233 | * ) |
||
| 234 | * |
||
| 235 | * @param Request $request Current request instance |
||
| 236 | * @param RouteEntity $route Treated route instance |
||
| 237 | * |
||
| 238 | * @return Response Output |
||
| 239 | * |
||
| 240 | * @throws AccessDeniedException Thrown if the user doesn't have required permissions |
||
| 241 | * @throws NotFoundHttpException Thrown by param converter if item to be deleted isn't found |
||
| 242 | * @throws RuntimeException Thrown if another critical error occurs (e.g. workflow actions not available) |
||
| 243 | */ |
||
| 244 | public function deleteAction(Request $request, RouteEntity $route) |
||
| 248 | |||
| 249 | /** |
||
| 250 | * {@inheritdoc} |
||
| 251 | * |
||
| 252 | * @Route("/admin/routes/reload", |
||
| 253 | * methods = {"GET", "POST"} |
||
| 254 | * ) |
||
| 255 | * @Theme("admin") |
||
| 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 | */ |
||
| 263 | public function adminReloadAction(Request $request) |
||
| 289 | |||
| 290 | /** |
||
| 291 | * {@inheritdoc} |
||
| 292 | * |
||
| 293 | * @Route("/routes/reload", |
||
| 294 | * methods = {"GET", "POST"} |
||
| 295 | * ) |
||
| 296 | * |
||
| 297 | * @param Request $request Current request instance |
||
| 298 | * |
||
| 299 | * @return Response Output |
||
| 300 | * |
||
| 301 | * @throws AccessDeniedException Thrown if the user doesn't have required permissions |
||
| 302 | */ |
||
| 303 | public function reloadAction(Request $request) |
||
| 307 | |||
| 308 | /** |
||
| 309 | * {@inheritdoc} |
||
| 310 | * |
||
| 311 | * @Route("/admin/routes/renew", |
||
| 312 | * methods = {"GET", "POST"} |
||
| 313 | * ) |
||
| 314 | * @Theme("admin") |
||
| 315 | * |
||
| 316 | * @param Request $request Current request instance |
||
| 317 | * |
||
| 318 | * @return Response Output |
||
| 319 | * |
||
| 320 | * @throws AccessDeniedException Thrown if the user doesn't have required permissions |
||
| 321 | */ |
||
| 322 | public function adminRenewAction(Request $request) |
||
| 336 | |||
| 337 | /** |
||
| 338 | * {@inheritdoc} |
||
| 339 | * |
||
| 340 | * @Route("/routes/renew", |
||
| 341 | * methods = {"GET", "POST"} |
||
| 342 | * ) |
||
| 343 | * |
||
| 344 | * @param Request $request Current request instance |
||
| 345 | * |
||
| 346 | * @return Response Output |
||
| 347 | * |
||
| 348 | * @throws AccessDeniedException Thrown if the user doesn't have required permissions |
||
| 349 | */ |
||
| 350 | public function renewAction(Request $request) |
||
| 354 | |||
| 355 | /** |
||
| 356 | * Process status changes for multiple items. |
||
| 357 | * |
||
| 358 | * This function processes the items selected in the admin view page. |
||
| 359 | * Multiple items may have their state changed or be deleted. |
||
| 360 | * |
||
| 361 | * @Route("/routes/handleSelectedEntries", |
||
| 362 | * methods = {"POST"} |
||
| 363 | * ) |
||
| 364 | * @Theme("admin") |
||
| 365 | * |
||
| 366 | * @param Request $request Current request instance |
||
| 367 | * |
||
| 368 | * @return bool true on sucess, false on failure |
||
| 369 | * |
||
| 370 | * @throws RuntimeException Thrown if executing the workflow action fails |
||
| 371 | */ |
||
| 372 | public function adminHandleSelectedEntriesAction(Request $request) |
||
| 376 | /** |
||
| 377 | * Process status changes for multiple items. |
||
| 378 | * |
||
| 379 | * This function processes the items selected in the admin view page. |
||
| 380 | * Multiple items may have their state changed or be deleted. |
||
| 381 | * |
||
| 382 | * @Route("/routes/handleSelectedEntries", |
||
| 383 | * methods = {"POST"} |
||
| 384 | * ) |
||
| 385 | * |
||
| 386 | * @param Request $request Current request instance |
||
| 387 | * |
||
| 388 | * @return bool true on sucess, false on failure |
||
| 389 | * |
||
| 390 | * @throws RuntimeException Thrown if executing the workflow action fails |
||
| 391 | */ |
||
| 392 | public function handleSelectedEntriesAction(Request $request) |
||
| 396 | |||
| 397 | /** |
||
| 398 | * Dumps the routes exposed to javascript to '/web/js/fos_js_routes.js'. |
||
| 399 | * |
||
| 400 | * @Route("/routes/dump/{lang}", |
||
| 401 | * name = "zikularoutesmodule_route_dumpjsroutes", |
||
| 402 | * methods = {"GET"} |
||
| 403 | * ) |
||
| 404 | * @Theme("admin") |
||
| 405 | * |
||
| 406 | * @param Request $request Current request instance |
||
| 407 | * |
||
| 408 | * @return Response Output |
||
| 409 | * |
||
| 410 | * @throws AccessDeniedException Thrown if the user doesn't have required permissions |
||
| 411 | */ |
||
| 412 | public function dumpJsRoutesAction(Request $request, $lang = null) |
||
| 430 | } |
||
| 431 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.