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 |
||
10 | class CaptureReservation extends Response |
||
11 | { |
||
12 | use ResultTrait; |
||
13 | use TransactionsTrait; |
||
14 | |||
15 | /** |
||
16 | * @var Money |
||
17 | */ |
||
18 | protected $captureAmount; |
||
19 | |||
20 | /** |
||
21 | * @var int |
||
22 | */ |
||
23 | protected $captureCurrency; |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $captureResult; |
||
29 | |||
30 | /** |
||
31 | * @var Transaction[] |
||
32 | */ |
||
33 | protected $transactions; |
||
34 | |||
35 | /** |
||
36 | * @return Money |
||
37 | */ |
||
38 | 3 | public function getCaptureAmount() : Money |
|
42 | |||
43 | /** |
||
44 | * @return int |
||
45 | */ |
||
46 | 3 | public function getCaptureCurrency() : int |
|
50 | |||
51 | /** |
||
52 | * @deprecated According to AltaPay documentation this is deprecated, |
||
53 | * @see https://testgateway.altapaysecure.com/merchant/help/Merchant_API#API_captureReservation |
||
54 | * @return string |
||
55 | */ |
||
56 | 3 | public function getCaptureResult() : string |
|
60 | |||
61 | /** |
||
62 | * @return Transaction[] |
||
63 | */ |
||
64 | 3 | public function getTransactions() : array |
|
68 | |||
69 | 6 | View Code Duplication | protected function init() |
84 | } |
||
85 |
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.