Issues (138)

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/Reflection/Adapter/ReflectionFunction.php (1 issue)

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
declare(strict_types=1);
4
5
namespace Roave\BetterReflection\Reflection\Adapter;
6
7
use Exception;
8
use ReflectionException as CoreReflectionException;
9
use ReflectionFunction as CoreReflectionFunction;
10
use Roave\BetterReflection\Reflection\Adapter\Exception\NotImplemented;
11
use Roave\BetterReflection\Reflection\ReflectionFunction as BetterReflectionFunction;
12
use Throwable;
13
use function func_get_args;
14
15
class ReflectionFunction extends CoreReflectionFunction
16
{
17
    /** @var BetterReflectionFunction */
18
    private $betterReflectionFunction;
19
20 35
    public function __construct(BetterReflectionFunction $betterReflectionFunction)
21
    {
22 35
        $this->betterReflectionFunction = $betterReflectionFunction;
23 35
    }
24
25
    /**
26
     * {@inheritDoc}
27
     *
28
     * @throws Exception
29
     */
30 1
    public static function export($name, $return = null)
31
    {
32 1
        throw new Exception('Unable to export statically');
33
    }
34
35
    /**
36
     * {@inheritDoc}
37
     */
38 1
    public function __toString()
39
    {
40 1
        return $this->betterReflectionFunction->__toString();
41
    }
42
43
    /**
44
     * {@inheritDoc}
45
     */
46 1
    public function inNamespace()
47
    {
48 1
        return $this->betterReflectionFunction->inNamespace();
49
    }
50
51
    /**
52
     * {@inheritDoc}
53
     */
54 1
    public function isClosure()
55
    {
56 1
        return $this->betterReflectionFunction->isClosure();
57
    }
58
59
    /**
60
     * {@inheritDoc}
61
     */
62 1
    public function isDeprecated()
63
    {
64 1
        return $this->betterReflectionFunction->isDeprecated();
65
    }
66
67
    /**
68
     * {@inheritDoc}
69
     */
70 1
    public function isInternal()
71
    {
72 1
        return $this->betterReflectionFunction->isInternal();
73
    }
74
75
    /**
76
     * {@inheritDoc}
77
     */
78 1
    public function isUserDefined()
79
    {
80 1
        return $this->betterReflectionFunction->isUserDefined();
81
    }
82
83
    /**
84
     * {@inheritDoc}
85
     */
86 1
    public function getClosureThis()
87
    {
88 1
        throw new NotImplemented('Not implemented');
89
    }
90
91
    /**
92
     * {@inheritDoc}
93
     */
94 1
    public function getClosureScopeClass()
95
    {
96 1
        throw new NotImplemented('Not implemented');
97
    }
98
99
    /**
100
     * {@inheritDoc}
101
     */
102 2
    public function getDocComment()
103
    {
104 2
        return $this->betterReflectionFunction->getDocComment() ?: false;
105
    }
106
107
    /**
108
     * {@inheritDoc}
109
     */
110 1
    public function getEndLine()
111
    {
112 1
        return $this->betterReflectionFunction->getEndLine();
113
    }
114
115
    /**
116
     * {@inheritDoc}
117
     */
118 1
    public function getExtension()
119
    {
120 1
        throw new NotImplemented('Not implemented');
121
    }
122
123
    /**
124
     * {@inheritDoc}
125
     */
126 2
    public function getExtensionName()
127
    {
128 2
        return $this->betterReflectionFunction->getExtensionName() ?? false;
0 ignored issues
show
Bug Best Practice introduced by Jaroslav Hanslík
The return type of return $this->betterRefl...tensionName() ?? false; (false) is incompatible with the return type of the parent method ReflectionFunction::getExtensionName of type string.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
129
    }
130
131
    /**
132
     * {@inheritDoc}
133
     */
134 2
    public function getFileName()
135
    {
136 2
        return $this->betterReflectionFunction->getFileName() ?? false;
137
    }
138
139
    /**
140
     * {@inheritDoc}
141
     */
142 1
    public function getName()
143
    {
144 1
        return $this->betterReflectionFunction->getName();
145
    }
146
147
    /**
148
     * {@inheritDoc}
149
     */
150 1
    public function getNamespaceName()
151
    {
152 1
        return $this->betterReflectionFunction->getNamespaceName();
153
    }
154
155
    /**
156
     * {@inheritDoc}
157
     */
158 1
    public function getNumberOfParameters()
159
    {
160 1
        return $this->betterReflectionFunction->getNumberOfParameters();
161
    }
162
163
    /**
164
     * {@inheritDoc}
165
     */
166 1
    public function getNumberOfRequiredParameters()
167
    {
168 1
        return $this->betterReflectionFunction->getNumberOfRequiredParameters();
169
    }
170
171
    /**
172
     * {@inheritDoc}
173
     */
174 1
    public function getParameters()
175
    {
176 1
        $parameters = $this->betterReflectionFunction->getParameters();
177
178 1
        $wrappedParameters = [];
179 1
        foreach ($parameters as $key => $parameter) {
180 1
            $wrappedParameters[$key] = new ReflectionParameter($parameter);
181
        }
182
183 1
        return $wrappedParameters;
184
    }
185
186
    /**
187
     * {@inheritDoc}
188
     */
189 1
    public function getReturnType()
190
    {
191 1
        return ReflectionNamedType::fromReturnTypeOrNull($this->betterReflectionFunction->getReturnType());
192
    }
193
194
    /**
195
     * {@inheritDoc}
196
     */
197 1
    public function getShortName()
198
    {
199 1
        return $this->betterReflectionFunction->getShortName();
200
    }
201
202
    /**
203
     * {@inheritDoc}
204
     */
205 1
    public function getStartLine()
206
    {
207 1
        return $this->betterReflectionFunction->getStartLine();
208
    }
209
210
    /**
211
     * {@inheritDoc}
212
     */
213 1
    public function getStaticVariables()
214
    {
215 1
        throw new NotImplemented('Not implemented');
216
    }
217
218
    /**
219
     * {@inheritDoc}
220
     */
221 1
    public function returnsReference()
222
    {
223 1
        return $this->betterReflectionFunction->returnsReference();
224
    }
225
226
    /**
227
     * {@inheritDoc}
228
     */
229 1
    public function isGenerator()
230
    {
231 1
        return $this->betterReflectionFunction->isGenerator();
232
    }
233
234
    /**
235
     * {@inheritDoc}
236
     */
237 1
    public function isVariadic()
238
    {
239 1
        return $this->betterReflectionFunction->isVariadic();
240
    }
241
242
    /**
243
     * {@inheritDoc}
244
     */
245 1
    public function isDisabled()
246
    {
247 1
        return $this->betterReflectionFunction->isDisabled();
248
    }
249
250
    /**
251
     * {@inheritDoc}
252
     */
253 2
    public function invoke($args = null)
254
    {
255
        try {
256 2
            return $this->betterReflectionFunction->invoke(...func_get_args());
257 1
        } catch (Throwable $e) {
258 1
            throw new CoreReflectionException($e->getMessage(), 0, $e);
259
        }
260
    }
261
262
    /**
263
     * {@inheritDoc}
264
     */
265 2
    public function invokeArgs(array $args)
266
    {
267
        try {
268 2
            return $this->betterReflectionFunction->invokeArgs($args);
269 1
        } catch (Throwable $e) {
270 1
            throw new CoreReflectionException($e->getMessage(), 0, $e);
271
        }
272
    }
273
274
    /**
275
     * {@inheritDoc}
276
     */
277 2
    public function getClosure()
278
    {
279
        try {
280 2
            return $this->betterReflectionFunction->getClosure();
281 1
        } catch (Throwable $e) {
282 1
            return null;
283
        }
284
    }
285
}
286