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/ReflectionObject.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;
6
7
use InvalidArgumentException;
8
use PhpParser\Builder\Property as PropertyNodeBuilder;
9
use PhpParser\Node\Stmt\ClassLike as ClassLikeNode;
10
use PhpParser\Node\Stmt\Namespace_;
11
use PhpParser\Node\Stmt\Property as PropertyNode;
12
use ReflectionException;
13
use ReflectionObject as CoreReflectionObject;
14
use ReflectionProperty as CoreReflectionProperty;
15
use Roave\BetterReflection\BetterReflection;
16
use Roave\BetterReflection\Reflector\ClassReflector;
17
use Roave\BetterReflection\Reflector\Exception\IdentifierNotFound;
18
use Roave\BetterReflection\Reflector\Reflector;
19
use Roave\BetterReflection\SourceLocator\Located\LocatedSource;
20
use Roave\BetterReflection\SourceLocator\Type\AnonymousClassObjectSourceLocator;
21
use function array_merge;
22
use function get_class;
23
use function is_object;
24
use function strpos;
25
26
class ReflectionObject extends ReflectionClass
27
{
28
    /** @var ReflectionClass */
29
    private $reflectionClass;
30
31
    /** @var object */
32
    private $object;
33
34
    /** @var Reflector */
35
    private $reflector;
36
37
    /**
38
     * @param object $object
39
     */
40 71
    private function __construct(Reflector $reflector, ReflectionClass $reflectionClass, $object)
0 ignored issues
show
Consider using a different method name as you override a private method of the parent class.

Overwriting private methods is generally fine as long as you also use private visibility. It might still be preferable for understandability to use a different method name.

Loading history...
41
    {
42 71
        $this->reflector       = $reflector;
43 71
        $this->reflectionClass = $reflectionClass;
44 71
        $this->object          = $object;
45 71
    }
46
47
    /**
48
     * Pass an instance of an object to this method to reflect it
49
     *
50
     * @param object $object
51
     *
52
     * @throws ReflectionException
53
     * @throws InvalidArgumentException
54
     * @throws IdentifierNotFound
55
     *
56
     * @psalm-suppress DocblockTypeContradiction
57
     */
58 72
    public static function createFromInstance($object) : ReflectionClass
59
    {
60 72
        if (! is_object($object)) {
61 1
            throw new InvalidArgumentException('Can only create from an instance of an object');
62
        }
63
64 71
        $className = get_class($object);
65
66 71
        if (strpos($className, ReflectionClass::ANONYMOUS_CLASS_NAME_PREFIX) === 0) {
67 3
            $reflector = new ClassReflector(new AnonymousClassObjectSourceLocator(
68 3
                $object,
69 3
                (new BetterReflection())->phpParser()
70
            ));
71
        } else {
72 68
            $reflector = (new BetterReflection())->classReflector();
73
        }
74
75 71
        return new self($reflector, $reflector->reflect($className), $object);
76
    }
77
78
    /**
79
     * Reflect on runtime properties for the current instance
80
     *
81
     * @see ReflectionClass::getProperties() for the usage of $filter
82
     *
83
     * @return ReflectionProperty[]
84
     *
85
     * @psalm-return array<string, ReflectionProperty>
86
     */
87 8
    private function getRuntimeProperties(?int $filter = null) : array
88
    {
89 8
        if (! $this->reflectionClass->isInstance($this->object)) {
90 1
            throw new InvalidArgumentException('Cannot reflect runtime properties of a separate class');
91
        }
92
93
        // Ensure we have already cached existing properties so we can add to them
94 7
        $this->reflectionClass->getProperties();
95
96
        // Only known current way is to use internal ReflectionObject to get
97
        // the runtime-declared properties  :/
98 7
        $reflectionProperties = (new CoreReflectionObject($this->object))->getProperties();
99 7
        $runtimeProperties    = [];
100
101 7
        foreach ($reflectionProperties as $property) {
102 3
            if ($this->reflectionClass->hasProperty($property->getName())) {
103 1
                continue;
104
            }
105
106 3
            $reflectionProperty = $this->reflectionClass->getProperty($property->getName());
107
108 3
            $runtimeProperty = ReflectionProperty::createFromNode(
109 3
                $this->reflector,
110 3
                $this->createPropertyNodeFromReflection($property, $this->object),
111 3
                0,
112 3
                $reflectionProperty
113
                    ? $reflectionProperty->getDeclaringClass()->getDeclaringNamespaceAst()
114 3
                    : null,
115 3
                $this,
116 3
                $this,
117 3
                false
118
            );
119
120 3
            if ($filter !== null && ! ($filter & $runtimeProperty->getModifiers())) {
121 2
                continue;
122
            }
123
124 3
            $runtimeProperties[$runtimeProperty->getName()] = $runtimeProperty;
125
        }
126
127 7
        return $runtimeProperties;
128
    }
129
130
    /**
131
     * Create an AST PropertyNode given a reflection
132
     *
133
     * Note that we don't copy across DocBlock, protected, private or static
134
     * because runtime properties can't have these attributes.
135
     *
136
     * @param object $instance
137
     */
138 3
    private function createPropertyNodeFromReflection(CoreReflectionProperty $property, $instance) : PropertyNode
139
    {
140 3
        $builder = new PropertyNodeBuilder($property->getName());
141 3
        $builder->setDefault($property->getValue($instance));
142
143 3
        if ($property->isPublic()) {
144 3
            $builder->makePublic();
145
        }
146
147 3
        return $builder->getNode();
148
    }
149
150 1
    public function getShortName() : string
151
    {
152 1
        return $this->reflectionClass->getShortName();
153
    }
154
155 6
    public function getName() : string
156
    {
157 6
        return $this->reflectionClass->getName();
158
    }
159
160 1
    public function getNamespaceName() : string
161
    {
162 1
        return $this->reflectionClass->getNamespaceName();
163
    }
164
165 4
    public function inNamespace() : bool
166
    {
167 4
        return $this->reflectionClass->inNamespace();
168
    }
169
170 3
    public function getExtensionName() : ?string
171
    {
172 3
        return $this->reflectionClass->getExtensionName();
173
    }
174
175
    /**
176
     * {@inheritdoc}
177
     */
178 1
    public function getMethods(?int $filter = null) : array
179
    {
180 1
        return $this->reflectionClass->getMethods($filter);
181
    }
182
183
    /**
184
     * {@inheritdoc}
185
     */
186 1
    public function getImmediateMethods(?int $filter = null) : array
187
    {
188 1
        return $this->reflectionClass->getImmediateMethods($filter);
189
    }
190
191 1
    public function getMethod(string $methodName) : ReflectionMethod
192
    {
193 1
        return $this->reflectionClass->getMethod($methodName);
194
    }
195
196 1
    public function hasMethod(string $methodName) : bool
197
    {
198 1
        return $this->reflectionClass->hasMethod($methodName);
199
    }
200
201
    /**
202
     * {@inheritdoc}
203
     */
204 1
    public function getImmediateConstants() : array
205
    {
206 1
        return $this->reflectionClass->getImmediateConstants();
207
    }
208
209
    /**
210
     * {@inheritdoc}
211
     */
212 1
    public function getConstants() : array
213
    {
214 1
        return $this->reflectionClass->getConstants();
215
    }
216
217
    /**
218
     * {@inheritdoc}
219
     */
220 1
    public function getConstant(string $name)
221
    {
222 1
        return $this->reflectionClass->getConstant($name);
223
    }
224
225 1
    public function hasConstant(string $name) : bool
226
    {
227 1
        return $this->reflectionClass->hasConstant($name);
228
    }
229
230 1
    public function getReflectionConstant(string $name) : ?ReflectionClassConstant
231
    {
232 1
        return $this->reflectionClass->getReflectionConstant($name);
233
    }
234
235
    /**
236
     * {@inheritdoc}
237
     */
238 1
    public function getImmediateReflectionConstants() : array
239
    {
240 1
        return $this->reflectionClass->getImmediateReflectionConstants();
241
    }
242
243
    /**
244
     * {@inheritdoc}
245
     */
246 1
    public function getReflectionConstants() : array
247
    {
248 1
        return $this->reflectionClass->getReflectionConstants();
249
    }
250
251 1
    public function getConstructor() : ReflectionMethod
252
    {
253 1
        return $this->reflectionClass->getConstructor();
254
    }
255
256
    /**
257
     * {@inheritdoc}
258
     */
259 3
    public function getProperties(?int $filter = null) : array
260
    {
261 3
        return array_merge(
262 3
            $this->reflectionClass->getProperties($filter),
263 3
            $this->getRuntimeProperties($filter)
264
        );
265
    }
266
267
    /**
268
     * {@inheritdoc}
269
     */
270 2
    public function getImmediateProperties(?int $filter = null) : array
271
    {
272 2
        return array_merge(
273 2
            $this->reflectionClass->getImmediateProperties($filter),
274 2
            $this->getRuntimeProperties($filter)
275
        );
276
    }
277
278 2
    public function getProperty(string $name) : ?ReflectionProperty
279
    {
280 2
        $runtimeProperties = $this->getRuntimeProperties();
281
282 2
        if (isset($runtimeProperties[$name])) {
283 1
            return $runtimeProperties[$name];
284
        }
285
286 1
        return $this->reflectionClass->getProperty($name);
287
    }
288
289 1
    public function hasProperty(string $name) : bool
290
    {
291 1
        $runtimeProperties = $this->getRuntimeProperties();
292
293 1
        return isset($runtimeProperties[$name]) || $this->reflectionClass->hasProperty($name);
294
    }
295
296
    /**
297
     * {@inheritdoc}
298
     */
299 1
    public function getDefaultProperties() : array
300
    {
301 1
        return $this->reflectionClass->getDefaultProperties();
302
    }
303
304 3
    public function getFileName() : ?string
305
    {
306 3
        return $this->reflectionClass->getFileName();
307
    }
308
309 1
    public function getLocatedSource() : LocatedSource
310
    {
311 1
        return $this->reflectionClass->getLocatedSource();
312
    }
313
314 3
    public function getStartLine() : int
315
    {
316 3
        return $this->reflectionClass->getStartLine();
317
    }
318
319 3
    public function getEndLine() : int
320
    {
321 3
        return $this->reflectionClass->getEndLine();
322
    }
323
324 1
    public function getStartColumn() : int
325
    {
326 1
        return $this->reflectionClass->getStartColumn();
327
    }
328
329 1
    public function getEndColumn() : int
330
    {
331 1
        return $this->reflectionClass->getEndColumn();
332
    }
333
334 1
    public function getParentClass() : ?ReflectionClass
335
    {
336 1
        return $this->reflectionClass->getParentClass();
337
    }
338
339
    /**
340
     * {@inheritdoc}
341
     */
342 1
    public function getParentClassNames() : array
343
    {
344 1
        return $this->reflectionClass->getParentClassNames();
345
    }
346
347 1
    public function getDocComment() : string
348
    {
349 1
        return $this->reflectionClass->getDocComment();
350
    }
351
352 4
    public function isAnonymous() : bool
353
    {
354 4
        return $this->reflectionClass->isAnonymous();
355
    }
356
357 3
    public function isInternal() : bool
358
    {
359 3
        return $this->reflectionClass->isInternal();
360
    }
361
362 1
    public function isUserDefined() : bool
363
    {
364 1
        return $this->reflectionClass->isUserDefined();
365
    }
366
367 1
    public function isAbstract() : bool
368
    {
369 1
        return $this->reflectionClass->isAbstract();
370
    }
371
372 1
    public function isFinal() : bool
373
    {
374 1
        return $this->reflectionClass->isFinal();
375
    }
376
377 1
    public function getModifiers() : int
378
    {
379 1
        return $this->reflectionClass->getModifiers();
380
    }
381
382 1
    public function isTrait() : bool
383
    {
384 1
        return $this->reflectionClass->isTrait();
385
    }
386
387 1
    public function isInterface() : bool
388
    {
389 1
        return $this->reflectionClass->isInterface();
390
    }
391
392
    /**
393
     * {@inheritdoc}
394
     */
395 1
    public function getTraits() : array
396
    {
397 1
        return $this->reflectionClass->getTraits();
398
    }
399
400
    /**
401
     * {@inheritdoc}
402
     */
403 1
    public function getTraitNames() : array
404
    {
405 1
        return $this->reflectionClass->getTraitNames();
406
    }
407
408
    /**
409
     * {@inheritdoc}
410
     */
411 1
    public function getTraitAliases() : array
412
    {
413 1
        return $this->reflectionClass->getTraitAliases();
414
    }
415
416
    /**
417
     * {@inheritdoc}
418
     */
419 1
    public function getInterfaces() : array
420
    {
421 1
        return $this->reflectionClass->getInterfaces();
422
    }
423
424
    /**
425
     * {@inheritdoc}
426
     */
427 1
    public function getImmediateInterfaces() : array
428
    {
429 1
        return $this->reflectionClass->getImmediateInterfaces();
430
    }
431
432
    /**
433
     * {@inheritdoc}
434
     */
435 2
    public function getInterfaceNames() : array
436
    {
437 2
        return $this->reflectionClass->getInterfaceNames();
438
    }
439
440
    /**
441
     * {@inheritdoc}
442
     */
443 1
    public function isInstance($object) : bool
444
    {
445 1
        return $this->reflectionClass->isInstance($object);
446
    }
447
448 1
    public function isSubclassOf(string $className) : bool
449
    {
450 1
        return $this->reflectionClass->isSubclassOf($className);
451
    }
452
453 1
    public function implementsInterface(string $interfaceName) : bool
454
    {
455 1
        return $this->reflectionClass->implementsInterface($interfaceName);
456
    }
457
458 2
    public function isInstantiable() : bool
459
    {
460 2
        return $this->reflectionClass->isInstantiable();
461
    }
462
463 1
    public function isCloneable() : bool
464
    {
465 1
        return $this->reflectionClass->isCloneable();
466
    }
467
468 1
    public function isIterateable() : bool
469
    {
470 1
        return $this->reflectionClass->isIterateable();
471
    }
472
473
    /**
474
     * {@inheritdoc}
475
     */
476 1
    public function getStaticProperties() : array
477
    {
478 1
        return $this->reflectionClass->getStaticProperties();
479
    }
480
481
    /**
482
     * {@inheritdoc}
483
     */
484 1
    public function setStaticPropertyValue(string $propertyName, $value) : void
485
    {
486 1
        $this->reflectionClass->setStaticPropertyValue($propertyName, $value);
487 1
    }
488
489
    /**
490
     * {@inheritdoc}
491
     */
492 1
    public function getStaticPropertyValue(string $propertyName)
493
    {
494 1
        return $this->reflectionClass->getStaticPropertyValue($propertyName);
495
    }
496
497 1
    public function getAst() : ClassLikeNode
498
    {
499 1
        return $this->reflectionClass->getAst();
500
    }
501
502 1
    public function getDeclaringNamespaceAst() : ?Namespace_
503
    {
504 1
        return $this->reflectionClass->getDeclaringNamespaceAst();
505
    }
506
507 1
    public function setFinal(bool $isFinal) : void
508
    {
509 1
        $this->reflectionClass->setFinal($isFinal);
510 1
    }
511
512 1
    public function removeMethod(string $methodName) : bool
513
    {
514 1
        return $this->reflectionClass->removeMethod($methodName);
515
    }
516
517 1
    public function addMethod(string $methodName) : void
518
    {
519 1
        $this->reflectionClass->addMethod($methodName);
520 1
    }
521
522 1
    public function removeProperty(string $methodName) : bool
523
    {
524 1
        return $this->reflectionClass->removeProperty($methodName);
525
    }
526
527 1
    public function addProperty(
528
        string $methodName,
529
        int $visibility = CoreReflectionProperty::IS_PUBLIC,
530
        bool $static = false
531
    ) : void {
532 1
        $this->reflectionClass->addProperty($methodName, $visibility, $static);
533 1
    }
534
}
535