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 | * Đường dẫn API của thanh toán nội địa. |
||
35 | */ |
||
36 | const PURCHASE_DOMESTIC_URL = '/onecomm-pay/vpc.op'; |
||
37 | |||
38 | /** |
||
39 | * Đường dẫn API để truy vấn thông tin giao dịch nội địa. |
||
40 | */ |
||
41 | const QUERY_DR_DOMESTIC_URL = '/onecomm-pay/Vpcdps.op'; |
||
42 | |||
43 | /** |
||
44 | * Đường dẫn API của thanh toán quốc tế. |
||
45 | */ |
||
46 | const PURCHASE_INTERNATIONAL_URL = '/vpcpay/vpcpay.op'; |
||
47 | |||
48 | /** |
||
49 | * Đường dẫn API để truy vấn thông tin giao dịch quốc tế. |
||
50 | */ |
||
51 | const QUERY_DR_INTERNATIONAL_URL = '/vpcpay/Vpcdps.op'; |
||
52 | |||
53 | /** |
||
54 | * Id của client trong môi trường thử nghiệm dùng để giao tiếp với OnePay ở cổng quốc tế. |
||
55 | */ |
||
56 | const ID_CLIENT_SANDBOX_INTERNATIONAL = '__sandboxInternational'; |
||
57 | |||
58 | /** |
||
59 | * Id của client trong môi trường thử nghiệm dùng để giao tiếp với OnePay ở cổng nội địa. |
||
60 | */ |
||
61 | const ID_CLIENT_SANDBOX_DOMESTIC = '__sandboxDomestic'; |
||
62 | |||
63 | /** |
||
64 | * @var bool Optional to use international gateway. Set to TRUE if you want use methods (requests, verifies) with international mode. |
||
65 | */ |
||
66 | public $international = false; |
||
67 | |||
68 | /** |
||
69 | * @inheritdoc |
||
70 | */ |
||
71 | public $clientConfig = ['class' => PaymentClient::class]; |
||
72 | |||
73 | /** |
||
74 | * @inheritdoc |
||
75 | */ |
||
76 | public $requestDataConfig = ['class' => RequestData::class]; |
||
77 | |||
78 | /** |
||
79 | * @inheritdoc |
||
80 | */ |
||
81 | public $responseDataConfig = ['class' => ResponseData::class]; |
||
82 | |||
83 | /** |
||
84 | * @inheritdoc |
||
85 | */ |
||
86 | public $verifiedDataConfig = ['class' => VerifiedData::class]; |
||
87 | |||
88 | /** |
||
89 | * @inheritdoc |
||
90 | */ |
||
91 | 4 | public function getBaseUrl(): string |
|
95 | |||
96 | /** |
||
97 | * @inheritdoc |
||
98 | * @since 1.0.3 |
||
99 | */ |
||
100 | 4 | public function requestCommands(): array |
|
104 | |||
105 | /** |
||
106 | * @return ResponseData|DataInterface |
||
107 | * @inheritdoc |
||
108 | */ |
||
109 | 4 | View Code Duplication | public function request($command, array $data, $clientId = null): DataInterface |
117 | |||
118 | /** |
||
119 | * @return bool|VerifiedData |
||
120 | * @inheritdoc |
||
121 | */ |
||
122 | 4 | View Code Duplication | public function verifyRequest($command, \yii\web\Request $request = null, $clientId = null) |
130 | |||
131 | /** |
||
132 | * @inheritdoc |
||
133 | */ |
||
134 | 4 | protected function defaultVersion(): string |
|
138 | |||
139 | /** |
||
140 | * @inheritdoc |
||
141 | * @throws \yii\base\InvalidConfigException |
||
142 | */ |
||
143 | 9 | protected function initSandboxEnvironment() |
|
151 | |||
152 | /** |
||
153 | * @inheritdoc |
||
154 | * @throws \yii\base\InvalidConfigException|\yii\httpclient\Exception |
||
155 | */ |
||
156 | 4 | protected function requestInternal(\vxm\gatewayclients\RequestData $requestData, \yii\httpclient\Client $httpClient): array |
|
173 | |||
174 | /** |
||
175 | * @inheritdoc |
||
176 | */ |
||
177 | 4 | View Code Duplication | protected function getVerifyRequestData($command, \yii\web\Request $request): array |
189 | |||
190 | } |
||
191 |
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.