Act   A
last analyzed

Complexity

Total Complexity 26

Size/Duplication

Total Lines 193
Duplicated Lines 13.47 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
wmc 26
c 0
b 0
f 0
lcom 2
cbo 2
dl 26
loc 193
rs 10

19 Methods

Rating   Name   Duplication   Size   Complexity  
A getIds() 0 4 1
A getCode() 0 4 1
A getNegationInd() 0 4 1
A getText() 0 4 1
A getStatusCode() 0 4 1
A getEffectiveTime() 0 4 1
A getTemplateIds() 0 4 1
A setIds() 0 5 1
A setCode() 0 6 1
A setNegationInd() 0 5 1
A setText() 0 5 1
A setStatusCode() 0 5 1
A setEffectiveTime() 0 10 2
A setTemplateIds() 21 21 3
A addTemplateId() 0 6 1
A getClassCode() 0 4 1
A getMoodCode() 0 4 1
A getElementTag() 0 4 1
B toDOMElement() 5 20 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\Elements\AbstractElement;
28
use PHPHealth\CDA\HasClassCode;
29
use PHPHealth\CDA\HasMoodCodeInterface;
30
use PHPHealth\CDA\DataType\Collection\Set;
31
use PHPHealth\CDA\DataType\Code\CodedWithEquivalents;
32
use PHPHealth\CDA\DataType\Boolean\Boolean;
33
use PHPHealth\CDA\DataType\TextAndMultimedia\EncapsuledData;
34
use PHPHealth\CDA\DataType\Code\StatusCode;
35
use PHPHealth\CDA\DataType\Identifier\InstanceIdentifier;
36
use PHPHealth\CDA\Elements\Code;
37
use PHPHealth\CDA\DataType\Code\CodedValue;
38
39
/**
40
 * A record of something that is being done, has been done, can be done, 
41
 * or is intended or requested to be done.
42
 *
43
 * @author Julien Fastré <[email protected]>
44
 */
45
class Act extends AbstractElement implements HasClassCode, HasMoodCodeInterface
46
{
47
    /**
48
     * A unique identifier for the Act.
49
     *
50
     * @var Set
51
     */
52
    protected $ids;
53
    
54
    /**
55
     *
56
     * @var CodedValue
57
     */
58
    protected $code;
59
    
60
    /**
61
     *
62
     * @var Boolean
63
     */
64
    protected $negationInd;
65
    
66
    /**
67
     *
68
     * @var EncapsuledData
69
     */
70
    protected $text;
71
    
72
    /**
73
     *
74
     * @var StatusCode
75
     */
76
    protected $statusCode;
77
    
78
    protected $effectiveTime = array();
79
    
80
    /**
81
     *
82
     * @var array 
83
     */
84
    protected $templateIds;
85
    
86
    protected $moodCode = 'EVN';
87
    
88
    
89
    public function getIds()
90
    {
91
        return $this->ids;
92
    }
93
94
    public function getCode()
95
    {
96
        return $this->code;
97
    }
98
99
    public function getNegationInd(): Boolean
100
    {
101
        return $this->negationInd;
102
    }
103
104
    public function getText()
105
    {
106
        return $this->text;
107
    }
108
109
    public function getStatusCode()
110
    {
111
        return $this->statusCode;
112
    }
113
114
    public function getEffectiveTime()
115
    {
116
        return $this->effectiveTime;
117
    }
118
    
119
    public function getTemplateIds()
120
    {
121
        return $this->templateIds;
122
    }
123
124
    
125
    public function setIds(Set $ids)
126
    {
127
        $this->ids = $ids;
128
        return $this;
129
    }
130
131
    public function setCode(CodedValue $code)
132
    {
133
        $this->code = $code;
134
        
135
        return $this;
136
    }
137
138
    public function setNegationInd(Boolean $negationInd)
139
    {
140
        $this->negationInd = $negationInd;
141
        return $this;
142
    }
143
144
    public function setText(EncapsuledData $text)
145
    {
146
        $this->text = $text;
147
        return $this;
148
    }
149
150
    public function setStatusCode(StatusCode $statusCode)
151
    {
152
        $this->statusCode = $statusCode;
153
        return $this;
154
    }
155
156
    public function setEffectiveTime($effectiveTime, $append = true)
157
    {
158
        if ($append) {
159
            $this->effectiveTime[] = $effectiveTime;
160
        } else {
161
            $this->effectiveTime = array($effectiveTime);
162
        }
163
        
164
        return $this;
165
    }
166
167
    /**
168
     * 
169
     * @param InstanceIdentifier[] $templateIds
170
     * @return $this
171
     */
172 View Code Duplication
    public function setTemplateIds(array $templateIds)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
173
    {
174
        // check that each element is an instance of InstanceIdentifier
175
        $result = \array_reduce($templateIds, function ($carry, $current) {
176
            if ($carry === false) {
177
                return false;
178
            }
179
            
180
            return $current instanceof InstanceIdentifier;
181
        });
182
        
183
        if ($result === false) {
184
            throw new \RuntimeException(sprintf("the templateIds must be "
185
                . "instance of %s", InstanceIdentifier::class));
186
        }
187
        
188
        $this->templateIds = $templateIds;
189
        
190
        
191
        return $this;
192
    }
193
194
    public function addTemplateId(InstanceIdentifier $id)
195
    {
196
        $this->templateIds[] = $id;
197
        
198
        return $this;
199
    }
200
            
201
    public function getClassCode(): string
202
    {
203
        return 'ACT';
204
    }
205
    
206
    public function getMoodCode()
207
    {
208
        return $this->moodCode;
209
    }
210
211
    protected function getElementTag(): string
212
    {
213
        return 'act';
214
    }
215
216
    public function toDOMElement(\DOMDocument $doc): \DOMElement
217
    {
218
        $el = $this->createElement($doc);
219
        
220 View Code Duplication
        if ($this->getTemplateIds() !== null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
221
            foreach ($this->templateIds as $id) {
222
                $el->appendChild((new TemplateId($id))->toDOMElement($doc));
223
            }
224
        }
225
        
226
        if ($this->getText() !== null) {
227
            $el->appendChild((new Text($this->getText()))->toDOMElement($doc));
228
        }
229
        
230
        if ($this->getCode() !== null) {
231
            $el->appendChild((new Code($this->getCode()))->toDOMElement($doc));
232
        }
233
        
234
        return $el;
235
    }
236
237
}
238