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 PaymentsController extends AbstractController |
||
19 | { |
||
20 | /** |
||
21 | * @Route("/pay-ins", name="pay-ins", methods={"GET"}, defaults={"action" = "pay-ins"}) |
||
22 | * @Route("/pay-outs", name="pay-outs", methods={"GET"}, defaults={"action" = "pay-outs"}) |
||
23 | * @Route("/bopis", name="bopis", methods={"GET"}, defaults={"action" = "bopis"}) |
||
24 | * @Route("/subscriptions", name="subscriptions", methods={"GET"}, defaults={"action" = "subscriptions"}) |
||
25 | * @Route("/invoices", name="invoices", methods={"GET"}, defaults={"action" = "invoices"}) |
||
26 | * @Route("/ecs", name="ecs", methods={"GET"}, defaults={"action" = "ecs"}) |
||
27 | * |
||
28 | * @param string $action |
||
29 | * |
||
30 | * @return Response | RedirectResponse |
||
31 | */ |
||
32 | public function payments(string $action) |
||
36 | |||
37 | /** |
||
38 | * @Route("/{paymentId}/capture", name="capture", methods={"POST"}) |
||
39 | * @param string $paymentId |
||
40 | * @return Response | RedirectResponse |
||
41 | */ |
||
42 | View Code Duplication | public function capture(string $paymentId) |
|
51 | |||
52 | /** |
||
53 | * @Route("/pay-outs", name="pay-outs-create", methods={"POST"}) |
||
54 | * |
||
55 | * @return Response | RedirectResponse |
||
56 | */ |
||
57 | public function payoutsCreate() |
||
75 | |||
76 | /** |
||
77 | * @Route("/pay-outs/{statusId}", name="pay-outs-refresh", methods={"GET"}) |
||
78 | * |
||
79 | * @param string $statusId |
||
80 | * @return Response | RedirectResponse |
||
81 | */ |
||
82 | public function payoutsRefresh(string $statusId) |
||
91 | |||
92 | /** |
||
93 | * @Route("/invoices", name="invoices-create", methods={"POST"}) |
||
94 | * |
||
95 | * @return Response | RedirectResponse |
||
96 | */ |
||
97 | public function invoicesCreate() |
||
115 | |||
116 | /** |
||
117 | * @Route("/invoices/{invoiceId}", name="invoices-refresh", methods={"GET"}) |
||
118 | * @param string $invoiceId |
||
119 | * @return Response | RedirectResponse |
||
120 | */ |
||
121 | View Code Duplication | public function invoicesRefresh(string $invoiceId) |
|
130 | |||
131 | /** |
||
132 | * @Route("/{paymentId}/ecs-result", name="ecs-result", methods={"POST"}) |
||
133 | * @param string $paymentId |
||
134 | * @return Response | RedirectResponse |
||
135 | */ |
||
136 | public function ecsResult(string $paymentId) |
||
143 | } |
||
144 |
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.