Issues (127)

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