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 |
||
30 | class PaymentGateway extends BasePaymentGateway |
||
31 | { |
||
32 | |||
33 | /** |
||
34 | * Đường dẫn API để yêu cầu tạo giao dịch thanh toán. |
||
35 | */ |
||
36 | const PURCHASE_URL = '/paymentv2/vpcpay.html'; |
||
37 | |||
38 | /** |
||
39 | * Đường dẫn API để truy vấn thông tin giao dịch. |
||
40 | */ |
||
41 | const QUERY_DR_URL = '/merchant_webapi/merchant.html'; |
||
42 | |||
43 | /** |
||
44 | * Đường dẫn API để yêu cầu hoàn trả tiền. |
||
45 | */ |
||
46 | const REFUND_URL = '/merchant_webapi/merchant.html'; |
||
47 | |||
48 | /** |
||
49 | * @inheritdoc |
||
50 | */ |
||
51 | public $clientConfig = ['class' => PaymentClient::class]; |
||
52 | |||
53 | /** |
||
54 | * @inheritdoc |
||
55 | */ |
||
56 | public $requestDataConfig = ['class' => RequestData::class]; |
||
57 | |||
58 | /** |
||
59 | * @inheritdoc |
||
60 | */ |
||
61 | public $responseDataConfig = ['class' => ResponseData::class]; |
||
62 | |||
63 | /** |
||
64 | * @inheritdoc |
||
65 | */ |
||
66 | public $verifiedDataConfig = ['class' => VerifiedData::class]; |
||
67 | |||
68 | /** |
||
69 | * @inheritdoc |
||
70 | */ |
||
71 | 3 | public function getBaseUrl(): string |
|
75 | |||
76 | /** |
||
77 | * @inheritdoc |
||
78 | * @since 1.0.3 |
||
79 | */ |
||
80 | 3 | public function requestCommands(): array |
|
84 | |||
85 | /** |
||
86 | * @inheritdoc |
||
87 | */ |
||
88 | 3 | protected function defaultVersion(): string |
|
92 | |||
93 | /** |
||
94 | * @inheritdoc |
||
95 | * @throws \yii\base\InvalidConfigException |
||
96 | */ |
||
97 | 7 | protected function initSandboxEnvironment() |
|
103 | |||
104 | /** |
||
105 | * @inheritdoc |
||
106 | * @throws \yii\base\InvalidConfigException|\yii\httpclient\Exception |
||
107 | */ |
||
108 | 3 | protected function requestInternal(\vxm\gatewayclients\RequestData $requestData, \yii\httpclient\Client $httpClient): array |
|
125 | |||
126 | /** |
||
127 | * @inheritdoc |
||
128 | */ |
||
129 | 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.