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 |
||
19 | View Code Duplication | class ApplicationController extends Controller |
|
1 ignored issue
–
show
|
|||
20 | { |
||
21 | /** |
||
22 | * Lists all Settings entities. |
||
23 | * |
||
24 | * @Route("/", name="admin_application") |
||
25 | * @Method("GET") |
||
26 | * @Template() |
||
27 | */ |
||
28 | public function indexAction() |
||
38 | |||
39 | /** |
||
40 | * Finds and displays a Settings entity. |
||
41 | * |
||
42 | * @Route("/{id}/show", name="admin_application_show", requirements={"id"="\d+"}) |
||
43 | * @Method("GET") |
||
44 | * @Template() |
||
45 | */ |
||
46 | public function showAction(Settings $settings) |
||
55 | |||
56 | /** |
||
57 | * Displays a form to create a new Settings entity. |
||
58 | * |
||
59 | * @Route("/new", name="admin_application_new") |
||
60 | * @Method("GET") |
||
61 | * @Template() |
||
62 | */ |
||
63 | public function newAction() |
||
73 | |||
74 | /** |
||
75 | * Creates a new Settings entity. |
||
76 | * |
||
77 | * @Route("/create", name="admin_application_create") |
||
78 | * @Method("POST") |
||
79 | * @Template("AppBundle:Application:new.html.twig") |
||
80 | */ |
||
81 | public function createAction(Request $request) |
||
98 | |||
99 | /** |
||
100 | * Displays a form to edit an existing Settings entity. |
||
101 | * |
||
102 | * @Route("/{id}/edit", name="admin_application_edit", requirements={"id"="\d+"}) |
||
103 | * @Method("GET") |
||
104 | * @Template() |
||
105 | */ |
||
106 | public function editAction(Settings $settings) |
||
120 | |||
121 | /** |
||
122 | * Edits an existing Settings entity. |
||
123 | * |
||
124 | * @Route("/{id}/update", name="admin_application_update", requirements={"id"="\d+"}) |
||
125 | * @Method("PUT") |
||
126 | * @Template("AppBundle:Application:edit.html.twig") |
||
127 | */ |
||
128 | public function updateAction(Settings $settings, Request $request) |
||
147 | |||
148 | /** |
||
149 | * Deletes a Settings entity. |
||
150 | * |
||
151 | * @Route("/{id}/delete", name="admin_application_delete", requirements={"id"="\d+"}) |
||
152 | * @Method("DELETE") |
||
153 | */ |
||
154 | public function deleteAction(Settings $settings, Request $request) |
||
165 | |||
166 | /** |
||
167 | * Create Delete form |
||
168 | * |
||
169 | * @param integer $id |
||
170 | * @param string $route |
||
171 | * @return \Symfony\Component\Form\Form |
||
172 | */ |
||
173 | protected function createDeleteForm($id, $route) |
||
181 | |||
182 | } |
||
183 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.