Conditions | 26 |
Paths | 4097 |
Total Lines | 79 |
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 |
||
217 | protected function createElement(\DOMDocument $doc, array $properties = array()): \DOMElement |
||
218 | { |
||
219 | /* @var $el \DOMElement */ |
||
220 | $el = $doc->createElement(CDA::NS_CDA . $this->getElementTag()); |
||
221 | if ($this->hasNullFlavour()) { |
||
222 | $el->setAttribute(CDA::NS_CDA . 'nullFlavor', $this->getNullFlavour()); |
||
223 | return $el; |
||
224 | } |
||
225 | |||
226 | // tag can have class code or type code, but not both. |
||
227 | // can have a class code and a mood code, but not type code and mood code |
||
228 | /** @noinspection PhpUndefinedMethodInspection */ |
||
229 | if ($this instanceof ClassCodeInterface |
||
230 | && $this->hasClassCode()) { |
||
231 | $el->setAttribute(CDA::NS_CDA . 'classCode', $this->getClassCode()); |
||
232 | /** @noinspection PhpUndefinedMethodInspection */ |
||
233 | if ($this instanceof MoodCodeInterface |
||
234 | && $this->hasMoodCode()) { |
||
235 | $el->setAttribute(CDA::NS_CDA . 'moodCode', $this->getMoodCode()); |
||
236 | } |
||
237 | } /** @noinspection PhpUndefinedMethodInspection */ |
||
238 | elseif ($this instanceof TypeCodeInterface && $this->hasTypeCode()) { |
||
239 | $el->setAttribute(CDA::NS_CDA . 'typeCode', $this->getTypeCode()); |
||
240 | } |
||
241 | |||
242 | if ($this instanceof DeterminerCodeInterface |
||
243 | && false === empty($this->getDeterminerCode())) { |
||
244 | $el->setAttribute(CDA::NS_CDA . 'determinerCode', $this->getDeterminerCode()); |
||
245 | } |
||
246 | |||
247 | if ($this instanceof MediaTypeInterface && $this->getMediaType()) { |
||
248 | $el->setAttribute(CDA::NS_CDA . 'mediaType', $this->getMediaType()); |
||
249 | } |
||
250 | |||
251 | if ($this instanceof InversionIndInterface |
||
252 | && $this->hasInversionInd()) { |
||
253 | $negationInd = new Boolean('inversionInd', $this->getInversionInd()); |
||
254 | $negationInd->setValueToElement($el, $doc); |
||
255 | } |
||
256 | |||
257 | if ($this instanceof ContextConductionIndInterface |
||
258 | && $this->hasContextConductionInd()) { |
||
259 | $negationInd = new Boolean('contextConductionInd', $this->getContextConductionInd()); |
||
260 | $negationInd->setValueToElement($el, $doc); |
||
261 | } |
||
262 | |||
263 | if ($this instanceof NegationInterface |
||
264 | && $this->hasNegationInd()) { |
||
265 | $negationInd = new Boolean('negationInd', $this->getNegationInd()); |
||
266 | $negationInd->setValueToElement($el, $doc); |
||
267 | } |
||
268 | if ($this instanceof UseAttributeInterface |
||
269 | && false === empty($this->getUseAttribute())) { |
||
270 | $el->setAttribute(CDA::NS_CDA . 'use', $this->getUseAttribute()); |
||
271 | } |
||
272 | |||
273 | if ($this instanceof ContextControlCodeInterface |
||
274 | && false === empty($this->getContextControlCode())) { |
||
275 | |||
276 | $el->setAttribute(CDA::NS_CDA . 'contextControlCode', $this->getContextControlCode()); |
||
277 | } |
||
278 | if ($this instanceof XSITypeInterface |
||
279 | && false === empty($this->getXSIType())) { |
||
280 | $el->setAttribute(CDA::NS_CDA . 'xsi:type', $this->getXSIType()); |
||
281 | } |
||
282 | |||
283 | foreach ($properties as $property) { |
||
284 | $this->{$property}->setValueToElement($el, $doc); |
||
285 | } |
||
286 | |||
287 | foreach ($this->attributes as $attribute => $value) { |
||
288 | $el->setAttribute($attribute, $value); |
||
289 | } |
||
290 | // attributes have finished, now start adding the elements. |
||
291 | // realm codes are used to store data like the organisation/country etc this tag conforms to. |
||
292 | $this->renderRealmCodes($el, $doc) |
||
293 | ->renderTypeId($el, $doc) |
||
294 | ->renderTemplateIds($el, $doc); |
||
295 | return $el; |
||
296 | } |
||
306 |