OrganizerComponent::toDOMElement()   C
last analyzed

Complexity

Conditions 12
Paths 40

Size

Total Lines 49
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 49
rs 6.9666
c 0
b 0
f 0
cc 12
nc 40
nop 1

How to fix   Complexity   

Long Method

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:

1
<?php
2
3
/**
4
 * The MIT License
5
 *
6
 * Copyright 2018  Peter Gee <https://github.com/pgee70>.
7
 *
8
 * Permission is hereby granted, free of charge, to any person obtaining a copy
9
 * of this software and associated documentation files (the "Software"), to deal
10
 * in the Software without restriction, including without limitation the rights
11
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
 * copies of the Software, and to permit persons to whom the Software is
13
 * furnished to do so, subject to the following conditions:
14
 *
15
 * The above copyright notice and this permission notice shall be included in
16
 * all copies or substantial portions of the Software.
17
 *
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
21
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
 * THE SOFTWARE.
25
 */
26
27
/**
28
 *
29
 * @package     i3Soft\CDA
30
 * @author      Peter Gee <https://github.com/pgee70>
31
 * @link        https://github.com/pgee70/cda
32
 *
33
 */
34
35
36
namespace i3Soft\CDA\RIM\Act;
37
38
39
use i3Soft\CDA\Elements\AbstractElement;
40
use i3Soft\CDA\Elements\Procedure;
41
use i3Soft\CDA\Interfaces\ContextConductionIndInterface;
42
use i3Soft\CDA\Interfaces\TypeCodeInterface;
43
use i3Soft\CDA\Traits\ActTrait;
44
use i3Soft\CDA\Traits\ContextConductionIndTrait;
45
use i3Soft\CDA\Traits\EncounterTrait;
46
use i3Soft\CDA\Traits\ObservationMediaTrait;
47
use i3Soft\CDA\Traits\ObservationTrait;
48
use i3Soft\CDA\Traits\OrganizerTrait;
49
use i3Soft\CDA\Traits\ProcedureTrait;
50
use i3Soft\CDA\Traits\RegionOfInterestTrait;
51
use i3Soft\CDA\Traits\SeperatableIndTrait;
52
use i3Soft\CDA\Traits\SequenceNumberTrait;
53
use i3Soft\CDA\Traits\SubstanceAdministrationTrait;
54
use i3Soft\CDA\Traits\SupplyTrait;
55
use i3Soft\CDA\Traits\TypeCodeTrait;
56
57
class OrganizerComponent extends AbstractElement implements TypeCodeInterface, ContextConductionIndInterface
58
{
59
  use TypeCodeTrait;
60
  use ActTrait;
61
  use SequenceNumberTrait;
62
  use SeperatableIndTrait;
63
  use EncounterTrait;
64
  use ObservationTrait;
65
  use ObservationMediaTrait;
66
  use OrganizerTrait;
67
  use ProcedureTrait;
68
  use RegionOfInterestTrait;
69
  use SubstanceAdministrationTrait;
70
  use SupplyTrait;
71
  use ContextConductionIndTrait;
72
73
  public function __construct ($choice = NULL)
74
  {
75
    $this->setAcceptableTypeCodes(TypeCodeInterface::ActRelationshipHasComponent)
76
      ->setTypeCode('');
77
    if ($choice instanceOf Act)
78
    {
79
      $this->setAct($choice);
80
    }
81
    elseif ($choice instanceOf Encounter)
82
    {
83
      $this->setEncounter($choice);
84
    }
85
    elseif ($choice instanceOf Observation)
86
    {
87
      $this->setObservation($choice);
88
    }
89
    elseif ($choice instanceOf ObservationMedia)
90
    {
91
      $this->setObservationMedia($choice);
92
    }
93
    elseif ($choice instanceOf Organizer)
94
    {
95
      $this->setOrganizer($choice);
96
    }
97
    elseif ($choice instanceOf Procedure)
98
    {
99
      $this->setProcedure($choice);
100
    }
101
    elseif ($choice instanceOf SubstanceAdministration)
102
    {
103
      $this->setSubstanceAdministration($choice);
104
    }
105
  }
106
107
  /**
108
   * @inheritDoc
109
   */
110
  public function toDOMElement (\DOMDocument $doc): \DOMElement
111
  {
112
    $el = $this->createElement($doc);
113
    if ($this->hasSequenceNumber())
114
    {
115
      $el->appendChild($this->getSequenceNumber()->toDOMElement($doc));
116
    }
117
    if ($this->hasSeperatableInd())
118
    {
119
      $el->appendChild($this->getSeperatableInd()->toDOMElement($doc));
120
    }
121
    if ($this->hasAct())
122
    {
123
      $el->appendChild($this->getAct()->toDOMElement($doc));
124
    }
125
    elseif ($this->hasEncounter())
126
    {
127
      $el->appendChild($this->getEncounter()->toDOMElement($doc));
128
    }
129
    elseif ($this->hasObservation())
130
    {
131
      $el->appendChild($this->getObservation()->toDOMElement($doc));
132
    }
133
    elseif ($this->hasObservationMedia())
134
    {
135
      $el->appendChild($this->getObservationMedia()->toDOMElement($doc));
136
    }
137
    elseif ($this->hasOrganizer())
138
    {
139
      $el->appendChild($this->getOrganizer()->toDOMElement($doc));
140
    }
141
    elseif ($this->hasProcedure())
142
    {
143
      $el->appendChild($this->getProcedure()->toDOMElement($doc));
144
    }
145
    elseif ($this->hasRegionOfInterest())
146
    {
147
      $el->appendChild($this->getRegionOfInterest()->toDOMElement($doc));
148
    }
149
    elseif ($this->hasSubstanceAdministration())
150
    {
151
      $el->appendChild($this->getSubstanceAdministration()->toDOMElement($doc));
152
    }
153
    elseif ($this->hasSupply())
154
    {
155
      $el->appendChild($this->getSupply()->toDOMElement($doc));
156
    }
157
158
    return $el;
159
  }
160
161
162
  /**
163
   * @inheritDoc
164
   */
165
  protected function getElementTag (): string
166
  {
167
    return 'component';
168
  }
169
}