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/ReflectionMethod.php (1 issue)

Check for incompatible return types

Best Practice Bug Major

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