Issues (115)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

lib/Component/SingleComponent/Section.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
use PHPHealth\CDA\Elements\Entry;
38
39
/**
40
 * 
41
 * Single section which will be included in component
42
 *
43
 * @author Julien Fastré <[email protected]>
44
 */
45
class Section extends AbstractElement implements HasClassCode
46
{
47
    /**
48
     *
49
     * @var InstanceIdentifier
50
     */
51
    private $id;
52
    
53
    /**
54
     *
55
     * @var CodedWithEquivalents
56
     */
57
    private $code;
58
    
59
    /**
60
     * 
61
     * @var CharacterString
62
     */
63
    private $text;
64
    
65
    /**
66
     *
67
     * @var InstanceIdentifier[]
68
     */
69
    private $templateIds = array();
70
    
71
    /**
72
     *
73
     * @var CharacterString
74
     */
75
    private $title;
76
    
77
    /**
78
     *
79
     * @var Entry[]
80
     */
81
    private $entries = array();
82
    
83
    protected function getElementTag(): string
84
    {
85
        return 'section';
86
    }
87
88
    public function getClassCode(): string
89
    {
90
        return 'DOCSECT';
91
    }
92
    
93
    /**
94
     * 
95
     * @return InstanceIdentifier
96
     */
97
    public function getId()
98
    {
99
        return $this->id;
100
    }
101
102
    public function setId(InstanceIdentifier $id)
103
    {
104
        $this->id = $id;
105
        
106
        return $this;
107
    }
108
109
    public function getCode(): CodedWithEquivalents
110
    {
111
        return $this->code;
112
    }
113
114
    public function setCode(CodedWithEquivalents $code)
115
    {
116
        $this->code = $code;
117
        return $this;
118
    }
119
    
120
    public function getText(): CharacterString
121
    {
122
        return $this->text;
123
    }
124
125
    public function setText(CharacterString $text)
126
    {
127
        $this->text = $text;
128
        return $this;
129
    }
130
    
131 View Code Duplication
    public function setTemplateIds(array $templateIds)
0 ignored issues
show
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...
132
    {
133
        $validation = \array_reduce($templateIds, 
134
            function ($carry, $item) {
135
                if ($carry === false) {
136
                    return false;
137
                }
138
                
139
                return $item instanceof InstanceIdentifier;
140
            });
141
        
142
        if ($validation === false) {
143
            throw new \UnexpectedValueException(sprintf("The values of templateIds"
144
                . " must contains only %s", InstanceIdentifier::class));
145
        }
146
        
147
        $this->templateIds = $templateIds;
148
        
149
        return $this;
150
    }
151
    
152
    public function addTemplateId(InstanceIdentifier $templateId)
153
    {
154
        $this->templateIds[] = $templateId;
155
        
156
        return $this;
157
    }
158
159
            
160
    /**
161
     * the code for the current section
162
     * 
163
     * @return InstanceIdentifier[]
164
     */
165
    public function getTemplateIds()
166
    {
167
        return $this->templateIds;
168
    }
169
    
170
    /**
171
     * The title for the section
172
     * 
173
     * @return CharacterString
174
     */
175
    public function getTitle()
176
    {
177
        return $this->title;
178
    }
179
    
180
    public function setTitle(CharacterString $title)
181
    {
182
        $this->title = $title;
183
        
184
        return $this;
185
    }
186
    
187
    /**
188
     * create an entry, which is already bound to the current section
189
     * 
190
     * @return Entry
191
     */
192
    public function createEntry(): Entry
193
    {
194
        $entry = new Entry();
195
        
196
        $this->addEntry($entry);
197
        
198
        return $entry;
199
    }
200
    
201
    function getEntries(): array
202
    {
203
        return $this->entries;
204
    }
205
    
206
    public function addEntry(Entry $entry)
207
    {
208
        $this->entries[] = $entry;
209
    }
210
211
    
212
    /**
213
     * 
214
     * @param \DOMDocument $doc
215
     */
216
    public function toDOMElement(\DOMDocument $doc): \DOMElement
217
    {
218
        $el = $this->createElement($doc);
219
        // append templateId
220
        if ($this->getTemplateIds() !== NULL) {
221
            foreach ($this->getTemplateIds() as $id) {
222
                $el->appendChild(
223
                    (new TemplateId($id))->toDOMElement($doc)
224
                    );
225
            }
226
        }
227
        // append id
228
        if ($this->getId() !== NULL) {
229
            $el->appendChild(
230
                (new Id($this->getId()))->toDOMElement($doc)
231
                );
232
        }
233
        // append code
234
        if ($this->getCode() !== NULL) {
235
            $el->appendChild(
236
                (new Code($this->getCode()))->toDOMElement($doc)
0 ignored issues
show
$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...
237
                );
238
        }
239
        // append title
240
        if (! empty($this->getTitle())) {
241
            $el->appendChild(
242
                (new Title($this->getTitle()))->toDOMElement($doc)
243
                );
244
        }
245
        // append text
246
        if (! empty($this->getText())) {
247
            $el->appendChild(
248
                (new Text($this->getText()))->toDOMElement($doc)
249
                );
250
        }
251
        
252
        foreach ($this->getEntries() as $entry) {
253
            $el->appendChild($entry->toDOMElement($doc));
254
        }
255
        
256
        return $el;
257
    }
258
}
259