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 |
||
| 34 | class OrdersController extends AbstractOrdersController |
||
| 35 | { |
||
| 36 | /** |
||
| 37 | * Lists all Orders entities. |
||
| 38 | * |
||
| 39 | * @Route("/", name="orders") |
||
| 40 | * @Method("GET") |
||
| 41 | * @Template() |
||
| 42 | */ |
||
| 43 | public function indexAction(Request $request) |
||
| 44 | { |
||
| 45 | $etm = $this->getDoctrine()->getManager(); |
||
| 46 | $item = $this->container->getParameter('knp_paginator.page_range'); |
||
| 47 | $qbd = $etm->getRepository('AppBundle:Orders')->createQueryBuilder('o'); |
||
| 48 | $qbd->where('o.delivdate > ' . date('Y-m-d')); |
||
| 49 | $qbd->andWhere('o.status = 1'); |
||
| 50 | |||
| 51 | $createForm = $this->createCreateForm('orders_create'); |
||
| 52 | |||
| 53 | $paginator = $this->get('knp_paginator')->paginate($qbd, $request->query->get('page', 1), $item); |
||
| 54 | return array( |
||
| 55 | 'create_form' => $createForm->createView(), |
||
| 56 | 'paginator' => $paginator, |
||
| 57 | ); |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Finds and displays a Orders entity. |
||
| 62 | * |
||
| 63 | * @Route("/{id}/show", name="orders_show", requirements={"id"="\d+"}) |
||
| 64 | * @Method("GET") |
||
| 65 | * @Template() |
||
| 66 | */ |
||
| 67 | public function showAction(Orders $orders) |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Displays a form to create a new Orders entity. |
||
| 79 | * |
||
| 80 | * @Route("/new/{supplier}", name="orders_new") |
||
| 81 | * @Method("GET") |
||
| 82 | * @Template() |
||
| 83 | */ |
||
| 84 | public function newAction(Supplier $supplier) |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Creates a new Orders entity. |
||
| 106 | * |
||
| 107 | * @Route("/admin/create", name="orders_create") |
||
| 108 | * @Method("POST") |
||
| 109 | * @Template("AppBundle:Orders:new.html.twig") |
||
| 110 | */ |
||
| 111 | public function createAction(Request $request) |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Displays a form to edit an existing Orders entity. |
||
| 144 | * |
||
| 145 | * @Route("/admin/{id}/edit", name="orders_edit", requirements={"id"="\d+"}) |
||
| 146 | * @Method("GET") |
||
| 147 | * @Template() |
||
| 148 | */ |
||
| 149 | public function editAction(Orders $orders) |
||
| 163 | |||
| 164 | /** |
||
| 165 | * Edits an existing Orders entity. |
||
| 166 | * |
||
| 167 | * @Route("/admin/{id}/update", name="orders_update", requirements={"id"="\d+"}) |
||
| 168 | * @Method("PUT") |
||
| 169 | * @Template("AppBundle:Orders:edit.html.twig") |
||
| 170 | */ |
||
| 171 | public function updateAction(Orders $orders, Request $request) |
||
| 195 | |||
| 196 | /** |
||
| 197 | * Deletes a Orders entity. |
||
| 198 | * |
||
| 199 | * @Route("/admin/{id}/delete", name="orders_delete", requirements={"id"="\d+"}) |
||
| 200 | * @Method("DELETE") |
||
| 201 | */ |
||
| 202 | public function deleteAction(Orders $orders, Request $request) |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Set order Dates. |
||
| 211 | * |
||
| 212 | * @param \AppBundle\Entity\Orders $orders La commande à traiter |
||
| 213 | * @param \AppBundle\Entity\Supplier $supplier Le fournisseur concerné |
||
| 214 | * @return \AppBundle\Entity\Orders La commande modifiée |
||
| 215 | */ |
||
| 216 | private function setDates(Orders $orders, Supplier $supplier) |
||
| 236 | |||
| 237 | /** |
||
| 238 | * Save OrdersArticles. |
||
| 239 | * |
||
| 240 | * @param array $articles Liste des articles |
||
| 241 | * @param \AppBundle\Entity\Orders $orders La commande à traiter |
||
| 242 | * @param \Doctrine\Common\Persistence\ObjectManager $etm Entity Manager |
||
| 243 | */ |
||
| 244 | private function saveOrdersArticles($articles, $orders, $etm) |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Print the current order.<br />Creating a `PDF` file for viewing on paper |
||
| 262 | * |
||
| 263 | * @Route("/{id}/print/", name="orders_print", requirements={"id"="\d+"}) |
||
| 264 | * @Method("GET") |
||
| 265 | * @Template() |
||
| 266 | * |
||
| 267 | * @param \AppBundle\Entity\Orders $orders Order item to print |
||
| 268 | * @return \Symfony\Component\HttpFoundation\Response |
||
| 269 | */ |
||
| 270 | public function printAction(Orders $orders) |
||
| 276 | } |
||
| 277 |