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 |
||
13 | class AccessPointCOD implements NodeInterface |
||
14 | { |
||
15 | |||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | private $currencyCode; |
||
20 | |||
21 | /** |
||
22 | * @var float |
||
23 | */ |
||
24 | private $monetaryValue; |
||
25 | |||
26 | /** |
||
27 | * @param \stdClass|null $response |
||
28 | */ |
||
29 | View Code Duplication | public function __construct(\stdClass $response = null) |
|
40 | |||
41 | /** |
||
42 | * @param null|DOMDocument $document |
||
43 | * |
||
44 | * @return DOMElement |
||
45 | */ |
||
46 | View Code Duplication | public function toNode(DOMDocument $document = null) |
|
59 | |||
60 | /** |
||
61 | * @return string |
||
62 | */ |
||
63 | public function getCurrencyCode() |
||
67 | |||
68 | /** |
||
69 | * @param string $currencyCode |
||
70 | */ |
||
71 | public function setCurrencyCode($currencyCode) |
||
75 | |||
76 | /** |
||
77 | * @return float |
||
78 | */ |
||
79 | public function getMonetaryValue() |
||
83 | |||
84 | /** |
||
85 | * @param float $monetaryValue |
||
86 | */ |
||
87 | public function setMonetaryValue($monetaryValue) |
||
91 | } |
||
92 |
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.