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/ReflectionClass.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 InvalidArgumentException;
8
use OutOfBoundsException;
9
use ReflectionClass as CoreReflectionClass;
10
use ReflectionException as CoreReflectionException;
11
use Roave\BetterReflection\Reflection\ReflectionClass as BetterReflectionClass;
12
use Roave\BetterReflection\Reflection\ReflectionClassConstant as BetterReflectionClassConstant;
13
use Roave\BetterReflection\Reflection\ReflectionMethod as BetterReflectionMethod;
14
use Roave\BetterReflection\Reflection\ReflectionObject as BetterReflectionObject;
15
use function array_combine;
16
use function array_map;
17
use function func_num_args;
18
use function is_object;
19
use function is_string;
20
use function sprintf;
21
use function strtolower;
22
23
class ReflectionClass extends CoreReflectionClass
24
{
25
    /** @var BetterReflectionClass */
26
    private $betterReflectionClass;
27
28 66
    public function __construct(BetterReflectionClass $betterReflectionClass)
29
    {
30 66
        $this->betterReflectionClass = $betterReflectionClass;
31 66
    }
32
33
    /**
34
     * {@inheritDoc}
35
     *
36
     * @throws CoreReflectionException
37
     */
38 1
    public static function export($argument, $return = false)
39
    {
40 1
        if (is_string($argument) || is_object($argument)) {
41 1
            if (is_string($argument)) {
42 1
                $output = BetterReflectionClass::createFromName($argument)->__toString();
43
            } else {
44
                $output = BetterReflectionObject::createFromInstance($argument)->__toString();
45
            }
46
47 1
            if ($return) {
48 1
                return $output;
49
            }
50
51
            echo $output;
52
53
            return null;
54
        }
55
56
        throw new InvalidArgumentException('Class name must be provided');
57
    }
58
59
    /**
60
     * {@inheritDoc}
61
     */
62 1
    public function __toString()
63
    {
64 1
        return $this->betterReflectionClass->__toString();
65
    }
66
67
    /**
68
     * {@inheritDoc}
69
     */
70 1
    public function getName()
71
    {
72 1
        return $this->betterReflectionClass->getName();
73
    }
74
75
    /**
76
     * {@inheritDoc}
77
     */
78 1
    public function isAnonymous()
79
    {
80 1
        return $this->betterReflectionClass->isAnonymous();
81
    }
82
83
    /**
84
     * {@inheritDoc}
85
     */
86 1
    public function isInternal()
87
    {
88 1
        return $this->betterReflectionClass->isInternal();
89
    }
90
91
    /**
92
     * {@inheritDoc}
93
     */
94 1
    public function isUserDefined()
95
    {
96 1
        return $this->betterReflectionClass->isUserDefined();
97
    }
98
99
    /**
100
     * {@inheritDoc}
101
     */
102 1
    public function isInstantiable()
103
    {
104 1
        return $this->betterReflectionClass->isInstantiable();
105
    }
106
107
    /**
108
     * {@inheritDoc}
109
     */
110 1
    public function isCloneable()
111
    {
112 1
        return $this->betterReflectionClass->isCloneable();
113
    }
114
115
    /**
116
     * {@inheritDoc}
117
     */
118 2
    public function getFileName()
119
    {
120 2
        return $this->betterReflectionClass->getFileName() ?? false;
121
    }
122
123
    /**
124
     * {@inheritDoc}
125
     */
126 1
    public function getStartLine()
127
    {
128 1
        return $this->betterReflectionClass->getStartLine();
129
    }
130
131
    /**
132
     * {@inheritDoc}
133
     */
134 1
    public function getEndLine()
135
    {
136 1
        return $this->betterReflectionClass->getEndLine();
137
    }
138
139
    /**
140
     * {@inheritDoc}
141
     */
142 2
    public function getDocComment()
143
    {
144 2
        return $this->betterReflectionClass->getDocComment() ?: false;
145
    }
146
147
    /**
148
     * {@inheritDoc}
149
     */
150 2
    public function getConstructor()
151
    {
152
        try {
153 2
            return new ReflectionMethod($this->betterReflectionClass->getConstructor());
154 1
        } catch (OutOfBoundsException $e) {
155 1
            return null;
156
        }
157
    }
158
159
    /**
160
     * {@inheritDoc}
161
     */
162 2
    public function hasMethod($name)
163
    {
164 2
        return $this->betterReflectionClass->hasMethod($this->getMethodRealName($name));
165
    }
166
167
    /**
168
     * {@inheritDoc}
169
     */
170 2
    public function getMethod($name)
171
    {
172 2
        return new ReflectionMethod($this->betterReflectionClass->getMethod($this->getMethodRealName($name)));
173
    }
174
175 4
    private function getMethodRealName(string $name) : string
176
    {
177
        $realMethodNames = array_map(static function (BetterReflectionMethod $method) : string {
178 2
            return $method->getName();
179 4
        }, $this->betterReflectionClass->getMethods());
180
181
        $methodNames = array_combine(array_map(static function (string $methodName) : string {
182 2
            return strtolower($methodName);
183 4
        }, $realMethodNames), $realMethodNames);
184
185 4
        return $methodNames[strtolower($name)] ?? $name;
186
    }
187
188
    /**
189
     * {@inheritDoc}
190
     */
191 1
    public function getMethods($filter = null)
192
    {
193 1
        $methods = $this->betterReflectionClass->getMethods();
194
195 1
        $wrappedMethods = [];
196 1
        foreach ($methods as $key => $method) {
197 1
            $wrappedMethods[$key] = new ReflectionMethod($method);
198
        }
199
200 1
        return $wrappedMethods;
201
    }
202
203
    /**
204
     * {@inheritDoc}
205
     */
206 1
    public function hasProperty($name)
207
    {
208 1
        return $this->betterReflectionClass->hasProperty($name);
209
    }
210
211
    /**
212
     * {@inheritDoc}
213
     */
214 2
    public function getProperty($name)
215
    {
216 2
        $betterReflectionProperty = $this->betterReflectionClass->getProperty($name);
217
218 2
        if ($betterReflectionProperty === null) {
219 1
            throw new CoreReflectionException(sprintf('Property "%s" does not exist', $name));
220
        }
221
222 1
        return new ReflectionProperty($betterReflectionProperty);
223
    }
224
225
    /**
226
     * {@inheritDoc}
227
     */
228 1
    public function getProperties($filter = null)
229
    {
230 1
        $properties = $this->betterReflectionClass->getProperties();
231
232 1
        $wrappedProperties = [];
233 1
        foreach ($properties as $key => $property) {
234 1
            $wrappedProperties[$key] = new ReflectionProperty($property);
235
        }
236
237 1
        return $wrappedProperties;
238
    }
239
240
    /**
241
     * {@inheritDoc}
242
     */
243 1
    public function hasConstant($name)
244
    {
245 1
        return $this->betterReflectionClass->hasConstant($name);
246
    }
247
248
    /**
249
     * {@inheritDoc}
250
     */
251 1
    public function getConstants()
252
    {
253 1
        return $this->betterReflectionClass->getConstants();
254
    }
255
256
    /**
257
     * {@inheritDoc}
258
     */
259 1
    public function getConstant($name)
260
    {
261 1
        return $this->betterReflectionClass->getConstant($name);
262
    }
263
264
    /**
265
     * {@inheritdoc}
266
     */
267 1
    public function getReflectionConstant($name)
268
    {
269 1
        return new ReflectionClassConstant(
270 1
            $this->betterReflectionClass->getReflectionConstant($name)
271
        );
272
    }
273
274
    /**
275
     * {@inheritdoc}
276
     *
277
     * @psalm-suppress InvalidReturnType see #530
278
     */
279 1
    public function getReflectionConstants()
280
    {
281
        return array_map(static function (BetterReflectionClassConstant $betterConstant) : ReflectionClassConstant {
282 1
            return new ReflectionClassConstant($betterConstant);
283 1
        }, $this->betterReflectionClass->getReflectionConstants());
284
    }
285
286
    /**
287
     * {@inheritDoc}
288
     */
289 1
    public function getInterfaces()
290
    {
291 1
        $interfaces = $this->betterReflectionClass->getInterfaces();
292
293 1
        $wrappedInterfaces = [];
294 1
        foreach ($interfaces as $key => $interface) {
295 1
            $wrappedInterfaces[$key] = new self($interface);
296
        }
297
298 1
        return $wrappedInterfaces;
299
    }
300
301
    /**
302
     * {@inheritDoc}
303
     */
304 1
    public function getInterfaceNames()
305
    {
306 1
        return $this->betterReflectionClass->getInterfaceNames();
307
    }
308
309
    /**
310
     * {@inheritDoc}
311
     */
312 1
    public function isInterface()
313
    {
314 1
        return $this->betterReflectionClass->isInterface();
315
    }
316
317
    /**
318
     * {@inheritDoc}
319
     *
320
     * @psalm-suppress InvalidReturnType see #530
321
     */
322 1
    public function getTraits()
323
    {
324 1
        $traits = $this->betterReflectionClass->getTraits();
325
326 1
        $wrappedTraits = [];
327 1
        foreach ($traits as $key => $trait) {
328 1
            $wrappedTraits[$key] = new self($trait);
329
        }
330
331 1
        return $wrappedTraits;
332
    }
333
334
    /**
335
     * {@inheritDoc}
336
     */
337 1
    public function getTraitNames()
338
    {
339 1
        return $this->betterReflectionClass->getTraitNames();
340
    }
341
342
    /**
343
     * {@inheritDoc}
344
     */
345 1
    public function getTraitAliases()
346
    {
347 1
        return $this->betterReflectionClass->getTraitAliases();
348
    }
349
350
    /**
351
     * {@inheritDoc}
352
     */
353 1
    public function isTrait()
354
    {
355 1
        return $this->betterReflectionClass->isTrait();
356
    }
357
358
    /**
359
     * {@inheritDoc}
360
     */
361 1
    public function isAbstract()
362
    {
363 1
        return $this->betterReflectionClass->isAbstract();
364
    }
365
366
    /**
367
     * {@inheritDoc}
368
     */
369 1
    public function isFinal()
370
    {
371 1
        return $this->betterReflectionClass->isFinal();
372
    }
373
374
    /**
375
     * {@inheritDoc}
376
     */
377 1
    public function getModifiers()
378
    {
379 1
        return $this->betterReflectionClass->getModifiers();
380
    }
381
382
    /**
383
     * {@inheritDoc}
384
     */
385 1
    public function isInstance($object)
386
    {
387 1
        return $this->betterReflectionClass->isInstance($object);
388
    }
389
390
    /**
391
     * {@inheritDoc}
392
     */
393 1
    public function newInstance($arg = null, ...$args)
0 ignored issues
show
The parameter $args is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
394
    {
395 1
        throw new Exception\NotImplemented('Not implemented');
396
    }
397
398
    /**
399
     * {@inheritDoc}
400
     */
401 1
    public function newInstanceWithoutConstructor()
402
    {
403 1
        throw new Exception\NotImplemented('Not implemented');
404
    }
405
406
    /**
407
     * {@inheritDoc}
408
     */
409 1
    public function newInstanceArgs(?array $args = null)
410
    {
411 1
        throw new Exception\NotImplemented('Not implemented');
412
    }
413
414
    /**
415
     * {@inheritDoc}
416
     */
417 2
    public function getParentClass()
418
    {
419 2
        $parentClass = $this->betterReflectionClass->getParentClass();
420
421 2
        if ($parentClass === null) {
422 1
            return false;
423
        }
424
425 1
        return new self($parentClass);
426
    }
427
428
    /**
429
     * {@inheritDoc}
430
     */
431 3
    public function isSubclassOf($class)
432
    {
433 3
        $realParentClassNames = $this->betterReflectionClass->getParentClassNames();
434
435
        $parentClassNames = array_combine(array_map(static function (string $parentClassName) : string {
436 1
            return strtolower($parentClassName);
437 3
        }, $realParentClassNames), $realParentClassNames);
438
439 3
        $realParentClassName = $parentClassNames[strtolower($class)] ?? $class;
440
441 3
        return $this->betterReflectionClass->isSubclassOf($realParentClassName) || $this->implementsInterface($class);
442
    }
443
444
    /**
445
     * {@inheritDoc}
446
     */
447 1
    public function getStaticProperties()
448
    {
449 1
        return $this->betterReflectionClass->getStaticProperties();
450
    }
451
452
    /**
453
     * {@inheritDoc}
454
     */
455 4
    public function getStaticPropertyValue($name, $default = null)
456
    {
457 4
        $betterReflectionProperty = $this->betterReflectionClass->getProperty($name);
458
459 4
        if ($betterReflectionProperty === null) {
460 2
            if (func_num_args() === 2) {
461 1
                return $default;
462
            }
463
464 1
            throw new CoreReflectionException(sprintf('Property "%s" does not exist', $name));
465
        }
466
467 2
        $property = new ReflectionProperty($betterReflectionProperty);
468
469 2
        if (! $property->isAccessible()) {
470 1
            throw new CoreReflectionException(sprintf('Property "%s" is not accessible', $name));
471
        }
472
473 1
        if (! $property->isStatic()) {
474
            throw new CoreReflectionException(sprintf('Property "%s" is not static', $name));
475
        }
476
477 1
        return $property->getValue();
478
    }
479
480
    /**
481
     * {@inheritDoc}
482
     */
483 3
    public function setStaticPropertyValue($name, $value)
484
    {
485 3
        $betterReflectionProperty = $this->betterReflectionClass->getProperty($name);
486
487 3
        if ($betterReflectionProperty === null) {
488 1
            throw new CoreReflectionException(sprintf('Property "%s" does not exist', $name));
489
        }
490
491 2
        $property = new ReflectionProperty($betterReflectionProperty);
492
493 2
        if (! $property->isAccessible()) {
494 1
            throw new CoreReflectionException(sprintf('Property "%s" is not accessible', $name));
495
        }
496
497 1
        if (! $property->isStatic()) {
498
            throw new CoreReflectionException(sprintf('Property "%s" is not static', $name));
499
        }
500
501 1
        $property->setValue($value);
502 1
    }
503
504
    /**
505
     * {@inheritDoc}
506
     */
507 1
    public function getDefaultProperties()
508
    {
509 1
        return $this->betterReflectionClass->getDefaultProperties();
510
    }
511
512
    /**
513
     * {@inheritDoc}
514
     */
515 1
    public function isIterateable()
516
    {
517 1
        return $this->betterReflectionClass->isIterateable();
518
    }
519
520
    /**
521
     * {@inheritDoc}
522
     */
523 3
    public function implementsInterface($interface)
524
    {
525 3
        $realInterfaceNames = $this->betterReflectionClass->getInterfaceNames();
526
527
        $interfaceNames = array_combine(array_map(static function (string $interfaceName) : string {
528 2
            return strtolower($interfaceName);
529 3
        }, $realInterfaceNames), $realInterfaceNames);
530
531 3
        $realInterfaceName = $interfaceNames[strtolower($interface)] ?? $interface;
532
533 3
        return $this->betterReflectionClass->implementsInterface($realInterfaceName);
534
    }
535
536
    /**
537
     * {@inheritDoc}
538
     */
539 1
    public function getExtension()
540
    {
541 1
        throw new Exception\NotImplemented('Not implemented');
542
    }
543
544
    /**
545
     * {@inheritDoc}
546
     */
547 2
    public function getExtensionName()
548
    {
549 2
        return $this->betterReflectionClass->getExtensionName() ?? false;
550
    }
551
552
    /**
553
     * {@inheritDoc}
554
     */
555 1
    public function inNamespace()
556
    {
557 1
        return $this->betterReflectionClass->inNamespace();
558
    }
559
560
    /**
561
     * {@inheritDoc}
562
     */
563 1
    public function getNamespaceName()
564
    {
565 1
        return $this->betterReflectionClass->getNamespaceName();
566
    }
567
568
    /**
569
     * {@inheritDoc}
570
     */
571 1
    public function getShortName()
572
    {
573 1
        return $this->betterReflectionClass->getShortName();
574
    }
575
}
576