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 |
||
9 | class POA implements NodeInterface |
||
10 | { |
||
11 | const POA_ONE_TIME = '1'; // One Time POA |
||
12 | const POA_BLANKET = '2'; // Blanket POA |
||
13 | |||
14 | /** |
||
15 | * @var string |
||
16 | */ |
||
17 | private $code; |
||
18 | |||
19 | /** |
||
20 | * @var string |
||
21 | */ |
||
22 | private $description; |
||
23 | |||
24 | /** |
||
25 | * @param null|object $attributes |
||
26 | */ |
||
27 | View Code Duplication | public function __construct($attributes = null) |
|
38 | |||
39 | /** |
||
40 | * @param null|DOMDocument $document |
||
41 | * |
||
42 | * @return DOMElement |
||
43 | */ |
||
44 | View Code Duplication | public function toNode(DOMDocument $document = null) |
|
64 | |||
65 | /** |
||
66 | * @return string |
||
67 | */ |
||
68 | public function getCode() |
||
72 | |||
73 | /** |
||
74 | * @param string $code |
||
75 | * |
||
76 | * @return $this |
||
77 | */ |
||
78 | public function setCode($code) |
||
84 | |||
85 | /** |
||
86 | * @return string |
||
87 | */ |
||
88 | public function getDescription() |
||
92 | |||
93 | /** |
||
94 | * @param string $description |
||
95 | * |
||
96 | * @return $this |
||
97 | */ |
||
98 | public function setDescription($description) |
||
104 | } |
||
105 |
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.