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 | View Code Duplication | class QRCodeGateway extends AbstractGateway |
|
|
|||
21 | { |
||
22 | use Concerns\Parameters; |
||
23 | |||
24 | /** |
||
25 | * {@inheritdoc} |
||
26 | */ |
||
27 | public function getName(): string |
||
31 | |||
32 | /** |
||
33 | * Tạo request notification gửi từ MoMo. |
||
34 | * |
||
35 | * @param array $options |
||
36 | * @return \Omnipay\Common\Message\RequestInterface|NotificationRequest |
||
37 | */ |
||
38 | public function notification(array $options = []): NotificationRequest |
||
42 | |||
43 | /** |
||
44 | * Tạo yêu cầu xác nhận hoàn thành hoặc hủy bỏ giao dịch đến MoMo. |
||
45 | * |
||
46 | * @param array $options |
||
47 | * @return \Omnipay\Common\Message\RequestInterface|PayConfirmRequest |
||
48 | */ |
||
49 | public function payConfirm(array $options = []): PayConfirmRequest |
||
53 | |||
54 | /** |
||
55 | * Tạo yêu cầu truy vấn thông tin giao dịch đến MoMo. |
||
56 | * |
||
57 | * @param array $options |
||
58 | * @return \Omnipay\Common\Message\RequestInterface|PayQueryStatusRequest |
||
59 | */ |
||
60 | public function queryTransaction(array $options = []): PayQueryStatusRequest |
||
64 | |||
65 | /** |
||
66 | * {@inheritdoc} |
||
67 | * @return \Omnipay\Common\Message\RequestInterface|PayRefundRequest |
||
68 | */ |
||
69 | public function refund(array $options = []): PayRefundRequest |
||
73 | } |
||
74 |
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.