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 |
||
31 | class DeliveriesController extends AbstractOrdersController |
||
32 | { |
||
33 | /** |
||
34 | * Lists all Orders entities. |
||
35 | * |
||
36 | * @Route("/", name="deliveries") |
||
37 | * @Method("GET") |
||
38 | * @Template() |
||
39 | */ |
||
40 | View Code Duplication | public function indexAction(Request $request) |
|
53 | |||
54 | /** |
||
55 | * Finds and displays a Orders entity. |
||
56 | * |
||
57 | * @Route("/{id}/show", name="deliveries_show", requirements={"id"="\d+"}) |
||
58 | * @Method("GET") |
||
59 | * @Template() |
||
60 | */ |
||
61 | public function showAction(Orders $orders) |
||
67 | |||
68 | /** |
||
69 | * Displays a form to edit an existing Orders entity. |
||
70 | * |
||
71 | * @Route("/admin/{id}/edit", name="deliveries_edit", requirements={"id"="\d+"}) |
||
72 | * @Method("GET") |
||
73 | * @Template() |
||
74 | */ |
||
75 | public function editAction(Orders $orders) |
||
87 | |||
88 | /** |
||
89 | * Edits an existing Orders entity. |
||
90 | * |
||
91 | * @Route("/admin/{id}/update", name="deliveries_update", requirements={"id"="\d+"}) |
||
92 | * @Method("PUT") |
||
93 | * @Template("AppBundle:Deliveries:edit.html.twig") |
||
94 | */ |
||
95 | public function updateAction(Orders $orders, Request $request) |
||
122 | |||
123 | /** |
||
124 | * Print the current delivery.<br />Creating a `PDF` file for viewing on paper |
||
125 | * |
||
126 | * @Route("/{id}/print/", name="deliveries_print", requirements={"id"="\d+"}) |
||
127 | * @Method("GET") |
||
128 | * @Template() |
||
129 | * |
||
130 | * @param \AppBundle\Entity\Inventory $orders Inventory item to print |
||
131 | * @return \Symfony\Component\HttpFoundation\Response |
||
132 | */ |
||
133 | public function printAction(Orders $orders) |
||
157 | |||
158 | /** |
||
159 | * Update Articles. |
||
160 | * |
||
161 | * @param \AppBundle\Entity\Orders $orders Articles de la commande à traiter |
||
162 | * @param \Doctrine\Common\Persistence\ObjectManager $etm Entity Manager |
||
163 | */ |
||
164 | private function updateArticles(Orders $orders, $etm) |
||
176 | } |
||
177 |
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.