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 |
||
| 32 | View Code Duplication | class CompanyController extends AbstractAppController |
|
| 33 | { |
||
| 34 | /** |
||
| 35 | * Lists all Company entities. |
||
| 36 | * |
||
| 37 | * @Route("/", name="company") |
||
| 38 | * @Method("GET") |
||
| 39 | * @Template() |
||
| 40 | * |
||
| 41 | * @return array |
||
| 42 | */ |
||
| 43 | public function indexAction() |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Finds and displays a Company entity. |
||
| 52 | * |
||
| 53 | * @Route("/{id}/show", name="company_show", requirements={"id"="\d+"}) |
||
| 54 | * @Method("GET") |
||
| 55 | * @Template() |
||
| 56 | * |
||
| 57 | * @param \App\Entity\Settings\Company $company Company item to display |
||
| 58 | * @return array |
||
| 59 | */ |
||
| 60 | public function showAction(Company $company) |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Displays a form to create a new Company entity. |
||
| 69 | * |
||
| 70 | * @Route("/new", name="company_new") |
||
| 71 | * @Method("GET") |
||
| 72 | * @Template() |
||
| 73 | * |
||
| 74 | * @return array |
||
| 75 | */ |
||
| 76 | public function newAction() |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Creates a new Company entity. |
||
| 90 | * |
||
| 91 | * @Route("/create", name="company_create") |
||
| 92 | * @Method("POST") |
||
| 93 | * @Template("settings/company/new.html.twig") |
||
| 94 | * |
||
| 95 | * @param \Symfony\Component\HttpFoundation\Request $request Form request |
||
| 96 | * @return array |
||
| 97 | */ |
||
| 98 | public function createAction(Request $request) |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Displays a form to edit an existing Company entity. |
||
| 113 | * |
||
| 114 | * @Route("/{id}/edit", name="company_edit", requirements={"id"="\d+"}) |
||
| 115 | * @Method("GET") |
||
| 116 | * @Template() |
||
| 117 | * |
||
| 118 | * @param \App\Entity\Settings\Company $company Company item to edit |
||
| 119 | * @return array |
||
| 120 | */ |
||
| 121 | public function editAction(Company $company) |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Edits an existing Company entity. |
||
| 134 | * |
||
| 135 | * @Route("/{id}/update", name="company_update", requirements={"id"="\d+"}) |
||
| 136 | * @Method("PUT") |
||
| 137 | * @Template("settings/company/edit.html.twig") |
||
| 138 | * |
||
| 139 | * @param \App\Entity\Settings\Company $company Company item to update |
||
| 140 | * @param \Symfony\Component\HttpFoundation\Request $request Form request |
||
| 141 | * @return array |
||
| 142 | */ |
||
| 143 | public function updateAction(Company $company, Request $request) |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Deletes a Company entity. |
||
| 157 | * |
||
| 158 | * @Route("/{id}/delete", name="company_delete", requirements={"id"="\d+"}) |
||
| 159 | * @Method("DELETE") |
||
| 160 | * |
||
| 161 | * @param \App\Entity\Settings\Company $company Company item to delete |
||
| 162 | * @param \Symfony\Component\HttpFoundation\Request $request Form request |
||
| 163 | * @return array |
||
| 164 | */ |
||
| 165 | public function deleteAction(Company $company, Request $request) |
||
| 175 | } |
||
| 176 |