Completed
Push — master ( 5894ae...4ef642 )
by Julien
02:50
created

SubstanceAdministration::toDOMElement()   D

Complexity

Conditions 10
Paths 192

Size

Total Lines 45
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 45
rs 4.606
c 0
b 0
f 0
cc 10
eloc 24
nc 192
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
 * 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 NONINFRINGEMENT. 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
namespace PHPHealth\CDA\RIM\Act;
26
27
use PHPHealth\CDA\DataType\Code\CodedWithEquivalents;
28
use PHPHealth\CDA\DataType\Collection\Set;
29
use PHPHealth\CDA\DataType\Collection\Interval;
30
use PHPHealth\CDA\DataType\Quantity\PhysicalQuantity\PhysicalQuantity;
31
use PHPHealth\CDA\Elements\TemplateId;
32
use PHPHealth\CDA\Elements\Text;
33
use PHPHealth\CDA\Elements\EffectiveTime;
34
use PHPHealth\CDA\Elements\RouteCode;
35
use PHPHealth\CDA\RIM\Participation\Consumable;
36
use PHPHealth\CDA\Elements\DoseQuantity;
37
38
/**
39
 * 
40
 *
41
 * @author Julien Fastré <[email protected]>
42
 */
43
class SubstanceAdministration extends Act
44
{
45
    /**
46
     *
47
     * @var CodedWithEquivalents
48
     */
49
    private $routeCode;
50
    
51
    /**
52
     *
53
     * @var Set|CodedWithEquivalents
54
     */
55
    private $approachSiteCode;
56
    
57
    /**
58
     *
59
     * @var Interval|PhysicalQuantity
60
     */
61
    private $doseQuantity;
62
    
63
    /**
64
     *
65
     * @var Interval|PhysicalQuantity
66
     */
67
    private $rateQuantity;
68
    
69
    /**
70
     *
71
     * @var Consumable 
72
     */
73
    private $consumable;
74
    
75
    private $frequencyOfAdministration;
76
    
77
    
78
    public function getClassCode(): string
79
    {
80
        return 'SBADM';
81
    }
82
83
    protected function getElementTag(): string
84
    {
85
        return 'substanceAdministration';
86
    }
87
    
88
    /**
89
     * 
90
     * @return CodedWithEquivalents
91
     */
92
    public function getRouteCode(): CodedWithEquivalents
93
    {
94
        return $this->routeCode;
95
    }
96
97
    /**
98
     * 
99
     * @return Set|CodedWithEquivalents
100
     */
101
    public function getApproachSiteCode()
102
    {
103
        return $this->approachSiteCode;
104
    }
105
106
    /**
107
     * 
108
     * @return Interval|PhysicalQuantity
109
     */
110
    public function getDoseQuantity()
111
    {
112
        return $this->doseQuantity;
113
    }
114
115
    /**
116
     * 
117
     * @return Interval|PhysicalQuantity
118
     */
119
    public function getRateQuantity()
120
    {
121
        return $this->rateQuantity;
122
    }
123
    
124
    public function getTimeOfAdministration()
125
    {
126
        return parent::getEffectiveTime();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (getEffectiveTime() instead of getTimeOfAdministration()). Are you sure this is correct? If so, you might want to change this to $this->getEffectiveTime().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
127
    }
128
    
129
    public function getFrequencyOfAdministration()
130
    {
131
        return $this->frequencyOfAdministration;
132
    }
133
    
134
    /**
135
     * 
136
     * @return Consumable
137
     */
138
    public function getConsumable()
139
    {
140
        return $this->consumable;
141
    }
142
143
    /**
144
     * 
145
     * @param CodedWithEquivalents $routeCode
146
     * @return $this
147
     */
148
    public function setRouteCode(CodedWithEquivalents $routeCode)
149
    {
150
        $this->routeCode = $routeCode;
151
        return $this;
152
    }
153
154
    /**
155
     * 
156
     * @param Set|CodedWithEquivalents $approachSiteCode
157
     * @return $this
158
     */
159
    public function setApproachSiteCode($approachSiteCode)
160
    {
161
        $this->approachSiteCode = $approachSiteCode;
162
        return $this;
163
    }
164
165
    /**
166
     * 
167
     * @param Interval|PhysicalQuantity $doseQuantity
168
     * @return $this
169
     */
170
    public function setDoseQuantity($doseQuantity)
171
    {
172
        $this->doseQuantity = $doseQuantity;
173
        return $this;
174
    }
175
176
    /**
177
     * 
178
     * @param Interval|PhysicalQuantity $rateQuantity
179
     * @return $this
180
     */
181
    public function setRateQuantity($rateQuantity)
182
    {
183
        $this->rateQuantity = $rateQuantity;
184
        return $this;
185
    }
186
    
187
    public function setTimeOfAdministration($time)
0 ignored issues
show
Unused Code introduced by
The parameter $time is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
188
    {
189
        return parent::setEffectiveTime($effectiveTime);
0 ignored issues
show
Bug introduced by
The variable $effectiveTime does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Comprehensibility Bug introduced by
It seems like you call parent on a different method (setEffectiveTime() instead of setTimeOfAdministration()). Are you sure this is correct? If so, you might want to change this to $this->setEffectiveTime().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
190
    }
191
    
192
    public function setFrequencyOfAdministration($frequency)
193
    {
194
        $this->frequencyOfAdministration = $frequency;
195
        
196
        return $this;
197
    }
198
199
    /**
200
     * 
201
     * @param Consumable $consumable
202
     * @return $this
203
     */
204
    function setConsumable(Consumable $consumable)
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
205
    {
206
        $this->consumable = $consumable;
207
        return $this;
208
    }
209
        
210
    public function toDOMElement(\DOMDocument $doc): \DOMElement
211
    {
212
        $el = $this->createElement($doc);
213
        
214
        if ($this->getTemplateIds() !== null) {
215
            foreach ($this->templateIds as $id) {
216
                $el->appendChild((new TemplateId($id))->toDOMElement($doc));
217
            }
218
        }
219
        
220
        if ($this->getText() !== null) {
221
            $el->appendChild((new Text($this->getText()))->toDOMElement($doc));
0 ignored issues
show
Compatibility introduced by
$this->getText() of type object<PHPHealth\CDA\Dat...timedia\EncapsuledData> is not a sub-type of object<PHPHealth\CDA\Dat...imedia\CharacterString>. It seems like you assume a child class of the class PHPHealth\CDA\DataType\T...ltimedia\EncapsuledData to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
222
        }
223
        
224
        if ($this->getTimeOfAdministration() !== null) {
225
            $el->appendChild((new EffectiveTime($this->getTimeOfAdministration()))
226
                ->toDOMElement($doc));
227
        }
228
        
229
        if ($this->getFrequencyOfAdministration() !== null) {
230
            $effectiveTime = new EffectiveTime($this->getFrequencyOfAdministration());
231
            
232
            if ($this->getTimeOfAdministration() !== null) {
233
                $effectiveTime->setOperatorAppend();
234
            }
235
            
236
            $el->appendChild($effectiveTime->toDOMElement($doc));
237
        }
238
        
239
        if ($this->getRouteCode() !== null) {
240
            $el->appendChild((new RouteCode($this->getRouteCode()))
241
                ->toDOMElement($doc));
242
        }
243
        
244
        if ($this->getDoseQuantity() !== null) {
245
            $el->appendChild((new DoseQuantity($this->getDoseQuantity()))
246
                ->toDOMElement($doc));
247
        }
248
        
249
        if ($this->getConsumable() !== null) {
250
            $el->appendChild($this->getConsumable()->toDOMElement($doc));
251
        }
252
        
253
        return $el;
254
    }
255
256
}
257