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 |
||
| 26 | class FormSubmissionsController extends Controller |
||
| 27 | { |
||
| 28 | /** |
||
| 29 | * The index action will use an admin list to list all the form pages |
||
| 30 | * |
||
| 31 | * @Route("/", name="KunstmaanFormBundle_formsubmissions") |
||
| 32 | * @Template("KunstmaanAdminListBundle:Default:list.html.twig") |
||
| 33 | * |
||
| 34 | * @return array |
||
|
|
|||
| 35 | */ |
||
| 36 | View Code Duplication | public function indexAction(Request $request) |
|
| 51 | |||
| 52 | /** |
||
| 53 | * The list action will use an admin list to list all the form submissions related to the given $nodeTranslationId |
||
| 54 | * |
||
| 55 | * @param int $nodeTranslationId |
||
| 56 | * |
||
| 57 | * @Route("/list/{nodeTranslationId}", requirements={"nodeTranslationId" = "\d+"}, |
||
| 58 | * name="KunstmaanFormBundle_formsubmissions_list") |
||
| 59 | * @Method({"GET", "POST"}) |
||
| 60 | * @Template() |
||
| 61 | * |
||
| 62 | * @return array |
||
| 63 | */ |
||
| 64 | public function listAction(Request $request, $nodeTranslationId) |
||
| 78 | |||
| 79 | /** |
||
| 80 | * The edit action will be used to edit a given submission. |
||
| 81 | * |
||
| 82 | * @param int $nodeTranslationId The node translation id |
||
| 83 | * @param int $submissionId The submission id |
||
| 84 | * |
||
| 85 | * @Route("/list/{nodeTranslationId}/{submissionId}", requirements={"nodeTranslationId" = "\d+", "submissionId" = |
||
| 86 | * "\d+"}, name="KunstmaanFormBundle_formsubmissions_list_edit") |
||
| 87 | * @Method({"GET", "POST"}) |
||
| 88 | * @Template() |
||
| 89 | * |
||
| 90 | * @return array |
||
| 91 | */ |
||
| 92 | public function editAction($nodeTranslationId, $submissionId) |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Export as CSV of all the form submissions for the given $nodeTranslationId |
||
| 116 | * |
||
| 117 | * @param int $nodeTranslationId |
||
| 118 | * |
||
| 119 | * @Route("/export/{nodeTranslationId}.{_format}", requirements={"nodeTranslationId" = "\d+","_format" = |
||
| 120 | * "csv|xlsx|ods"}, name="KunstmaanFormBundle_formsubmissions_export") |
||
| 121 | * @Method({"GET"}) |
||
| 122 | * |
||
| 123 | * @return Response |
||
| 124 | */ |
||
| 125 | public function exportAction($nodeTranslationId, $_format) |
||
| 138 | |||
| 139 | /** |
||
| 140 | * @Route( |
||
| 141 | * "/{id}/delete", |
||
| 142 | * requirements={"id" = "\d+"}, |
||
| 143 | * name="KunstmaanFormBundle_formsubmissions_delete" |
||
| 144 | * ) |
||
| 145 | * @Template() |
||
| 146 | * @Method("POST") |
||
| 147 | * |
||
| 148 | * @param Request $request |
||
| 149 | * @param int $id |
||
| 150 | * |
||
| 151 | * @return RedirectResponse |
||
| 152 | * |
||
| 153 | * @throws AccessDeniedException |
||
| 154 | */ |
||
| 155 | public function deleteAction(Request $request, $id) |
||
| 196 | } |
||
| 197 |
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.