Issues (7)

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/Service/XmlExtractor.php (7 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
namespace mxdiModule\Service;
3
4
use mxdiModule\Annotation\AnnotationInterface;
5
use mxdiModule\Annotation\InjectParams;
6
7
class XmlExtractor implements ExtractorInterface
8
{
9
    /**
10
     * Path to the XML file.
11
     * @var array
12
     */
13
    protected $file;
14
15
    /**
16
     * Parsed results
17
     * @var \SimpleXMLElement|null
18
     */
19
    protected $config;
20
21
    /**
22
     * Was config parsed?
23
     * @var bool
24
     */
25
    protected $isConfigParsed;
26
27
    /**
28
     * @param array $options
29
     */
30 10 View Code Duplication
    public function __construct(array $options)
31
    {
32 10
        if (!isset($options['file']) || empty($options['file'])) {
33 2
            throw new \InvalidArgumentException('XML file path is missing');
34
        }
35
36 10
        if (! file_exists($options['file'])) {
37 1
            throw new \InvalidArgumentException('XML file is missing');
38
        }
39
40 10
        $this->file = $options['file'];
41 10
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 3
    public function getConstructorInjections($fqcn)
47
    {
48 3
        $this->isConfigParsed($fqcn);
49
50 3
        if (empty($this->config)) {
51 1
            return null;
52
        }
53
54 2
        $values = [];
55 2
        foreach ($this->config->xpath('constructor/inject') as $spec) {
56 1
            $values[] = $this->createInjectionObject($spec);
57 2
        }
58
59 2
        if (!count($values)) {
60 1
            return null;
61
        }
62
63 1
        $injections = new InjectParams();
64 1
        $injections->value = $values;
65
66 1
        return $injections;
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72 3
    public function getMethodsInjections($fqcn)
73
    {
74 3
        $this->isConfigParsed($fqcn);
75
76 3
        if (empty($this->config)) {
77 1
            return [];
78
        }
79
80 2
        $injections = [];
81 2
        foreach ($this->config->xpath('methods/method') as $spec) {
82 1
            $params = new InjectParams();
83 1
            foreach ($spec->xpath('inject') as $methodSpec) {
84 1
                $params->value[] = $this->createInjectionObject($methodSpec);
85 1
            }
86
87 1
            $injections[(string)$spec['name']] = $params;
88 2
        }
89
90 2
        return $injections;
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     */
96 3
    public function getPropertiesInjections($fqcn)
97
    {
98 3
        $this->isConfigParsed($fqcn);
99
100 3
        if (empty($this->config)) {
101 1
            return [];
102
        }
103
104 2
        $injections = [];
105 2
        foreach ($this->config->xpath('properties/property') as $spec) {
106 1
            $injections[(string)$spec['name']] = $this->createInjectionObject($spec->xpath('inject')[0]);
107 2
        }
108
109 2
        return $injections;
110
    }
111
112
    /**
113
     * {@inheritdoc}
114
     */
115 1
    public function getChangeSet($fqcn)
116
    {
117 1
        $this->isConfigParsed($fqcn);
118
119 1
        if (!empty((string)$this->config['fqcn'])) {
120
            $fqcn = (string)$this->config['fqcn'];
121
        }
122
123 1
        return new ChangeSet($this, $fqcn);
124
    }
125
126
    /**
127
     * @return array
128
     */
129 1
    public function getFile()
130
    {
131 1
        return $this->file;
132
    }
133
134
    /**
135
     * Parse the XML.
136
     * @param string $fqcn
137
     */
138 6
    private function isConfigParsed($fqcn)
139
    {
140 6
        if ($this->isConfigParsed) {
141 3
            return;
142
        }
143
144 6
        $module = simplexml_load_file($this->file);
145
146 6
        foreach ($module->xpath('/mxdiModule/service') as $service) {
147 6
            if ((string)$service['id'] === $fqcn) {
148 5
                $this->config = $service;
149 5
                break;
150
            }
151 6
        }
152
153 6
        $this->isConfigParsed = true;
154 6
    }
155
156
    /**
157
     * @param \SimpleXMLElement $spec
158
     * @return AnnotationInterface
159
     */
160 3
    private function createInjectionObject(\SimpleXMLElement $spec)
161
    {
162 3
        $injectionFqcn = (string)$spec['type'];
163 3
        $injection = new $injectionFqcn;
164
165 3
        foreach ($spec->xpath('param') as $param) {
166 3
            $this->createProperty($injection, $param);
167 3
        }
168
169 3
        return $injection;
170
    }
171
172
    /**
173
     * @param object $injection
174
     * @param \SimpleXMLElement $param
175
     */
176 3
    private function createProperty($injection, $param)
177
    {
178 3
        $property = (string)$param['name'];
179
180 3
        switch ((string)$param['type']) {
181 3
            case 'boolean': $value = (bool)(string)$param; break;
0 ignored issues
show
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
182 3
            case 'integer': $value = (int)(string)$param; break;
0 ignored issues
show
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
183 3
            case 'float': $value = (float)(string)$param; break;
0 ignored issues
show
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
Terminating statement must be on a line by itself

As per the PSR-2 coding standard, the break (or other terminating) statement must be on a line of its own.

switch ($expr) {
     case "A":
         doSomething();
         break; //wrong
     case "B":
         doSomething();
         break; //right
     case "C:":
         doSomething();
         return true; //right
 }

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
184 3
            default: $value = (string)$param;
0 ignored issues
show
The default body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a default statement must start on the line immediately following the statement.

switch ($expr) {
    default:
        doSomething(); //right
        break;
}


switch ($expr) {
    default:

        doSomething(); //wrong
        break;
}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
185 3
        }
186
187 3
        $injection->$property = $value;
188 3
    }
189
}
190