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 |
||
20 | class AdyenController extends AbstractController |
||
21 | { |
||
22 | /** |
||
23 | * @var AdyenService |
||
24 | */ |
||
25 | protected $adyenService; |
||
26 | |||
27 | /** |
||
28 | * AdyenController constructor. |
||
29 | * @param PaypalService $paypalService |
||
30 | * @param AdyenService $adyenService |
||
31 | */ |
||
32 | public function __construct(PaypalService $paypalService, AdyenService $adyenService) |
||
37 | |||
38 | /** |
||
39 | * @Route("/", name="index", methods={"GET"}) |
||
40 | * @return Response | RedirectResponse |
||
41 | * @throws AdyenException |
||
42 | */ |
||
43 | public function index() |
||
54 | |||
55 | /** |
||
56 | * @Route("/make-payment", name="make-payment", methods={"POST"}) |
||
57 | * @return JsonResponse |
||
58 | * @throws AdyenException |
||
59 | */ |
||
60 | public function makePayment() |
||
68 | |||
69 | /** |
||
70 | * @Route("/payment-details", name="payment-details", methods={"POST"}) |
||
71 | * @return Response |
||
72 | * @throws AdyenException |
||
73 | */ |
||
74 | View Code Duplication | public function paymentDetails() |
|
85 | } |
||
86 |
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.