Issues (29)

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/StubGeneration/ClientStubGenerator.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
3
namespace GoetasWebservices\SoapServices\SoapClient\StubGeneration;
4
5
use Doctrine\Common\Inflector\Inflector;
6
use GoetasWebservices\SoapServices\SoapClient\StubGeneration\Tag\MethodTag;
7
use GoetasWebservices\SoapServices\SoapClient\StubGeneration\Tag\ParamTag;
8
use GoetasWebservices\XML\WSDLReader\Wsdl\Message\Part;
9
use GoetasWebservices\XML\WSDLReader\Wsdl\PortType;
10
use GoetasWebservices\Xsd\XsdToPhp\Naming\NamingStrategy;
11
use GoetasWebservices\Xsd\XsdToPhp\Php\PhpConverter;
12
use Zend\Code\Generator\ClassGenerator;
13
use Zend\Code\Generator\DocBlockGenerator;
14
15
class ClientStubGenerator
16
{
17
    protected $reservedWords = [
18
        'int',
19
        'float',
20
        'bool',
21
        'string',
22
        'true',
23
        'false',
24
        'null',
25
        'resource',
26
        'object',
27
        'mixed',
28
        'numeric',
29
    ];
30
31
    private $baseNs = [
32
        'headers' => '\\SoapEnvelope\\Headers',
33
        'parts' => '\\SoapEnvelope\\Parts',
34
        'messages' => '\\SoapEnvelope\\Messages',
35
    ];
36
    /**
37
     * @var NamingStrategy
38
     */
39
    private $namingStrategy;
40
    /**
41
     * @var PhpConverter
42
     */
43
    private $phpConverter;
44
    /**
45
     * @var bool
46
     */
47
    private $unwrapReturn = false;
48
49 1
    public function __construct(PhpConverter $phpConverter, NamingStrategy $namingStrategy, $unwrapReturn = false, array $baseNs = array())
50
    {
51 1
        foreach ($baseNs as $k => $ns) {
52
            if (isset($this->baseNs[$k])) {
53
                $this->baseNs[$k] = $ns;
54
            }
55 1
        }
56 1
        $this->baseNs = $baseNs;
57 1
        $this->namingStrategy = $namingStrategy;
58 1
        $this->phpConverter = $phpConverter;
59 1
        $this->unwrapReturn = $unwrapReturn;
60 1
    }
61
62 1
    public function setUnwrap($mode = true)
63
    {
64 1
        $this->unwrapReturn = (bool)$mode;
65 1
    }
66
67
    /**
68
     * @param PortType[] $ports
69
     * @return ClassGenerator
70
     */
71 1
    public function generate(array $ports)
72
    {
73 1
        $classes = array();
74 1
        foreach ($ports as $port) {
75 1
            $class = new ClassGenerator();
76 1
            if ($this->visitPortType($class, $port) !== false) {
77 1
                $classes[] = $class;
78 1
            }
79 1
        }
80 1
        return $classes;
81
    }
82
83 1
    private function visitPortType(ClassGenerator $class, PortType $portType)
84
    {
85 1
        if (!count($portType->getOperations())) {
86
            return false;
87
        }
88 1
        $docBlock = new DocBlockGenerator("Class representing " . $portType->getName());
89 1
        $docBlock->setWordWrap(false);
90 1
        if ($portType->getDocumentation()) {
91
            $docBlock->setLongDescription($portType->getDocumentation());
92
        }
93
94 1
        $namespaces = $this->phpConverter->getNamespaces();
95 1
        $class->setNamespaceName($namespaces[$portType->getDefinition()->getTargetNamespace()] . "\\SoapStubs");
96 1
        $class->setName(Inflector::classify($portType->getName()));
97 1
        $class->setDocblock($docBlock);
98
99 1
        foreach ($portType->getOperations() as $operation) {
100 1
            $operationTag = $this->visitOperation($operation);
101 1
            $docBlock->setTag($operationTag);
102 1
        }
103 1
    }
104
105 1
    private function visitOperation(PortType\Operation $operation)
106
    {
107 1
        $types = $this->getOperationReturnTypes($operation);
108 1
        $operationTag = new MethodTag(
109 1
            Inflector::camelize($operation->getName()),
0 ignored issues
show
Deprecated Code introduced by
The method Doctrine\Common\Inflector\Inflector::camelize() has been deprecated.

This method has been deprecated.

Loading history...
110 1
            $types,
111 1
            preg_replace("/[\n\r]+/", " ", $operation->getDocumentation())
112 1
        );
113 1
        $params = $this->getOperationParams($operation);
114 1
        $operationTag->setParams($params);
115 1
        return $operationTag;
116
    }
117
118 1
    private function getOperationParams(PortType\Operation $operation)
119
    {
120 1
        if (!$operation->getInput()) {
121
            return [];
122
        }
123
124 1
        $parts = $operation->getInput()->getMessage()->getParts();
0 ignored issues
show
The method getParts cannot be called on $operation->getInput()->getMessage() (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
125 1
        if (!$parts) {
126 1
            return [];
127
        }
128
129 1
        if (count($parts) > 1) {
130 1
            $params = [];
131 1
            foreach ($parts as $part) {
132 1
                $partName = $this->namingStrategy->getPropertyName($part);
133 1
                $class = $this->getClassFromPart($part);
134
135 1
                $typeName = $class->getPhpType();
136 1
                if ($t = $class->isSimpleType()) {
137
                    $typeName = $t->getType()->getPhpType();
138
                }
139 1
                $params[] = $param = new ParamTag($partName, [$typeName]);
0 ignored issues
show
$param is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
140 1
            }
141 1
        } else {
142 1
            $params = $this->extractSinglePartParameters(reset($parts));
143
        }
144
145 1
        return $params;
146
    }
147
148 1
    private function getOperationReturnTypes(PortType\Operation $operation)
149
    {
150 1
        if (!$operation->getOutput() || !$operation->getOutput()->getMessage()->getParts()) {
0 ignored issues
show
The method getParts cannot be called on $operation->getOutput()->getMessage() (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
151 1
            return ['void'];
152
        }
153 1
        $parts = $operation->getOutput()->getMessage()->getParts();
0 ignored issues
show
The method getParts cannot be called on $operation->getOutput()->getMessage() (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
154 1
        if (count($parts) > 1) {
155 1
            return ['array'];
156
        }
157
        /**
158
         * @var $part \GoetasWebservices\XML\WSDLReader\Wsdl\Message\Part
159
         */
160 1
        $part = reset($parts);
161
162 1
        $class = $this->getClassFromPart($part);
163 1
        if ($this->unwrapReturn) {
164
            foreach ($class->getProperties() as $property) {
165
                $propertyClass = $property->getType();
166
                if ($t = $propertyClass->isSimpleType()) {
167
                    return [$t->getType()->getPhpType()];
168
                }
169
                return [$propertyClass->getPhpType()];
170
            }
171
        }
172
173 1
        if ($t = $class->isSimpleType()) {
174
            return [$t->getType()->getPhpType()];
175
        }
176 1
        return [$class->getPhpType()];
177
    }
178
179 1
    private function getClassFromPart(Part $part)
180
    {
181 1
        if ($part->getType()) {
182 1
            return $this->phpConverter->visitType($part->getType());
183
        } else {
184 1
            return $this->phpConverter->visitElementDef($part->getElement());
0 ignored issues
show
$part->getElement() of type object<GoetasWebservices...ma\Element\ElementItem> is not a sub-type of object<GoetasWebservices...ema\Element\ElementDef>. It seems like you assume a concrete implementation of the interface GoetasWebservices\XML\XS...ema\Element\ElementItem 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...
185
        }
186
    }
187
188
    /**
189
     * @param $part
190
     * @return array
191
     */
192 1
    private function extractSinglePartParameters(Part $part)
193
    {
194 1
        $params = [];
195 1
        $class = $this->getClassFromPart($part);
196
197 1
        foreach ($class->getPropertiesInHierarchy() as $property) {
198 1
            $t = $property->getType()->getPhpType();
199 1
            $params[] = $param = new ParamTag($property->getName(), [$t]);
0 ignored issues
show
$param is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
200 1
        }
201 1
        return $params;
202
    }
203
}
204