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("/dropui", name="dropui", methods={"GET"}) |
||
22 | * |
||
23 | * @return Response |
||
24 | */ |
||
25 | View Code Duplication | public function dropUI() |
|
33 | |||
34 | /** |
||
35 | * @Route("/hosted-fields", name="hosted-fields", methods={"GET"}) |
||
36 | * |
||
37 | * @return Response |
||
38 | */ |
||
39 | View Code Duplication | public function hostedFields() |
|
47 | |||
48 | /** |
||
49 | * @Route("/apm", name="apm", methods={"GET"}) |
||
50 | * |
||
51 | * @return Response |
||
52 | */ |
||
53 | View Code Duplication | public function apm() |
|
62 | |||
63 | /** |
||
64 | * @Route("/3ds", name="three-ds", methods={"GET"}) |
||
65 | * |
||
66 | * @return Response |
||
67 | */ |
||
68 | View Code Duplication | public function threeDS() |
|
76 | |||
77 | /** |
||
78 | * @Route("/payload", name="payload", methods={"POST"}) |
||
79 | * |
||
80 | * @return Response |
||
81 | */ |
||
82 | public function paymentsPayload() |
||
91 | |||
92 | /** |
||
93 | * @Route("/transaction", name="create", methods={"POST"}) |
||
94 | * |
||
95 | * @return Response |
||
96 | */ |
||
97 | public function createTransaction() |
||
112 | |||
113 | /** |
||
114 | * @Route("/transaction/{transactionId}/capture", name="capture", methods={"POST"}) |
||
115 | * |
||
116 | * @param string $transactionId |
||
117 | * |
||
118 | * @return Response |
||
119 | */ |
||
120 | public function captureTransaction(string $transactionId) |
||
130 | |||
131 | /** |
||
132 | * @Route("/{transactionId}", name="get", methods={"GET"}) |
||
133 | * |
||
134 | * @param string $transactionId |
||
135 | * @return Response |
||
136 | * @throws NotFound |
||
137 | */ |
||
138 | public function getTransaction(string $transactionId) |
||
146 | } |
||
147 |
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.