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 |
||
31 | class PaymentGateway extends BasePaymentGateway |
||
32 | { |
||
33 | |||
34 | /** |
||
35 | * Đường dẫn API để yêu cầu tạo giao dịch thanh toán. |
||
36 | */ |
||
37 | const PURCHASE_URL = '/checkout.html'; |
||
38 | |||
39 | /** |
||
40 | * Phương thức thanh toán bằng ví điện tử VTCPay. |
||
41 | */ |
||
42 | const PAYMENT_METHOD_VTCPAY = 'VTCPay'; |
||
43 | |||
44 | /** |
||
45 | * Phương thức thanh toán bằng ngân hàng trong nước. |
||
46 | */ |
||
47 | const PAYMENT_METHOD_DOMESTIC_BANK = 'DomesticBank'; |
||
48 | |||
49 | /** |
||
50 | * Phương thức thanh toán bằng thẻ quốc tế (visa/master). |
||
51 | */ |
||
52 | const PAYMENT_METHOD_INTERNATIONAL_CARD = 'InternationalCard'; |
||
53 | |||
54 | /** |
||
55 | * @inheritdoc |
||
56 | */ |
||
57 | public $clientConfig = ['class' => PaymentClient::class]; |
||
58 | |||
59 | /** |
||
60 | * @inheritdoc |
||
61 | */ |
||
62 | public $requestDataConfig = ['class' => RequestData::class]; |
||
63 | |||
64 | /** |
||
65 | * @inheritdoc |
||
66 | */ |
||
67 | public $responseDataConfig = ['class' => ResponseData::class]; |
||
68 | |||
69 | /** |
||
70 | * @inheritdoc |
||
71 | */ |
||
72 | public $verifiedDataConfig = ['class' => VerifiedData::class]; |
||
73 | |||
74 | /** |
||
75 | * @inheritdoc |
||
76 | */ |
||
77 | 2 | public function getBaseUrl(): string |
|
81 | |||
82 | /** |
||
83 | * @inheritdoc |
||
84 | */ |
||
85 | 3 | public function requestCommands(): array |
|
89 | |||
90 | /** |
||
91 | * @inheritdoc |
||
92 | */ |
||
93 | 13 | protected function initSandboxEnvironment() |
|
98 | |||
99 | /** |
||
100 | * @inheritdoc |
||
101 | * @throws NotSupportedException |
||
102 | */ |
||
103 | 1 | public function queryDR(array $data, $clientId = null): DataInterface |
|
107 | |||
108 | /** |
||
109 | * @inheritdoc |
||
110 | * @throws \yii\base\InvalidConfigException |
||
111 | */ |
||
112 | 2 | protected function requestInternal(\vxm\gatewayclients\RequestData $requestData, HttpClient $httpClient): array |
|
119 | |||
120 | /** |
||
121 | * @param int|string $command |
||
122 | * @param \yii\web\Request $request |
||
123 | * @return array |
||
124 | */ |
||
125 | 5 | protected function getVerifyRequestData($command, \yii\web\Request $request): array |
|
145 | |||
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.