Issues (118)

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/AbstractConverter.php (37 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 GoetasWebservices\Xsd\XsdToPhp;
3
4
use GoetasWebservices\XML\XSDReader\Schema\Element\ElementSingle;
5
use GoetasWebservices\XML\XSDReader\Schema\Schema;
6
use GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType;
7
use GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType;
8
use GoetasWebservices\XML\XSDReader\Schema\Type\Type;
9
use GoetasWebservices\Xsd\XsdToPhp\Naming\NamingStrategy;
10
use Psr\Log\LoggerAwareTrait;
11
use Psr\Log\LoggerInterface;
12
use Psr\Log\NullLogger;
13
14
abstract class AbstractConverter
15
{
16
    use LoggerAwareTrait;
17
18
    protected $baseSchemas = array(
19
        'http://www.w3.org/2001/XMLSchema',
20
        'http://www.w3.org/XML/1998/namespace'
21
    );
22
23
    protected $namespaces = array(
24
        'http://www.w3.org/2001/XMLSchema' => '',
25
        'http://www.w3.org/XML/1998/namespace' => ''
26
    );
27
28
    /**
29
     * @var \GoetasWebservices\Xsd\XsdToPhp\Naming\NamingStrategy
30
     */
31
    private $namingStrategy;
32
33
    public abstract function convert(array $schemas);
0 ignored issues
show
The abstract declaration must precede the visibility declaration
Loading history...
34
35
    protected $typeAliases = array();
36
37
    protected $aliasCache = array();
38
39 53
    public function addAliasMap($ns, $name, callable $handler)
40
    {
41 53
        $this->logger->info("Added map $ns $name");
42 53
        $this->typeAliases[$ns][$name] = $handler;
43 53
    }
44
45 2
    public function addAliasMapType($ns, $name, $type)
46
    {
47
        $this->addAliasMap($ns, $name, function () use ($type) {
48 2
            return $type;
49 2
        });
50 2
    }
51
52 48
    public function getTypeAlias($type, Schema $schemapos = null)
53
    {
54 48
        $schema = $schemapos ?: $type->getSchema();
55
56 48
        $cid = $schema->getTargetNamespace() . "|" . $type->getName();
57 48
        if (isset($this->aliasCache[$cid])) {
58 10
            return $this->aliasCache[$cid];
59
        }
60 48
        if (isset($this->typeAliases[$schema->getTargetNamespace()][$type->getName()])) {
61 48
            return $this->aliasCache[$cid] = call_user_func($this->typeAliases[$schema->getTargetNamespace()][$type->getName()], $type);
62
        }
63 27
    }
64
65 53
    public function __construct(NamingStrategy $namingStrategy, LoggerInterface $logger = null)
66
    {
67 53
        $this->namingStrategy = $namingStrategy;
68 53
        $this->logger = $logger ?: new NullLogger();
69
70
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "gYearMonth", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
71
            return "integer";
72 53
        });
73
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "gMonthDay", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
74
            return "integer";
75 53
        });
76
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "gMonth", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
77
            return "integer";
78 53
        });
79
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "gYear", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
80
            return "integer";
81 53
        });
82
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "NMTOKEN", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
83
            return "string";
84 53
        });
85
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "NMTOKENS", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
86
            return "string";
87 53
        });
88
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "QName", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
89
            return "string";
90 53
        });
91
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "NCName", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
92
            return "string";
93 53
        });
94
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "decimal", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
95 5
            return "float";
96 53
        });
97
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "float", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
98
            return "float";
99 53
        });
100
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "double", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
101
            return "float";
102 53
        });
103
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "string", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
104 23
            return "string";
105 53
        });
106
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "normalizedString", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
107
            return "string";
108 53
        });
109
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "integer", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
110 5
            return "integer";
111 53
        });
112
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "int", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
113 5
            return "integer";
114 53
        });
115
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "unsignedInt", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
116
            return "integer";
117 53
        });
118
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "negativeInteger", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
119
            return "integer";
120 53
        });
121
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "positiveInteger", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
122
            return "integer";
123 53
        });
124
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "nonNegativeInteger", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
125
            return "integer";
126 53
        });
127
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "nonPositiveInteger", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
128
            return "integer";
129 53
        });
130
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "long", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
131 4
            return "integer";
132 53
        });
133
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "unsignedLong", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
134
            return "integer";
135 53
        });
136
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "short", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
137
            return "integer";
138 53
        });
139
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "boolean", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
140
            return "boolean";
141 53
        });
142
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "nonNegativeInteger", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
143
            return "integer";
144 53
        });
145
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "positiveInteger", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
146
            return "integer";
147 53
        });
148
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "language", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
149 1
            return "string";
150 53
        });
151
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "token", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
152
            return "string";
153 53
        });
154
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "anyURI", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
155
            return "string";
156 53
        });
157
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "byte", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
158
            return "string";
159 53
        });
160
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "duration", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
161
            return "DateInterval";
162 53
        });
163
164
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "ID", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
165
            return "string";
166 53
        });
167
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "IDREF", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
168
            return "string";
169 53
        });
170
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "IDREFS", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
171
            return "string";
172 53
        });
173
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "Name", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
174 1
            return "string";
175 53
        });
176
177 53
        $this->addAliasMap("http://www.w3.org/2001/XMLSchema", "NCName", function (Type $type) {
0 ignored issues
show
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
178
            return "string";
179 53
        });
180 53
    }
181
182
    /**
183
     * @return \GoetasWebservices\Xsd\XsdToPhp\Naming\NamingStrategy
184
     */
185 48
    protected function getNamingStrategy()
186
    {
187 48
        return $this->namingStrategy;
188
    }
189
190 51
    public function addNamespace($ns, $phpNamespace)
191
    {
192 51
        $this->logger->info("Added ns mapping $ns, $phpNamespace");
193 51
        $this->namespaces[$ns] = $phpNamespace;
194 51
        return $this;
195
    }
196
197
    protected function cleanName($name)
198
    {
199
        return preg_replace("/<.*>/", "", $name);
200
    }
201
202
    /**
203
     * @param Type $type
204
     * @return \GoetasWebservices\XML\XSDReader\Schema\Type\Type|null
205
     */
206 28
    protected function isArrayType(Type $type)
207
    {
208 28
        if ($type instanceof SimpleType) {
209 27
            return $type->getList();
210
        }
211 27
    }
212
213
    /**
214
     * @param Type $type
215
     * @return \GoetasWebservices\XML\XSDReader\Schema\Element\ElementSingle|null
216
     */
217 28
    protected function isArrayNestedElement(Type $type)
218
    {
219 28
        if ($type instanceof ComplexType && !$type->getParent() && !$type->getAttributes() && count($type->getElements()) === 1) {
220 20
            $elements = $type->getElements();
221 20
            return $this->isArrayElement(reset($elements));
222
        }
223 27
    }
224
225
    /**
226
     * @param mixed $element
227
     * @return \GoetasWebservices\XML\XSDReader\Schema\Element\ElementSingle|null
228
     */
229 26
    protected function isArrayElement($element)
230
    {
231 26
        if ($element instanceof ElementSingle && ($element->getMax() > 1 || $element->getMax() === -1)) {
232 9
            return $element;
233
        }
234 24
    }
235
236
    public function getNamespaces()
237
    {
238
        return $this->namespaces;
239
    }
240
241
}
242