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 |
||
37 | class ParticipantController extends CRUDController |
||
38 | { |
||
39 | protected $entityName = 'KyelaBundle:Participant'; |
||
40 | protected $cancelRoute = 'poll_show'; |
||
41 | protected $successRoute = 'poll_show'; |
||
42 | protected $deleteRoute = 'participant_delete'; |
||
43 | protected $deleteSuccessRoute = 'poll_show'; |
||
44 | |||
45 | /** |
||
46 | * Displays a form to create a new Participant entity. |
||
47 | * |
||
48 | * @Route("/new", name="participant_new") |
||
49 | * @Method({"GET", "POST"}) |
||
50 | * @Template() |
||
51 | */ |
||
52 | public function newAction(Request $request) |
||
56 | |||
57 | /** |
||
58 | * Displays a form to edit an existing Participant entity. |
||
59 | * |
||
60 | * @Route("/{id}/edit", name="participant_edit") |
||
61 | * @Method({"GET", "PUT"}) |
||
62 | * @Template() |
||
63 | */ |
||
64 | public function editAction(Request $request, $id) |
||
68 | |||
69 | /** |
||
70 | * Deletes a Participant entity. |
||
71 | * |
||
72 | * @Route("/{id}", name="participant_delete") |
||
73 | * @Method("DELETE") |
||
74 | */ |
||
75 | public function deleteAction(Request $request, $id) |
||
79 | |||
80 | /** |
||
81 | * Reorder participant |
||
82 | * |
||
83 | * @Route("/order", name="participant_order") |
||
84 | * @Method("POST") |
||
85 | */ |
||
86 | View Code Duplication | public function orderAction(Request $request) |
|
103 | } |
||
104 |
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.