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 | class SubFamilyLogController extends Controller |
||
19 | { |
||
20 | /** |
||
21 | * Lists all SubFamilyLog entities. |
||
22 | * |
||
23 | * @Route("/", name="admin_subfamilylog") |
||
24 | * @Method("GET") |
||
25 | * @Template() |
||
26 | */ |
||
27 | public function indexAction(Request $request) |
||
38 | |||
39 | /** |
||
40 | * Finds and displays a SubFamilyLog entity. |
||
41 | * |
||
42 | * @Route("/{slug}/show", name="admin_subfamilylog_show") |
||
43 | * @Method("GET") |
||
44 | * @Template() |
||
45 | */ |
||
46 | public function showAction(SubFamilyLog $subfamilylog) |
||
55 | |||
56 | /** |
||
57 | * Displays a form to create a new SubFamilyLog entity. |
||
58 | * |
||
59 | * @Route("/new", name="admin_subfamilylog_new") |
||
60 | * @Method("GET") |
||
61 | * @Template() |
||
62 | */ |
||
63 | public function newAction() |
||
73 | |||
74 | /** |
||
75 | * Creates a new SubFamilyLog entity. |
||
76 | * |
||
77 | * @Route("/create", name="admin_subfamilylog_create") |
||
78 | * @Method("POST") |
||
79 | * @Template("AppBundle:SubFamilyLog:new.html.twig") |
||
80 | */ |
||
81 | View Code Duplication | public function createAction(Request $request) |
|
109 | |||
110 | /** |
||
111 | * Displays a form to edit an existing SubFamilyLog entity. |
||
112 | * |
||
113 | * @Route("/{slug}/edit", name="admin_subfamilylog_edit") |
||
114 | * @Method("GET") |
||
115 | * @Template() |
||
116 | */ |
||
117 | View Code Duplication | public function editAction(SubFamilyLog $subfamilylog) |
|
134 | |||
135 | /** |
||
136 | * Edits an existing SubFamilyLog entity. |
||
137 | * |
||
138 | * @Route("/{slug}/update", name="admin_subfamilylog_update") |
||
139 | * @Method("PUT") |
||
140 | * @Template("AppBundle:SubFamilyLog:edit.html.twig") |
||
141 | */ |
||
142 | public function updateAction(SubFamilyLog $subfamilylog, Request $request) |
||
167 | |||
168 | |||
169 | /** |
||
170 | * Save order. |
||
171 | * |
||
172 | * @Route("/order/{field}/{type}", name="admin_subfamilylog_sort") |
||
173 | */ |
||
174 | public function sortAction($field, $type) |
||
180 | |||
181 | /** |
||
182 | * @param string $name session name |
||
183 | * @param string $field field name |
||
184 | * @param string $type sort type ("ASC"/"DESC") |
||
185 | */ |
||
186 | protected function setOrder($name, $field, $type = 'ASC') |
||
193 | |||
194 | /** |
||
195 | * @param string $name |
||
196 | * @return array |
||
197 | */ |
||
198 | protected function getOrder($name) |
||
204 | |||
205 | /** |
||
206 | * @param QueryBuilder $qb |
||
207 | * @param string $name |
||
208 | */ |
||
209 | View Code Duplication | protected function addQueryBuilderSort(\Doctrine\ORM\QueryBuilder $qb, $name) |
|
216 | |||
217 | /** |
||
218 | * Deletes a SubFamilyLog entity. |
||
219 | * |
||
220 | * @Route("/{id}/delete", name="admin_subfamilylog_delete", requirements={"id"="\d+"}) |
||
221 | * @Method("DELETE") |
||
222 | */ |
||
223 | public function deleteAction(SubFamilyLog $subfamilylog, Request $request) |
||
234 | |||
235 | /** |
||
236 | * Create Delete form |
||
237 | * |
||
238 | * @param integer $id |
||
239 | * @param string $route |
||
240 | * @return \Symfony\Component\Form\Form |
||
241 | */ |
||
242 | protected function createDeleteForm($id, $route) |
||
250 | } |
||
251 |
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.