Issues (5)

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.

src/Driver/XMLReader.php (4 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
/**
4
 * @author Serkin Alexander <[email protected]>
5
 * @license https://github.com/serkin/ymlparser/LICENSE MIT
6
 */
7
8
namespace YMLParser\Driver;
9
10
class XMLReader implements DriverInterface {
11
12
    /**
13
     * @var \XMLReader
14
     */
15
    private $xml;
16
17
    /**
18
     * Link to stored xml file.
19
     *
20
     * @var string
21
     */
22
    private $filename;
23
24
    /**
25
     * Gets categories.
26
     *
27
     * @return arry Array of \YMLParser\Node\Category instances or empty array
28
     */
29 View Code Duplication
    public function getCategories() {
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...
30
        $returnArr = [];
31
        $this->moveToStart();
32
        $xml = $this->xml;
33
34
        while ($xml->read()) {
35
            if ($xml->nodeType == \XMLReader::ELEMENT && $xml->name == 'categories') {
36
                while ($xml->read() && $xml->name != 'categories') {
37
                    if ($xml->nodeType == \XMLReader::ELEMENT) {
38
                        $arr = [];
39
40
                        if ($xml->hasAttributes) {
41
42
                            while ($xml->moveToNextAttribute()) {
43
                                $arr[strtolower($xml->name)] = $xml->value;
44
                            }
45
                        }
46
47
                        $xml->read();
48
                        $arr['value'] = $xml->value;
49
                        $returnArr[] = new \YMLParser\Node\Category($arr);
50
51
                        unset($arr);
52
                    }
53
                }
54
            }
55
        }
56
57
        return $returnArr;
58
    }
59
60
    /**
61
     * Gets currencies.
62
     *
63
     * @return array
64
     */
65 View Code Duplication
    public function getCurrencies() {
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...
66
67
        $returnArr = [];
68
        $this->moveToStart();
69
        $xml = $this->xml;
70
71
        while ($xml->read()) {
72
            if ($xml->nodeType == \XMLReader::ELEMENT && $xml->name == 'currencies') {
73
                while ($xml->read() && $xml->name != 'currencies') {
74
                    if ($xml->nodeType == \XMLReader::ELEMENT) {
75
                        $arr = [];
76
77
                        if ($xml->hasAttributes) {
78
79
                            while ($xml->moveToNextAttribute()) {
80
                                $arr[strtolower($xml->name)] = $xml->value;
81
                            }
82
                        }
83
84
                        $xml->read();
85
                        $arr['value'] = $xml->value;
86
                        $returnArr[] = new \YMLParser\Node\Currency($arr);
87
88
                        unset($arr);
89
                    }
90
                }
91
            }
92
        }
93
94
        return $returnArr;
95
    }
96
97
    /**
98
     * Gets offers.
99
     *
100
     * @param \Closure $filter
101
     *
102
     * @return \Iterator Array of \YMLParser\Node\Offer instances or empty array
103
     */
104
    public function getOffers(\Closure $filter = null) {
105
        $this->moveToStart();
106
        $xml = $this->xml;
107
108
        while ($xml->read()) {
109
            if ($xml->nodeType == \XMLReader::ELEMENT && $xml->name == 'offers') {
110
                while ($xml->read() && $xml->name != 'offers') {
111
                    if ($xml->nodeType == \XMLReader::ELEMENT && $xml->name == 'offer') {
112
                        $arr = $this->getElementAttributes($xml);
113
114
                        while ($xml->read() && $xml->name != 'offer') {
115
116
                            if ($xml->nodeType == \XMLReader::ELEMENT) {
117
118
                                $name = mb_strtolower($xml->name);
119
120
                                if ($name == 'param') {
121
                                    $tmpArr = ['name' => $xml->getAttribute('name')];
122
                                }
123
124
                                $xml->read();
125
126
                                if ($name == 'param') {
127
                                    $arr['params'][] = array_merge(['value' => $xml->value], $tmpArr);
0 ignored issues
show
The variable $tmpArr does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
128
                                } else {
129
                                    if ($name == 'picture') {
130
                                        $arr['pictures'][] = $xml->value;
131
                                    }
132
133
                                    $arr[$name] = $xml->value;
134
                                }
135
                            }
136
                        }
137
138
                        $returnValue = new \YMLParser\Node\Offer($arr);
139
140
                        if (!is_null($filter)) {
141
                            if ($filter($returnValue)) {
142
                                yield $returnValue;
143
                            }
144
                        } else {
145
                            yield $returnValue;
146
                        }
147
                    }
148
                }
149
            }
150
        }
151
    }
152
153
    /**
154
     * Gets attributes from element.
155
     *
156
     * @param \XMLReader $element
157
     *
158
     * @return array
159
     */
160
    private function getElementAttributes(\XMLReader $element) {
161
        $returnArr = [];
162
163
        if ($element->hasAttributes) {
164
            while ($element->moveToNextAttribute()) {
165
                $returnArr[mb_strtolower($element->name)] = $element->value;
166
            }
167
        }
168
169
        return $returnArr;
170
    }
171
172
    /**
173
     * Opens file.
174
     *
175
     * @param type $filename
176
     *
177
     * @throws \Exception
178
     *
179
     * @return bool
180
     */
181
    public function open($filename) {
182
        $this->filename = $filename;
0 ignored issues
show
Documentation Bug introduced by
It seems like $filename of type object<YMLParser\Driver\type> is incompatible with the declared type string of property $filename.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
183
        $this->xml = new \XMLReader();
184
185
        return $this->xml->open($filename);
186
    }
187
188
    /**
189
     * Gets amount of offers.
190
     *
191
     * @param \Closure $filter
192
     *
193
     * @return int
194
     */
195
    public function countOffers(\Closure $filter = null) {
196
        $returnValue = 0;
197
198
        foreach ($this->getOffers($filter) as $el):
199
            $returnValue++;
200
        endforeach;
201
202
        return $returnValue;
203
    }
204
205
    /**
206
     * Rewinds cursor to the first element.
207
     *
208
     * @return bool
209
     */
210
    private function moveToStart() {
211
        $this->xml->close();
212
213
        return $this->xml->open($this->filename);
214
    }
215
216
}
217