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 |
||
18 | View Code Duplication | class ZoneStorageController extends Controller |
|
1 ignored issue
–
show
|
|||
19 | { |
||
20 | /** |
||
21 | * Lists all ZoneStorage entities. |
||
22 | * |
||
23 | * @Route("/", name="admin_zonestorage") |
||
24 | * @Method("GET") |
||
25 | * @Template() |
||
26 | */ |
||
27 | public function indexAction() |
||
36 | |||
37 | /** |
||
38 | * Finds and displays a ZoneStorage entity. |
||
39 | * |
||
40 | * @Route("/{slug}/show", name="admin_zonestorage_show") |
||
41 | * @Method("GET") |
||
42 | * @Template() |
||
43 | */ |
||
44 | public function showAction(ZoneStorage $zonestorage) |
||
53 | |||
54 | /** |
||
55 | * Displays a form to create a new ZoneStorage entity. |
||
56 | * |
||
57 | * @Route("/new", name="admin_zonestorage_new") |
||
58 | * @Method("GET") |
||
59 | * @Template() |
||
60 | */ |
||
61 | public function newAction() |
||
71 | |||
72 | /** |
||
73 | * Creates a new ZoneStorage entity. |
||
74 | * |
||
75 | * @Route("/create", name="admin_zonestorage_create") |
||
76 | * @Method("POST") |
||
77 | * @Template("AppBundle:Settings/Divers/ZoneStorage:new.html.twig") |
||
78 | */ |
||
79 | public function createAction(Request $request) |
||
102 | |||
103 | /** |
||
104 | * Displays a form to edit an existing ZoneStorage entity. |
||
105 | * |
||
106 | * @Route("/{slug}/edit", name="admin_zonestorage_edit") |
||
107 | * @Method("GET") |
||
108 | * @Template() |
||
109 | */ |
||
110 | public function editAction(ZoneStorage $zonestorage) |
||
124 | |||
125 | /** |
||
126 | * Edits an existing ZoneStorage entity. |
||
127 | * |
||
128 | * @Route("/{slug}/update", name="admin_zonestorage_update") |
||
129 | * @Method("PUT") |
||
130 | * @Template("AppBundle:Settings/Divers/ZoneStorage:edit.html.twig") |
||
131 | */ |
||
132 | public function updateAction(ZoneStorage $zonestorage, Request $request) |
||
151 | |||
152 | /** |
||
153 | * Deletes a ZoneStorage entity. |
||
154 | * |
||
155 | * @Route("/{id}/delete", name="admin_zonestorage_delete", requirements={"id"="\d+"}) |
||
156 | * @Method("DELETE") |
||
157 | */ |
||
158 | public function deleteAction(ZoneStorage $zonestorage, Request $request) |
||
169 | |||
170 | /** |
||
171 | * Create Delete form |
||
172 | * |
||
173 | * @param integer $id |
||
174 | * @param string $route |
||
175 | * @return \Symfony\Component\Form\Form |
||
176 | */ |
||
177 | protected function createDeleteForm($id, $route) |
||
185 | |||
186 | } |
||
187 |
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.