Total Complexity | 49 |
Total Lines | 268 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like AbstractElement often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AbstractElement, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
62 | abstract class AbstractElement implements ElementInterface, NullFlavourInterface |
||
63 | { |
||
64 | use NullFlavourTrait; |
||
65 | use RealmCodesTrait; |
||
66 | use TypeIdTrait; |
||
67 | use TemplateIdsTrait; |
||
68 | |||
69 | /** |
||
70 | * @var array |
||
71 | */ |
||
72 | protected $attributes = array(); |
||
73 | |||
74 | /** |
||
75 | * this is a total hack to add non-commonly used attributes. |
||
76 | * don't use it lazy bones! |
||
77 | * |
||
78 | * @param $attribute |
||
79 | * @param $value |
||
80 | * |
||
81 | * @return AbstractElement |
||
82 | * @deprecated |
||
83 | */ |
||
84 | public function addAttribute ($attribute, $value): self |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * @return TargetSiteCode |
||
92 | */ |
||
93 | public function returnTargetSiteCode (): TargetSiteCode |
||
94 | { |
||
95 | if ($this instanceof TargetSiteCode) |
||
96 | { |
||
97 | return $this; |
||
98 | } |
||
99 | throw new \RuntimeException('The method must be an instance of TargetSiteCode'); |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * @return Observation |
||
104 | */ |
||
105 | public function returnObservation (): Observation |
||
106 | { |
||
107 | if ($this instanceof Observation) |
||
108 | { |
||
109 | return $this; |
||
110 | } |
||
111 | throw new \RuntimeException('The method must be an instance of Observation'); |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * @return SubstanceAdministration |
||
116 | */ |
||
117 | public function returnSubstanceAdministration (): SubstanceAdministration |
||
118 | { |
||
119 | if ($this instanceof SubstanceAdministration) |
||
120 | { |
||
121 | return $this; |
||
122 | } |
||
123 | throw new \RuntimeException('The method must be an instance of SubstanceAdministration'); |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * @return SpecimenRole |
||
128 | */ |
||
129 | public function returnSpecimenRole (): SpecimenRole |
||
130 | { |
||
131 | if ($this instanceof SpecimenRole) |
||
132 | { |
||
133 | return $this; |
||
134 | } |
||
135 | throw new \RuntimeException('The method must be an instance of SpecimenRole'); |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * @return ManufacturedProduct |
||
140 | */ |
||
141 | public function returnManufacturedProduct (): ManufacturedProduct |
||
148 | } |
||
149 | |||
150 | /** |
||
151 | * @return SpecimenPlayingEntity |
||
152 | */ |
||
153 | public function returnSpecimenPlayingEntity (): SpecimenPlayingEntity |
||
154 | { |
||
155 | if ($this instanceof SpecimenPlayingEntity) |
||
156 | { |
||
157 | return $this; |
||
158 | } |
||
159 | throw new \RuntimeException('The method must be an instance of SpecimenPlayingEntity'); |
||
160 | } |
||
161 | |||
162 | /** |
||
163 | * @return Consumable |
||
164 | */ |
||
165 | public function returnConsumable (): Consumable |
||
166 | { |
||
167 | if ($this instanceof Consumable) |
||
168 | { |
||
169 | return $this; |
||
170 | } |
||
171 | throw new \RuntimeException('The method must be an instance of Consumable'); |
||
172 | } |
||
173 | |||
174 | /** |
||
175 | * @return Performer |
||
176 | */ |
||
177 | public function returnPerformer (): Performer |
||
178 | { |
||
179 | if ($this instanceof Performer) |
||
180 | { |
||
181 | return $this; |
||
182 | } |
||
183 | throw new \RuntimeException('The method must be an instance of Performer'); |
||
184 | } |
||
185 | |||
186 | /** |
||
187 | * @return AssignedPerson |
||
188 | */ |
||
189 | public function returnAssignedPerson (): AssignedPerson |
||
190 | { |
||
191 | if ($this instanceof AssignedPerson) |
||
192 | { |
||
193 | return $this; |
||
194 | } |
||
195 | throw new \RuntimeException('The method must be an instance of AssignedPerson'); |
||
196 | } |
||
197 | |||
198 | /** |
||
199 | * @return ExtParticipantRole |
||
200 | */ |
||
201 | public function returnExtParticipantRole (): ExtParticipantRole |
||
202 | { |
||
203 | if ($this instanceof ExtParticipantRole) |
||
204 | { |
||
205 | return $this; |
||
206 | } |
||
207 | throw new \RuntimeException('The method must be an instance of ExtParticipantRole'); |
||
208 | } |
||
209 | |||
210 | /** |
||
211 | * @return Supply |
||
212 | */ |
||
213 | public function returnSupply (): Supply |
||
214 | { |
||
215 | if ($this instanceof Supply) |
||
216 | { |
||
217 | return $this; |
||
218 | } |
||
219 | throw new \RuntimeException('The method must be an instance of Supply'); |
||
220 | } |
||
221 | |||
222 | /** |
||
223 | * @param \DOMDocument $doc |
||
224 | * @param array $properties |
||
225 | * |
||
226 | * @return \DOMElement |
||
227 | */ |
||
228 | protected function createElement (\DOMDocument $doc, array $properties = array()): \DOMElement |
||
322 | } |
||
323 | |||
324 | /** |
||
325 | * get the element tag name |
||
326 | * |
||
327 | * @return string |
||
328 | */ |
||
329 | abstract protected function getElementTag (): string; |
||
330 | |||
332 |