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 |
||
23 | class ApplicationGateway extends AbstractGateway |
||
24 | { |
||
25 | /** |
||
26 | * @author WN |
||
27 | * @param int $id |
||
28 | * @param string $token |
||
29 | * @return ApplicationEntity |
||
30 | * @throws SdkException |
||
31 | */ |
||
32 | 2 | public function getApplication($id, $token) |
|
36 | |||
37 | /** |
||
38 | * @author WN |
||
39 | * @param ApplicationEntity $application |
||
40 | * @param string $token |
||
41 | * @return ApplicationEntity |
||
42 | * @throws SdkException |
||
43 | */ |
||
44 | 6 | View Code Duplication | public function initialiseApplication(ApplicationEntity $application, $token) |
67 | |||
68 | /** |
||
69 | * @author EA, EB |
||
70 | * @param ApplicationEntity $application |
||
71 | * @param string $token |
||
72 | * @return ApplicationEntity |
||
73 | * @throws SdkException |
||
74 | */ |
||
75 | 2 | View Code Duplication | public function initialiseAssistedApplication(ApplicationEntity $application, $token) |
99 | |||
100 | /** |
||
101 | * @author WN |
||
102 | * @param int $id |
||
103 | * @param string $token |
||
104 | * @return bool |
||
105 | * @throws SdkException |
||
106 | */ |
||
107 | 2 | public function fulfilApplication($id, $token) |
|
111 | |||
112 | /** |
||
113 | * @param int $id |
||
114 | * @param string $description |
||
115 | * @param string $token |
||
116 | * @return bool |
||
117 | * @throws SdkException |
||
118 | */ |
||
119 | 2 | public function cancelApplication($id, $description, $token) |
|
127 | |||
128 | /** |
||
129 | * @param $token |
||
130 | * @return array |
||
131 | * @throws SdkException |
||
132 | */ |
||
133 | 2 | public function getPendingCancellations($installationId, $token) |
|
142 | |||
143 | /** |
||
144 | * Get Merchant Payments. Filter Params can accept |
||
145 | * - since, until : (string - ISO8601 Date Part Only) |
||
146 | * - count, offset : (int) |
||
147 | * |
||
148 | * @author SL |
||
149 | * @param $application |
||
150 | * @param $token |
||
151 | * @param array $filterParams |
||
152 | * @return array |
||
153 | */ |
||
154 | 2 | public function getMerchantPayments($application, $token, array $filterParams = []) |
|
163 | |||
164 | /** |
||
165 | * Add a Merchant Payment to the given application. Amount should be supplied in pence. |
||
166 | * |
||
167 | * @author SL |
||
168 | * @param string $application |
||
169 | * @param \DateTime $effectiveDate |
||
170 | * @param int $amount |
||
171 | * @param string $token |
||
172 | * @return array |
||
173 | */ |
||
174 | 2 | public function addMerchantPayment($application, \DateTime $effectiveDate, $amount, $token) |
|
186 | |||
187 | /** |
||
188 | * @author EB |
||
189 | * @param $installationId |
||
190 | * @param $application |
||
191 | * @param $token |
||
192 | * @return array |
||
193 | */ |
||
194 | 2 | public function getApplicationCreditInfo($installationId, $application, $token) |
|
203 | |||
204 | /** |
||
205 | * Get application history |
||
206 | * |
||
207 | * @author SL |
||
208 | * @param $application |
||
209 | * @param $token |
||
210 | * @return array |
||
211 | */ |
||
212 | 2 | public function getApplicationHistory($application, $token) |
|
220 | |||
221 | /** |
||
222 | * @author WN |
||
223 | * @param string $action |
||
224 | * @param array $data |
||
225 | * @param string $token |
||
226 | * @return bool |
||
227 | * @throws SdkException |
||
228 | */ |
||
229 | 4 | private function requestAction($action, $data, $token) |
|
234 | } |
||
235 |
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.