Completed
Push — master ( 9f6cfb...5894ae )
by Julien
04:19
created

Section::setCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
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\Component\SingleComponent;
26
27
use PHPHealth\CDA\Elements\AbstractElement;
28
use PHPHealth\CDA\HasClassCode;
29
use PHPHealth\CDA\Elements\TemplateId;
30
use PHPHealth\CDA\DataType\Identifier\InstanceIdentifier;
31
use PHPHealth\CDA\Elements\Id;
32
use PHPHealth\CDA\Elements\Title;
33
use PHPHealth\CDA\DataType\Code\CodedWithEquivalents;
34
use PHPHealth\CDA\Elements\Code;
35
use PHPHealth\CDA\DataType\TextAndMultimedia\CharacterString;
36
use PHPHealth\CDA\Elements\Text;
37
38
/**
39
 * 
40
 * Single section which will be included in component
41
 *
42
 * @author Julien Fastré <[email protected]>
43
 */
44
abstract class Section extends AbstractElement implements HasClassCode
45
{
46
    /**
47
     *
48
     * @var InstanceIdentifier
49
     */
50
    private $id;
51
    
52
    /**
53
     *
54
     * @var CodedWithEquivalents
55
     */
56
    private $code;
57
    
58
    /**
59
     * 
60
     * @var CharacterString
61
     */
62
    private $text;
63
    
64
    protected function getElementTag(): string
65
    {
66
        return 'section';
67
    }
68
69
    public function getClassCode(): string
70
    {
71
        return 'DOCSECT';
72
    }
73
    
74
    /**
75
     * 
76
     * @return InstanceIdentifier
77
     */
78
    public function getId()
79
    {
80
        return $this->id;
81
    }
82
83
    public function setId(InstanceIdentifier $id)
84
    {
85
        $this->id = $id;
86
        
87
        return $this;
88
    }
89
90
    public function getCode(): CodedWithEquivalents
91
    {
92
        return $this->code;
93
    }
94
95
    public function setCode(CodedWithEquivalents $code)
96
    {
97
        $this->code = $code;
98
        return $this;
99
    }
100
    
101
    public function getText(): CharacterString
102
    {
103
        return $this->text;
104
    }
105
106
    public function setText(CharacterString $text)
107
    {
108
        $this->text = $text;
109
        return $this;
110
    }
111
        
112
    /**
113
     * the code for the current section
114
     * 
115
     * @return InstanceIdentifier
116
     */
117
    abstract public function getTemplateId();
118
    
119
    /**
120
     * The title for the section
121
     * 
122
     * @return CharacterString
123
     */
124
    abstract public function getTitle();
125
126
    /**
127
     * 
128
     * @param \DOMDocument $doc
129
     */
130
    public function toDOMElement(\DOMDocument $doc): \DOMElement
131
    {
132
        $el = $this->createElement($doc);
133
        // append templateId
134
        if ($this->getTemplateId() !== NULL) {
135
            $el->appendChild(
136
                (new TemplateId($this->getTemplateId()))->toDOMElement($doc)
137
                );
138
        }
139
        // append id
140
        if ($this->getId() !== NULL) {
141
            $el->appendChild(
142
                (new Id($this->getId()))->toDOMElement($doc)
143
                );
144
        }
145
        // append code
146
        if ($this->getCode() !== NULL) {
147
            $el->appendChild(
148
                (new Code($this->getCode()))->toDOMElement($doc)
0 ignored issues
show
Compatibility introduced by
$this->getCode() of type object<PHPHealth\CDA\Dat...e\CodedWithEquivalents> is not a sub-type of object<PHPHealth\CDA\DataType\Code\CodedValue>. It seems like you assume a child class of the class PHPHealth\CDA\DataType\Code\CodedWithEquivalents 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...
149
                );
150
        }
151
        // append title
152
        if (! empty($this->getTitle())) {
153
            $el->appendChild(
154
                (new Title($this->getTitle()))->toDOMElement($doc)
155
                );
156
        }
157
        // append text
158
        if (! empty($this->getText())) {
159
            $el->appendChild(
160
                (new Text($this->getText()))->toDOMElement($doc)
161
                );
162
        }
163
        
164
        
165
        return $el;
166
    }
167
}
168