Passed
Push — master ( 26e0e4...4a85b9 )
by Peter
10:37
created

Entry::toDOMElement()   B

Complexity

Conditions 10
Paths 10

Size

Total Lines 25
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 21
nc 10
nop 1
dl 0
loc 25
rs 7.6666
c 0
b 0
f 0

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
 * The MIT License
4
 *
5
 * Copyright 2017 Julien Fastré <[email protected]>.
6
 *
7
 * Permission is hereby granted, free of charge, to any person obtaining a copy
8
 * of this software and associated documentation files (the "Software"), to deal
9
 * in the Software without restriction, including without limitation the rights
10
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
 * copies of the Software, and to permit persons to whom the Software is
12
 * furnished to do so, subject to the following conditions:
13
 *
14
 * The above copyright notice and this permission notice shall be included in
15
 * all copies or substantial portions of the Software.
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE
20
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
 * THE SOFTWARE.
24
 */
25
26
namespace i3Soft\CDA\Elements;
27
28
use i3Soft\CDA\Interfaces\TypeCodeInterface;
29
use i3Soft\CDA\RIM\Act\Act;
30
use i3Soft\CDA\RIM\Act\Encounter;
31
use i3Soft\CDA\RIM\Act\Observation;
32
use i3Soft\CDA\RIM\Act\SubstanceAdministration;
33
use i3Soft\CDA\Traits\ActTrait;
34
use i3Soft\CDA\Traits\ContextConductionIndTrait;
35
use i3Soft\CDA\Traits\EncounterTrait;
36
use i3Soft\CDA\Traits\IdsTrait;
37
use i3Soft\CDA\Traits\ObservationMediaTrait;
38
use i3Soft\CDA\Traits\ObservationTrait;
39
use i3Soft\CDA\Traits\OrganizerTrait;
40
use i3Soft\CDA\Traits\ProcedureTrait;
41
use i3Soft\CDA\Traits\RegionOfInterestTrait;
42
use i3Soft\CDA\Traits\SubstanceAdministrationTrait;
43
use i3Soft\CDA\Traits\SupplyTrait;
44
use i3Soft\CDA\Traits\TypeCodeTrait;
45
46
/**
47
 * Class Entry
48
 *
49
 * @package i3Soft\CDA\Elements
50
 */
51
class Entry extends AbstractElement implements TypeCodeInterface
52
{
53
54
    use IdsTrait;
55
    use ActTrait;
56
    use EncounterTrait;
57
    use ObservationTrait;
58
    use ObservationMediaTrait;
59
    use OrganizerTrait;
60
    use ProcedureTrait;
61
    use RegionOfInterestTrait;
62
    use SubstanceAdministrationTrait;
63
    use SupplyTrait;
64
    // <xs:element ref="ext:controlAct"/>
65
    use TypeCodeTrait;
66
    use ContextConductionIndTrait;
67
68
    /**
69
     * Entry constructor.
70
     *
71
     * @param null $choice
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $choice is correct as it would always require null to be passed?
Loading history...
72
     */
73
    public function __construct($choice = null)
74
    {
75
        $this->setAcceptableTypeCodes(TypeCodeInterface::x_ActRelationshipEntry)
76
          ->setTypeCode(TypeCodeInterface::COMPONENT);
77
        if ($choice instanceof Act) {
78
            $this->setAct($choice);
79
        } elseif ($choice instanceof Encounter) {
80
            $this->setEncounter($choice);
81
        } elseif ($choice instanceof Observation) {
82
            $this->setObservation($choice);
83
        } elseif ($choice instanceof Procedure) {
84
            $this->setProcedure($choice);
85
        } elseif ($choice instanceof SubstanceAdministration) {
86
            $this->setSubstanceAdministration($choice);
87
        }
88
89
    }
90
91
92
    /**
93
     * @param \DOMDocument $doc
94
     *
95
     * @return \DOMElement
96
     */
97
    public function toDOMElement(\DOMDocument $doc): \DOMElement
98
    {
99
        $el = $this->createElement($doc);
100
        $this->renderIds($el, $doc);
101
        if ($this->hasAct()) {
102
            $this->renderAct($el, $doc);
103
        } elseif ($this->hasEncounter()) {
104
            $this->renderEncounter($el, $doc);
105
        } elseif ($this->hasObservation()) {
106
            $this->renderObservation($el, $doc);
107
        } elseif ($this->hasObservationMedia()) {
108
            $this->renderObservationMedia($el, $doc);
109
        } elseif ($this->hasOrganizer()) {
110
            $this->renderOrganizer($el, $doc);
111
        } elseif ($this->hasProcedure()) {
112
            $this->renderProcedure($el, $doc);
113
        } elseif ($this->hasRegionOfInterest()) {
114
            $this->renderRegionOfInterest($el, $doc);
115
        } elseif ($this->hasSubstanceAdministration()) {
116
            $this->renderSubstanceAdministration($el, $doc);
117
        } elseif ($this->hasSupply()) {
118
            $this->renderSupply($el, $doc);
119
        }
120
121
        return $el;
122
    }
123
124
125
    /**
126
     * @return string
127
     */
128
    protected function getElementTag(): string
129
    {
130
        return 'entry';
131
    }
132
133
}
134