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 |
||
15 | trait CancelTrait |
||
16 | { |
||
17 | /** |
||
18 | * Validates and returns the formated amount. |
||
19 | * |
||
20 | * @throws InvalidRequestException on any validation failure. |
||
21 | * |
||
22 | * @return string The amount formatted to the correct number of decimal places for the selected currency. |
||
23 | * |
||
24 | * @codeCoverageIgnore |
||
25 | */ |
||
26 | abstract public function getAmount(); |
||
27 | |||
28 | /** |
||
29 | * Get the payment currency code. |
||
30 | * |
||
31 | * @return string |
||
32 | * |
||
33 | * @codeCoverageIgnore |
||
34 | */ |
||
35 | abstract public function getCurrency(); |
||
36 | |||
37 | /** |
||
38 | * Get the transaction ID. |
||
39 | * |
||
40 | * The transaction ID is the identifier generated by the merchant website. |
||
41 | * |
||
42 | * @return string |
||
43 | * |
||
44 | * @codeCoverageIgnore |
||
45 | */ |
||
46 | abstract public function getTransactionId(); |
||
47 | |||
48 | /** |
||
49 | * Appends the rate request node to the SimpleXMLElement. |
||
50 | * |
||
51 | * @param SimpleXMLElement $data |
||
52 | * |
||
53 | * @throws InvalidRequestException |
||
54 | */ |
||
55 | 2 | View Code Duplication | protected function appendCancel(SimpleXMLElement $data) |
62 | } |
||
63 |
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.