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 |
||
45 | class Act extends AbstractElement implements HasClassCode, HasMoodCodeInterface |
||
46 | { |
||
47 | /** |
||
48 | * A unique identifier for the Act. |
||
49 | * |
||
50 | * @var Set |
||
51 | */ |
||
52 | protected $ids; |
||
53 | |||
54 | /** |
||
55 | * |
||
56 | * @var CodedValue |
||
57 | */ |
||
58 | protected $code; |
||
59 | |||
60 | /** |
||
61 | * |
||
62 | * @var Boolean |
||
63 | */ |
||
64 | protected $negationInd; |
||
65 | |||
66 | /** |
||
67 | * |
||
68 | * @var EncapsuledData |
||
69 | */ |
||
70 | protected $text; |
||
71 | |||
72 | /** |
||
73 | * |
||
74 | * @var StatusCode |
||
75 | */ |
||
76 | protected $statusCode; |
||
77 | |||
78 | protected $effectiveTime = array(); |
||
79 | |||
80 | /** |
||
81 | * |
||
82 | * @var array |
||
83 | */ |
||
84 | protected $templateIds; |
||
85 | |||
86 | protected $moodCode = 'EVN'; |
||
87 | |||
88 | |||
89 | public function getIds() |
||
93 | |||
94 | public function getCode() |
||
98 | |||
99 | public function getNegationInd(): Boolean |
||
103 | |||
104 | public function getText() |
||
108 | |||
109 | public function getStatusCode() |
||
113 | |||
114 | public function getEffectiveTime() |
||
118 | |||
119 | public function getTemplateIds() |
||
123 | |||
124 | |||
125 | public function setIds(Set $ids) |
||
130 | |||
131 | public function setCode(CodedValue $code) |
||
137 | |||
138 | public function setNegationInd(Boolean $negationInd) |
||
143 | |||
144 | public function setText(EncapsuledData $text) |
||
149 | |||
150 | public function setStatusCode(StatusCode $statusCode) |
||
155 | |||
156 | public function setEffectiveTime($effectiveTime, $append = true) |
||
166 | |||
167 | /** |
||
168 | * |
||
169 | * @param InstanceIdentifier[] $templateIds |
||
170 | * @return $this |
||
171 | */ |
||
172 | View Code Duplication | public function setTemplateIds(array $templateIds) |
|
193 | |||
194 | public function addTemplateId(InstanceIdentifier $id) |
||
200 | |||
201 | public function getClassCode(): string |
||
205 | |||
206 | public function getMoodCode() |
||
210 | |||
211 | protected function getElementTag(): string |
||
215 | |||
216 | public function toDOMElement(\DOMDocument $doc): \DOMElement |
||
236 | |||
237 | } |
||
238 |
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.