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 |
||
11 | class EcpayApi extends Api |
||
12 | { |
||
13 | /** |
||
14 | * $client. |
||
15 | * |
||
16 | * @var \Payum\Core\HttpClientInterface |
||
17 | */ |
||
18 | protected $client; |
||
19 | |||
20 | /** |
||
21 | * MessageFactory. |
||
22 | * |
||
23 | * @var \Http\Message\MessageFactory |
||
24 | */ |
||
25 | protected $messageFactory; |
||
26 | |||
27 | /** |
||
28 | * $options. |
||
29 | * |
||
30 | * @var array |
||
31 | */ |
||
32 | protected $options = []; |
||
33 | |||
34 | /** |
||
35 | * $sdk. |
||
36 | * |
||
37 | * @var \PayumTW\Ecpay\Sdk\AllInOne |
||
38 | */ |
||
39 | protected $sdk; |
||
40 | |||
41 | /** |
||
42 | * @param array $options |
||
43 | * @param \Payum\Core\HttpClientInterface $client |
||
44 | * @param \Http\Message\MessageFactory $messageFactory |
||
45 | * @param \PayumTW\Ecpay\Sdk\AllInOne $sdk |
||
46 | * |
||
47 | * @throws \Payum\Core\Exception\InvalidArgumentException if an option is invalid |
||
48 | */ |
||
49 | 5 | View Code Duplication | public function __construct(array $options, HttpClientInterface $client, MessageFactory $messageFactory, AllInOne $sdk = null) |
59 | |||
60 | /** |
||
61 | * getApiEndpoint. |
||
62 | * |
||
63 | * @return string |
||
64 | */ |
||
65 | 4 | public function getApiEndpoint($name = 'AioCheckOut') |
|
87 | |||
88 | /** |
||
89 | * createTransaction. |
||
90 | * |
||
91 | * @param array $params |
||
92 | * @return array |
||
93 | */ |
||
94 | 1 | public function createTransaction(array $params) |
|
127 | |||
128 | /** |
||
129 | * cancelTransaction. |
||
130 | * |
||
131 | * @param array $params |
||
132 | * @return array |
||
133 | */ |
||
134 | 1 | View Code Duplication | public function cancelTransaction($params) |
144 | |||
145 | /** |
||
146 | * refundTransaction. |
||
147 | * |
||
148 | * @param array $params |
||
149 | * @return array |
||
150 | */ |
||
151 | 1 | View Code Duplication | public function refundTransaction($params) |
161 | |||
162 | /** |
||
163 | * getTransactionData. |
||
164 | * |
||
165 | * @param mixed $params |
||
166 | * @return array |
||
167 | */ |
||
168 | 1 | public function getTransactionData($params) |
|
177 | } |
||
178 |
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.