Conditions | 26 |
Paths | 4097 |
Total Lines | 94 |
Code Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
228 | protected function createElement (\DOMDocument $doc, array $properties = array()): \DOMElement |
||
229 | { |
||
230 | /* @var $el \DOMElement */ |
||
231 | $el = $doc->createElement(CDA::getNS() . $this->getElementTag()); |
||
232 | if ($this->hasNullFlavour()) |
||
233 | { |
||
234 | $el->setAttribute(CDA::getNS() . 'nullFlavor', $this->getNullFlavour()); |
||
235 | return $el; |
||
236 | } |
||
237 | |||
238 | // tag can have class code or type code, but not both. |
||
239 | // can have a class code and a mood code, but not type code and mood code |
||
240 | /** @noinspection PhpUndefinedMethodInspection */ |
||
241 | if ($this instanceof ClassCodeInterface |
||
242 | && $this->hasClassCode()) |
||
243 | { |
||
244 | $el->setAttribute(CDA::getNS() . 'classCode', $this->getClassCode()); |
||
245 | /** @noinspection PhpUndefinedMethodInspection */ |
||
246 | if ($this instanceof MoodCodeInterface |
||
247 | && $this->hasMoodCode()) |
||
248 | { |
||
249 | $el->setAttribute(CDA::getNS() . 'moodCode', $this->getMoodCode()); |
||
250 | } |
||
251 | } |
||
252 | /** @noinspection PhpUndefinedMethodInspection */ |
||
253 | elseif ($this instanceof TypeCodeInterface && $this->hasTypeCode()) |
||
254 | { |
||
255 | $el->setAttribute(CDA::getNS() . 'typeCode', $this->getTypeCode()); |
||
256 | } |
||
257 | |||
258 | if ($this instanceof DeterminerCodeInterface |
||
259 | && FALSE === empty($this->getDeterminerCode())) |
||
260 | { |
||
261 | $el->setAttribute(CDA::getNS() . 'determinerCode', $this->getDeterminerCode()); |
||
262 | } |
||
263 | |||
264 | if ($this instanceof MediaTypeInterface && $this->getMediaType()) |
||
265 | { |
||
266 | $el->setAttribute(CDA::getNS() . 'mediaType', $this->getMediaType()); |
||
267 | } |
||
268 | |||
269 | if ($this instanceof InversionIndInterface |
||
270 | && $this->hasInversionInd()) |
||
271 | { |
||
272 | $negationInd = new Boolean('inversionInd', $this->getInversionInd()); |
||
273 | $negationInd->setValueToElement($el, $doc); |
||
274 | } |
||
275 | |||
276 | if ($this instanceof ContextConductionIndInterface |
||
277 | && $this->hasContextConductionInd()) |
||
278 | { |
||
279 | $negationInd = new Boolean('contextConductionInd', $this->getContextConductionInd()); |
||
280 | $negationInd->setValueToElement($el, $doc); |
||
281 | } |
||
282 | |||
283 | if ($this instanceof NegationInterface |
||
284 | && $this->hasNegationInd()) |
||
285 | { |
||
286 | $negationInd = new Boolean('negationInd', $this->getNegationInd()); |
||
287 | $negationInd->setValueToElement($el, $doc); |
||
288 | } |
||
289 | if ($this instanceof UseAttributeInterface |
||
290 | && FALSE === empty($this->getUseAttribute())) |
||
291 | { |
||
292 | $el->setAttribute(CDA::getNS() . 'use', $this->getUseAttribute()); |
||
293 | } |
||
294 | |||
295 | if ($this instanceof ContextControlCodeInterface |
||
296 | && FALSE === empty($this->getContextControlCode())) |
||
297 | { |
||
298 | |||
299 | $el->setAttribute(CDA::getNS() . 'contextControlCode', $this->getContextControlCode()); |
||
300 | } |
||
301 | if ($this instanceof XSITypeInterface |
||
302 | && FALSE === empty($this->getXSIType())) |
||
303 | { |
||
304 | $el->setAttribute(CDA::getNS() . 'xsi:type', $this->getXSIType()); |
||
305 | } |
||
306 | |||
307 | foreach ($properties as $property) |
||
308 | { |
||
309 | $this->{$property}->setValueToElement($el, $doc); |
||
310 | } |
||
311 | |||
312 | foreach ($this->attributes as $attribute => $value) |
||
313 | { |
||
314 | $el->setAttribute($attribute, $value); |
||
315 | } |
||
316 | // attributes have finished, now start adding the elements. |
||
317 | // realm codes are used to store data like the organisation/country etc this tag conforms to. |
||
318 | $this->renderRealmCodes($el, $doc) |
||
319 | ->renderTypeId($el, $doc) |
||
320 | ->renderTemplateIds($el, $doc); |
||
321 | return $el; |
||
322 | } |
||
332 |