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.

StringCast/ReflectionClassStringCast.php (4 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\StringCast;
6
7
use Roave\BetterReflection\Reflection\ReflectionClass;
8
use Roave\BetterReflection\Reflection\ReflectionClassConstant;
9
use Roave\BetterReflection\Reflection\ReflectionMethod;
10
use Roave\BetterReflection\Reflection\ReflectionObject;
11
use Roave\BetterReflection\Reflection\ReflectionProperty;
12
use function array_filter;
13
use function array_map;
14
use function count;
15
use function implode;
16
use function preg_replace;
17
use function sprintf;
18
use function str_repeat;
19
use function strtolower;
20
use function trim;
21
22
/**
23
 * @internal
24
 */
25
final class ReflectionClassStringCast
26
{
27 6
    public static function toString(ReflectionClass $classReflection) : string
28
    {
29 6
        $isObject = $classReflection instanceof ReflectionObject;
30
31 6
        $format  = "%s [ <%s> %s%s%s %s%s%s ] {\n";
32 6
        $format .= "%s\n";
33 6
        $format .= "  - Constants [%d] {%s\n  }\n\n";
34 6
        $format .= "  - Static properties [%d] {%s\n  }\n\n";
35 6
        $format .= "  - Static methods [%d] {%s\n  }\n\n";
36 6
        $format .= "  - Properties [%d] {%s\n  }\n\n";
37 6
        $format .= ($isObject ? "  - Dynamic properties [%d] {%s\n  }\n\n" : '%s%s');
38 6
        $format .= "  - Methods [%d] {%s\n  }\n";
39 6
        $format .= "}\n";
40
41 6
        $type = self::typeToString($classReflection);
42
43 6
        $constants         = $classReflection->getReflectionConstants();
44 6
        $staticProperties  = self::getStaticProperties($classReflection);
45 6
        $staticMethods     = self::getStaticMethods($classReflection);
46 6
        $defaultProperties = self::getDefaultProperties($classReflection);
47 6
        $dynamicProperties = self::getDynamicProperties($classReflection);
48 6
        $methods           = self::getMethods($classReflection);
49
50 6
        return sprintf(
51 6
            $format,
52 6
            $isObject ? 'Object of class' : $type,
53 6
            self::sourceToString($classReflection),
54 6
            $classReflection->isFinal() ? 'final ' : '',
55 6
            $classReflection->isAbstract() ? 'abstract ' : '',
56 6
            strtolower($type),
57 6
            $classReflection->getName(),
58 6
            self::extendsToString($classReflection),
59 6
            self::implementsToString($classReflection),
60 6
            self::fileAndLinesToString($classReflection),
61 6
            count($constants),
62 6
            self::constantsToString($constants),
63 6
            count($staticProperties),
64 6
            self::propertiesToString($staticProperties),
65 6
            count($staticMethods),
66 6
            self::methodsToString($classReflection, $staticMethods),
67 6
            count($defaultProperties),
68 6
            self::propertiesToString($defaultProperties),
69 6
            $isObject ? count($dynamicProperties) : '',
70 6
            $isObject ? self::propertiesToString($dynamicProperties) : '',
71 6
            count($methods),
72 6
            self::methodsToString($classReflection, $methods, 2)
73
        );
74
    }
75
76 6
    private static function typeToString(ReflectionClass $classReflection) : string
77
    {
78 6
        if ($classReflection->isInterface()) {
79 1
            return 'Interface';
80
        }
81
82 5
        if ($classReflection->isTrait()) {
83 1
            return 'Trait';
84
        }
85
86 4
        return 'Class';
87
    }
88
89 6
    private static function sourceToString(ReflectionClass $classReflection) : string
90
    {
91 6
        if ($classReflection->isUserDefined()) {
92 5
            return 'user';
93
        }
94
95 1
        return sprintf('internal:%s', $classReflection->getExtensionName());
96
    }
97
98 6
    private static function extendsToString(ReflectionClass $classReflection) : string
99
    {
100 6
        $parentClass = $classReflection->getParentClass();
101
102 6
        if (! $parentClass) {
103 5
            return '';
104
        }
105
106 1
        return ' extends ' . $parentClass->getName();
107
    }
108
109 6
    private static function implementsToString(ReflectionClass $classReflection) : string
110
    {
111 6
        $interfaceNames = $classReflection->getInterfaceNames();
112
113 6
        if (! $interfaceNames) {
0 ignored issues
show
Bug Best Practice introduced by Jaroslav Hanslík
The expression $interfaceNames of type string[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
114 4
            return '';
115
        }
116
117 2
        return ' implements ' . implode(', ', $interfaceNames);
118
    }
119
120 6 View Code Duplication
    private static function fileAndLinesToString(ReflectionClass $classReflection) : string
121
    {
122 6
        if ($classReflection->isInternal()) {
123 1
            return '';
124
        }
125
126 5
        return sprintf("  @@ %s %d-%d\n", $classReflection->getFileName(), $classReflection->getStartLine(), $classReflection->getEndLine());
127
    }
128
129
    /**
130
     * @param ReflectionClassConstant[] $constants
131
     */
132 6
    private static function constantsToString(array $constants) : string
133
    {
134 6
        if (! $constants) {
0 ignored issues
show
Bug Best Practice introduced by Jaroslav Hanslík
The expression $constants of type Roave\BetterReflection\R...flectionClassConstant[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
135 5
            return '';
136
        }
137
138
        return self::itemsToString(array_map(static function (ReflectionClassConstant $constantReflection) : string {
139 1
            return trim(ReflectionClassConstantStringCast::toString($constantReflection));
140 1
        }, $constants));
141
    }
142
143
    /**
144
     * @param ReflectionProperty[] $properties
145
     */
146 6
    private static function propertiesToString(array $properties) : string
147
    {
148 6
        if (! $properties) {
0 ignored issues
show
Bug Best Practice introduced by Jaroslav Hanslík
The expression $properties of type Roave\BetterReflection\R...on\ReflectionProperty[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
149 5
            return '';
150
        }
151
152
        return self::itemsToString(array_map(static function (ReflectionProperty $propertyReflection) : string {
153 3
            return ReflectionPropertyStringCast::toString($propertyReflection);
154 3
        }, $properties));
155
    }
156
157
    /**
158
     * @param ReflectionMethod[] $methods
159
     */
160 6
    private static function methodsToString(ReflectionClass $classReflection, array $methods, int $emptyLinesAmongItems = 1) : string
161
    {
162 6
        if (! $methods) {
0 ignored issues
show
Bug Best Practice introduced by Jaroslav Hanslík
The expression $methods of type Roave\BetterReflection\R...tion\ReflectionMethod[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
163 5
            return '';
164
        }
165
166
        return self::itemsToString(array_map(static function (ReflectionMethod $method) use ($classReflection) : string {
167 2
            return ReflectionMethodStringCast::toString($method, $classReflection);
168 2
        }, $methods), $emptyLinesAmongItems);
169
    }
170
171
    /**
172
     * @param string[] $items
173
     */
174 3
    private static function itemsToString(array $items, int $emptyLinesAmongItems = 1) : string
175
    {
176 3
        $string = implode(str_repeat("\n", $emptyLinesAmongItems), $items);
177
178 3
        return "\n" . preg_replace('/(^|\n)(?!\n)/', '\1' . self::indent(), $string);
179
    }
180
181 3
    private static function indent() : string
182
    {
183 3
        return str_repeat(' ', 4);
184
    }
185
186
    /**
187
     * @return ReflectionProperty[]
188
     */
189 6
    private static function getStaticProperties(ReflectionClass $classReflection) : array
190
    {
191
        return array_filter($classReflection->getProperties(), static function (ReflectionProperty $propertyReflection) : bool {
192 3
            return $propertyReflection->isStatic();
193 6
        });
194
    }
195
196
    /**
197
     * @return ReflectionMethod[]
198
     */
199 6
    private static function getStaticMethods(ReflectionClass $classReflection) : array
200
    {
201
        return array_filter($classReflection->getMethods(), static function (ReflectionMethod $methodReflection) : bool {
202 2
            return $methodReflection->isStatic();
203 6
        });
204
    }
205
206
    /**
207
     * @return ReflectionProperty[]
208
     */
209 6
    private static function getDefaultProperties(ReflectionClass $classReflection) : array
210
    {
211
        return array_filter($classReflection->getProperties(), static function (ReflectionProperty $propertyReflection) : bool {
212 3
            return ! $propertyReflection->isStatic() && $propertyReflection->isDefault();
213 6
        });
214
    }
215
216
    /**
217
     * @return ReflectionProperty[]
218
     */
219 6
    private static function getDynamicProperties(ReflectionClass $classReflection) : array
220
    {
221
        return array_filter($classReflection->getProperties(), static function (ReflectionProperty $propertyReflection) : bool {
222 3
            return ! $propertyReflection->isStatic() && ! $propertyReflection->isDefault();
223 6
        });
224
    }
225
226
    /**
227
     * @return ReflectionMethod[]
228
     */
229 6
    private static function getMethods(ReflectionClass $classReflection) : array
230
    {
231
        return array_filter($classReflection->getMethods(), static function (ReflectionMethod $methodReflection) : bool {
232 2
            return ! $methodReflection->isStatic();
233 6
        });
234
    }
235
}
236