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 SubstanceAdministration extends Act |
||
46 | { |
||
47 | /** |
||
48 | * |
||
49 | * @var CodedWithEquivalents |
||
50 | */ |
||
51 | private $routeCode; |
||
52 | |||
53 | /** |
||
54 | * |
||
55 | * @var Set|CodedWithEquivalents |
||
56 | */ |
||
57 | private $approachSiteCode; |
||
58 | |||
59 | /** |
||
60 | * |
||
61 | * @var Interval|PhysicalQuantity |
||
62 | */ |
||
63 | private $doseQuantity; |
||
64 | |||
65 | /** |
||
66 | * |
||
67 | * @var Interval|PhysicalQuantity |
||
68 | */ |
||
69 | private $rateQuantity; |
||
70 | |||
71 | /** |
||
72 | * |
||
73 | * @var Consumable |
||
74 | */ |
||
75 | private $consumable; |
||
76 | |||
77 | |||
78 | public function getClassCode(): string |
||
82 | |||
83 | protected function getElementTag(): string |
||
87 | |||
88 | /** |
||
89 | * |
||
90 | * @return CodedWithEquivalents |
||
91 | */ |
||
92 | public function getRouteCode(): CodedWithEquivalents |
||
96 | |||
97 | /** |
||
98 | * |
||
99 | * @return Set|CodedWithEquivalents |
||
100 | */ |
||
101 | public function getApproachSiteCode() |
||
105 | |||
106 | /** |
||
107 | * |
||
108 | * @return Interval|PhysicalQuantity |
||
109 | */ |
||
110 | public function getDoseQuantity() |
||
114 | |||
115 | /** |
||
116 | * |
||
117 | * @return Interval|PhysicalQuantity |
||
118 | */ |
||
119 | public function getRateQuantity() |
||
123 | |||
124 | /** |
||
125 | * |
||
126 | * @return Consumable |
||
127 | */ |
||
128 | public function getConsumable() |
||
132 | |||
133 | /** |
||
134 | * |
||
135 | * @param CodedWithEquivalents $routeCode |
||
136 | * @return $this |
||
137 | */ |
||
138 | public function setRouteCode(CodedWithEquivalents $routeCode) |
||
143 | |||
144 | /** |
||
145 | * |
||
146 | * @param Set|CodedWithEquivalents $approachSiteCode |
||
147 | * @return $this |
||
148 | */ |
||
149 | public function setApproachSiteCode($approachSiteCode) |
||
154 | |||
155 | /** |
||
156 | * |
||
157 | * @param Interval|PhysicalQuantity $doseQuantity |
||
158 | * @return $this |
||
159 | */ |
||
160 | public function setDoseQuantity($doseQuantity) |
||
165 | |||
166 | /** |
||
167 | * |
||
168 | * @param Interval|PhysicalQuantity $rateQuantity |
||
169 | * @return $this |
||
170 | */ |
||
171 | public function setRateQuantity($rateQuantity) |
||
176 | |||
177 | |||
178 | |||
179 | /** |
||
180 | * |
||
181 | * @param Consumable $consumable |
||
182 | * @return $this |
||
183 | */ |
||
184 | function setConsumable(Consumable $consumable) |
||
189 | |||
190 | public function toDOMElement(\DOMDocument $doc): \DOMElement |
||
249 | |||
250 | } |
||
251 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.