Issues (139)

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/ReflectionMethod.php (3 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
declare(strict_types=1);
4
5
namespace Roave\BetterReflection\Reflection\Adapter;
6
7
use Exception;
8
use ReflectionException as CoreReflectionException;
9
use ReflectionMethod as CoreReflectionMethod;
10
use Roave\BetterReflection\Reflection\Adapter\Exception\NotImplemented;
11
use Roave\BetterReflection\Reflection\Exception\NoObjectProvided;
12
use Roave\BetterReflection\Reflection\Exception\NotAnObject;
13
use Roave\BetterReflection\Reflection\ReflectionMethod as BetterReflectionMethod;
14
use Throwable;
15
use function func_get_args;
16
17
class ReflectionMethod extends CoreReflectionMethod
18
{
19
    /** @var BetterReflectionMethod */
20
    private $betterReflectionMethod;
21
22
    /** @var bool */
23
    private $accessible = false;
24
25 52
    public function __construct(BetterReflectionMethod $betterReflectionMethod)
26
    {
27 52
        $this->betterReflectionMethod = $betterReflectionMethod;
28 52
    }
29
30
    /**
31
     * {@inheritDoc}
32
     *
33
     * @throws Exception
34
     */
35 1
    public static function export($class, $name, $return = null)
36
    {
37 1
        throw new Exception('Unable to export statically');
38
    }
39
40
    /**
41
     * {@inheritDoc}
42
     */
43 1
    public function __toString()
44
    {
45 1
        return $this->betterReflectionMethod->__toString();
46
    }
47
48
    /**
49
     * {@inheritDoc}
50
     */
51 1
    public function inNamespace()
52
    {
53 1
        return $this->betterReflectionMethod->inNamespace();
54
    }
55
56
    /**
57
     * {@inheritDoc}
58
     */
59 1
    public function isClosure()
60
    {
61 1
        return $this->betterReflectionMethod->isClosure();
62
    }
63
64
    /**
65
     * {@inheritDoc}
66
     */
67 1
    public function isDeprecated()
68
    {
69 1
        return $this->betterReflectionMethod->isDeprecated();
70
    }
71
72
    /**
73
     * {@inheritDoc}
74
     */
75 1
    public function isInternal()
76
    {
77 1
        return $this->betterReflectionMethod->isInternal();
78
    }
79
80
    /**
81
     * {@inheritDoc}
82
     */
83 1
    public function isUserDefined()
84
    {
85 1
        return $this->betterReflectionMethod->isUserDefined();
86
    }
87
88
    /**
89
     * {@inheritDoc}
90
     */
91 1
    public function getClosureThis()
92
    {
93 1
        throw new NotImplemented('Not implemented');
94
    }
95
96
    /**
97
     * {@inheritDoc}
98
     */
99 1
    public function getClosureScopeClass()
100
    {
101 1
        throw new NotImplemented('Not implemented');
102
    }
103
104
    /**
105
     * {@inheritDoc}
106
     */
107 2
    public function getDocComment()
108
    {
109 2
        return $this->betterReflectionMethod->getDocComment() ?: false;
0 ignored issues
show
Comprehensibility Best Practice introduced by Jaroslav Hanslík
The expression $this->betterReflectionM...tDocComment() ?: false; of type string|false adds false to the return on line 109 which is incompatible with the return type of the parent method ReflectionMethod::getDocComment of type string. It seems like you forgot to handle an error condition.
Loading history...
110
    }
111
112
    /**
113
     * {@inheritDoc}
114
     */
115 1
    public function getEndLine()
116
    {
117 1
        return $this->betterReflectionMethod->getEndLine();
118
    }
119
120
    /**
121
     * {@inheritDoc}
122
     */
123 1
    public function getExtension()
124
    {
125 1
        throw new NotImplemented('Not implemented');
126
    }
127
128
    /**
129
     * {@inheritDoc}
130
     */
131 2
    public function getExtensionName()
132
    {
133 2
        return $this->betterReflectionMethod->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 ReflectionMethod::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...
134
    }
135
136
    /**
137
     * {@inheritDoc}
138
     */
139 2
    public function getFileName()
140
    {
141 2
        return $this->betterReflectionMethod->getFileName() ?? false;
0 ignored issues
show
Comprehensibility Best Practice introduced by Jaroslav Hanslík
The expression $this->betterReflectionM...getFileName() ?? false; of type string|false adds false to the return on line 141 which is incompatible with the return type of the parent method ReflectionMethod::getFileName of type string. It seems like you forgot to handle an error condition.
Loading history...
142
    }
143
144
    /**
145
     * {@inheritDoc}
146
     */
147 1
    public function getName()
148
    {
149 1
        return $this->betterReflectionMethod->getName();
150
    }
151
152
    /**
153
     * {@inheritDoc}
154
     */
155 1
    public function getNamespaceName()
156
    {
157 1
        return $this->betterReflectionMethod->getNamespaceName();
158
    }
159
160
    /**
161
     * {@inheritDoc}
162
     */
163 1
    public function getNumberOfParameters()
164
    {
165 1
        return $this->betterReflectionMethod->getNumberOfParameters();
166
    }
167
168
    /**
169
     * {@inheritDoc}
170
     */
171 1
    public function getNumberOfRequiredParameters()
172
    {
173 1
        return $this->betterReflectionMethod->getNumberOfRequiredParameters();
174
    }
175
176
    /**
177
     * {@inheritDoc}
178
     */
179 1
    public function getParameters()
180
    {
181 1
        $parameters = $this->betterReflectionMethod->getParameters();
182
183 1
        $wrappedParameters = [];
184 1
        foreach ($parameters as $key => $parameter) {
185 1
            $wrappedParameters[$key] = new ReflectionParameter($parameter);
186
        }
187
188 1
        return $wrappedParameters;
189
    }
190
191
    /**
192
     * {@inheritDoc}
193
     */
194 1
    public function getReturnType()
195
    {
196 1
        return ReflectionNamedType::fromReturnTypeOrNull($this->betterReflectionMethod->getReturnType());
197
    }
198
199
    /**
200
     * {@inheritDoc}
201
     */
202 1
    public function getShortName()
203
    {
204 1
        return $this->betterReflectionMethod->getShortName();
205
    }
206
207
    /**
208
     * {@inheritDoc}
209
     */
210 1
    public function getStartLine()
211
    {
212 1
        return $this->betterReflectionMethod->getStartLine();
213
    }
214
215
    /**
216
     * {@inheritDoc}
217
     */
218 1
    public function getStaticVariables()
219
    {
220 1
        throw new NotImplemented('Not implemented');
221
    }
222
223
    /**
224
     * {@inheritDoc}
225
     */
226 1
    public function returnsReference()
227
    {
228 1
        return $this->betterReflectionMethod->returnsReference();
229
    }
230
231
    /**
232
     * {@inheritDoc}
233
     */
234 1
    public function isGenerator()
235
    {
236 1
        return $this->betterReflectionMethod->isGenerator();
237
    }
238
239
    /**
240
     * {@inheritDoc}
241
     */
242 1
    public function isVariadic()
243
    {
244 1
        return $this->betterReflectionMethod->isVariadic();
245
    }
246
247
    /**
248
     * {@inheritDoc}
249
     */
250 10
    public function isPublic()
251
    {
252 10
        return $this->betterReflectionMethod->isPublic();
253
    }
254
255
    /**
256
     * {@inheritDoc}
257
     */
258 1
    public function isPrivate()
259
    {
260 1
        return $this->betterReflectionMethod->isPrivate();
261
    }
262
263
    /**
264
     * {@inheritDoc}
265
     */
266 1
    public function isProtected()
267
    {
268 1
        return $this->betterReflectionMethod->isProtected();
269
    }
270
271
    /**
272
     * {@inheritDoc}
273
     */
274 1
    public function isAbstract()
275
    {
276 1
        return $this->betterReflectionMethod->isAbstract();
277
    }
278
279
    /**
280
     * {@inheritDoc}
281
     */
282 1
    public function isFinal()
283
    {
284 1
        return $this->betterReflectionMethod->isFinal();
285
    }
286
287
    /**
288
     * {@inheritDoc}
289
     */
290 1
    public function isStatic()
291
    {
292 1
        return $this->betterReflectionMethod->isStatic();
293
    }
294
295
    /**
296
     * {@inheritDoc}
297
     */
298 1
    public function isConstructor()
299
    {
300 1
        return $this->betterReflectionMethod->isConstructor();
301
    }
302
303
    /**
304
     * {@inheritDoc}
305
     */
306 1
    public function isDestructor()
307
    {
308 1
        return $this->betterReflectionMethod->isDestructor();
309
    }
310
311
    /**
312
     * {@inheritDoc}
313
     */
314 4
    public function getClosure($object = null)
315
    {
316
        try {
317 4
            return $this->betterReflectionMethod->getClosure($object);
318 3
        } catch (NoObjectProvided | NotAnObject $e) {
319 2
            return null;
320 1
        } catch (Throwable $e) {
321 1
            throw new CoreReflectionException($e->getMessage(), 0, $e);
322
        }
323
    }
324
325
    /**
326
     * {@inheritDoc}
327
     */
328 1
    public function getModifiers()
329
    {
330 1
        return $this->betterReflectionMethod->getModifiers();
331
    }
332
333
    /**
334
     * {@inheritDoc}
335
     */
336 4
    public function invoke($object = null, $args = null)
337
    {
338 4
        if (! $this->isAccessible()) {
339 1
            throw new CoreReflectionException('Method not accessible');
340
        }
341
342
        try {
343 3
            return $this->betterReflectionMethod->invoke(...func_get_args());
344 2
        } catch (NoObjectProvided | NotAnObject $e) {
345 1
            return null;
346 1
        } catch (Throwable $e) {
347 1
            throw new CoreReflectionException($e->getMessage(), 0, $e);
348
        }
349
    }
350
351
    /**
352
     * {@inheritDoc}
353
     */
354 5
    public function invokeArgs($object = null, array $args = [])
355
    {
356 5
        if (! $this->isAccessible()) {
357 1
            throw new CoreReflectionException('Method not accessible');
358
        }
359
360
        try {
361 4
            return $this->betterReflectionMethod->invokeArgs($object, $args);
362 3
        } catch (NoObjectProvided | NotAnObject $e) {
363 2
            return null;
364 1
        } catch (Throwable $e) {
365 1
            throw new CoreReflectionException($e->getMessage(), 0, $e);
366
        }
367
    }
368
369
    /**
370
     * {@inheritDoc}
371
     */
372 1
    public function getDeclaringClass()
373
    {
374 1
        return new ReflectionClass($this->betterReflectionMethod->getImplementingClass());
375
    }
376
377
    /**
378
     * {@inheritDoc}
379
     */
380 1
    public function getPrototype()
381
    {
382 1
        return new self($this->betterReflectionMethod->getPrototype());
383
    }
384
385
    /**
386
     * {@inheritDoc}
387
     */
388
    public function setAccessible($accessible)
389
    {
390
        $this->accessible = true;
391
    }
392
393 9
    private function isAccessible() : bool
394
    {
395 9
        return $this->accessible || $this->isPublic();
396
    }
397
}
398