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/ReflectionClassConstant.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 PhpParser\Node\Stmt\ClassConst;
8
use ReflectionProperty;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Roave\BetterReflection\R...tion\ReflectionProperty.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
9
use Roave\BetterReflection\NodeCompiler\CompileNodeToValue;
10
use Roave\BetterReflection\NodeCompiler\CompilerContext;
11
use Roave\BetterReflection\Reflection\StringCast\ReflectionClassConstantStringCast;
12
use Roave\BetterReflection\Reflector\Reflector;
13
use Roave\BetterReflection\Util\CalculateReflectionColum;
14
use Roave\BetterReflection\Util\GetFirstDocComment;
15
16
class ReflectionClassConstant
17
{
18
    /** @var bool */
19
    private $valueWasCached = false;
20
21
    /**
22
     * @var bool|int|float|string|array<bool|int|float|string>|null const value
23
     * @psalm-var scalar|array<scalar>|null
24
     */
25
    private $value;
26
27
    /** @var Reflector */
28
    private $reflector;
29
30
    /** @var ReflectionClass Constant owner */
31
    private $owner;
32
33
    /** @var ClassConst */
34
    private $node;
35
36
    /** @var int */
37
    private $positionInNode;
38
39 21
    private function __construct()
40
    {
41 21
    }
42
43
    /**
44
     * Create a reflection of a class's constant by Const Node
45
     *
46
     * @internal
47
     *
48
     * @param ClassConst $node Node has to be processed by the PhpParser\NodeVisitor\NameResolver
49
     */
50 21
    public static function createFromNode(
51
        Reflector $reflector,
52
        ClassConst $node,
53
        int $positionInNode,
54
        ReflectionClass $owner
55
    ) : self {
56 21
        $ref                 = new self();
57 21
        $ref->node           = $node;
58 21
        $ref->positionInNode = $positionInNode;
59 21
        $ref->owner          = $owner;
60 21
        $ref->reflector      = $reflector;
61
62 21
        return $ref;
63
    }
64
65
    /**
66
     * Get the name of the reflection (e.g. if this is a ReflectionClass this
67
     * will be the class name).
68
     */
69 21
    public function getName() : string
70
    {
71 21
        return $this->node->consts[$this->positionInNode]->name->name;
72
    }
73
74
    /**
75
     * Returns constant value
76
     *
77
     * @return bool|int|float|string|array|null
78
     *
79
     * @psalm-return scalar|array<scalar>|null
80
     */
81 1
    public function getValue()
82
    {
83 1
        if ($this->valueWasCached !== false) {
84
            return $this->value;
85
        }
86
87 1
        $this->value          = (new CompileNodeToValue())->__invoke(
88 1
            $this->node->consts[$this->positionInNode]->value,
89 1
            new CompilerContext($this->reflector, $this->getDeclaringClass())
90
        );
91 1
        $this->valueWasCached = true;
92
93 1
        return $this->value;
94
    }
95
96
    /**
97
     * Constant is public
98
     */
99 6
    public function isPublic() : bool
100
    {
101 6
        return $this->node->isPublic();
102
    }
103
104
    /**
105
     * Constant is private
106
     */
107 6
    public function isPrivate() : bool
108
    {
109 6
        return $this->node->isPrivate();
110
    }
111
112
    /**
113
     * Constant is protected
114
     */
115 6
    public function isProtected() : bool
116
    {
117 6
        return $this->node->isProtected();
118
    }
119
120
    /**
121
     * Returns a bitfield of the access modifiers for this constant
122
     */
123 4
    public function getModifiers() : int
124
    {
125 4
        $val  = 0;
126 4
        $val += $this->isPublic() ? ReflectionProperty::IS_PUBLIC : 0;
127 4
        $val += $this->isProtected() ? ReflectionProperty::IS_PROTECTED : 0;
128 4
        $val += $this->isPrivate() ? ReflectionProperty::IS_PRIVATE : 0;
129
130 4
        return $val;
131
    }
132
133
    /**
134
     * Get the line number that this constant starts on.
135
     */
136 4
    public function getStartLine() : int
137
    {
138 4
        return $this->node->getStartLine();
139
    }
140
141
    /**
142
     * Get the line number that this constant ends on.
143
     */
144 4
    public function getEndLine() : int
145
    {
146 4
        return $this->node->getEndLine();
147
    }
148
149 3
    public function getStartColumn() : int
150
    {
151 3
        return CalculateReflectionColum::getStartColumn($this->owner->getLocatedSource()->getSource(), $this->node);
152
    }
153
154 3
    public function getEndColumn() : int
155
    {
156 3
        return CalculateReflectionColum::getEndColumn($this->owner->getLocatedSource()->getSource(), $this->node);
157
    }
158
159
    /**
160
     * Get the declaring class
161
     */
162 2
    public function getDeclaringClass() : ReflectionClass
163
    {
164 2
        return $this->owner;
165
    }
166
167
    /**
168
     * Returns the doc comment for this constant
169
     */
170 2
    public function getDocComment() : string
171
    {
172 2
        return GetFirstDocComment::forNode($this->node);
173
    }
174
175 1
    public function __toString() : string
176
    {
177 1
        return ReflectionClassConstantStringCast::toString($this);
178
    }
179
180 2
    public function getAst() : ClassConst
181
    {
182 2
        return $this->node;
183
    }
184
185 2
    public function getPositionInAst() : int
186
    {
187 2
        return $this->positionInNode;
188
    }
189
}
190