Issues (12)

Security Analysis    not enabled

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.php (5 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
if (!function_exists('short_class_name')) {
4
5
    /**
6
     * @param $object
7
     * @return string
8
     */
9
    function short_class_name($object): string
10
    {
11
        $objectProperties = new \ReflectionClass($object);
12
13
        return $objectProperties->getShortName();
14
    }
15
}
16
17
if (!function_exists('class_constants')) {
18
19
    /**
20
     * Get all class constants that starts with $startsWithFilter
21
     * or if empty get all class constants.
22
     * @param $object
23
     * @param string $startsWithFilter
24
     * @return array
25
     * @see https://github.com/spatie-custom/blender/blob/master/app/Foundation/helpers.php
26
     */
27
    function class_constants($object, string $startsWithFilter = ''): array
28
    {
29
        $objectProperties = new \ReflectionClass($object);
30
31
        $constants = $objectProperties->getConstants();
32
33
        if ($startsWithFilter == '') {
34
            return $constants;
35
        }
36
37
        return array_filter($constants, function ($key) use ($startsWithFilter) {
38
            return starts_with(strtolower($key), strtolower($startsWithFilter));
39
        }, ARRAY_FILTER_USE_KEY);
40
    }
41
}
42
43
if (!function_exists('class_uses_recursive')) {
44
    /**
45
     * Returns all traits used by a class, it's subclasses and trait of their traits
46
     *
47
     * @param  string $class
48
     * @return array
49
     */
50
    function class_uses_recursive($class)
51
    {
52
        $results = [];
53
        foreach (array_merge([$class => $class], class_parents($class)) as $class) {
54
            $results += trait_uses_recursive($class);
55
        }
56
        return array_unique($results);
57
    }
58
}
59
60
if (!function_exists('class_basename')) {
61
    /**
62
     * Get the class "basename" of the given object / class.
63
     *
64
     * @param  string|object $class
65
     * @return string
66
     */
67
    function class_basename($class)
68
    {
69
        $class = is_object($class) ? get_class($class) : $class;
70
        return basename(str_replace('\\', '/', $class));
71
    }
72
}
73
74
/**
75
 * Get the class name from a php file
76
 *
77
 * @param string $filePath
78
 *
79
 * @return string|null
80
 * @see https://github.com/laradic/support/blob/master/src/Util.php
81
 */
82
function getClassNameFromFile($filePath)
83
{
84
    $tokens = token_get_all(file_get_contents($filePath));
85
    $iMax = count($tokens);
86
    for ($i = 0; $i < $iMax; $i++) {
87
        if ($tokens[$i][0] === T_TRAIT || $tokens[$i][0] === T_INTERFACE) {
88
            return;
89
        }
90
        if ($tokens[$i][0] === T_CLASS) {
91
            for ($j = $i + 1; $j < $iMax; $j++) {
92
                if ($tokens[$j] === '{') {
93
                    return $tokens[$i + 2][1];
94
                }
95
            }
96
        }
97
    }
98
    return null;
99
}
100
101
/**
102
 * Get the namespace of the php file
103
 *
104
 * @param $filePath
105
 *
106
 * @return string|null
107
 * @see https://github.com/laradic/support/blob/master/src/Util.php
108
 */
109
function getNamespaceFromFile($filePath)
110
{
111
    $namespace = '';
112
    $tokens = token_get_all(file_get_contents($filePath));
113
    $iMax = count($tokens);
114
    for ($i = 0; $i < $iMax; $i++) {
115 View Code Duplication
        if ($tokens[$i][0] === T_NAMESPACE) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
116
            for ($j = $i + 1; $j < $iMax; $j++) {
117
                if ($tokens[$j][0] === T_STRING) {
118
                    $namespace .= '\\' . $tokens[$j][1];
119
                } else {
120
                    if ($tokens[$j] === '{' || $tokens[$j] === ';') {
121
                        return $namespace;
122
                    }
123
                }
124
            }
125
        }
126
    }
127
    return null;
128
}
129
130
/**
131
 * Get the namespace, classes, interfaces and traits of the php file
132
 *
133
 * @param $filePath
134
 *
135
 * @return array
136
 * @see https://github.com/laradic/support/blob/master/src/Util.php
137
 */
138
function getPhpDefinitionsFromFile($filePath)
139
{
140
    $classes = [];
141
    $traits = [];
142
    $interfaces = [];
143
    $fp = fopen($filePath, 'r');
144
    $class = $namespace = $buffer = '';
145
    $i = 0;
146
    while (!$class) {
147
        if (feof($fp)) {
148
            break;
149
        }
150
        $buffer .= fread($fp, 512);
151
        $tokens = token_get_all($buffer);
152
        if (strpos($buffer, '{') === false) {
153
            continue;
154
        }
155
        $iMax = count($tokens);
156
        for (; $i < $iMax; $i++) {
157 View Code Duplication
            if ($tokens[$i][0] === T_NAMESPACE) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
158
                for ($j = $i + 1; $j < $iMax; $j++) {
159
                    if ($tokens[$j][0] === T_STRING) {
160
                        $namespace .= '\\' . $tokens[$j][1];
161
                    } else {
162
                        if ($tokens[$j] === '{' || $tokens[$j] === ';') {
163
                            break;
164
                        }
165
                    }
166
                }
167
            }
168 View Code Duplication
            if ($tokens[$i][0] === T_CLASS) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
169
                for ($j = $i + 1; $j < $iMax; $j++) {
170
                    if ($tokens[$j] === '{') {
171
                        $class = $tokens[$i + 2][1];
172
                        $classes[] = $class;
173
                    }
174
                }
175
            }
176 View Code Duplication
            if ($tokens[$i][0] === T_INTERFACE) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
177
                for ($j = $i + 1; $j < $iMax; $j++) {
178
                    if ($tokens[$j] === '{') {
179
                        $interface = $tokens[$i + 2][1];
180
                        $interfaces[] = $interface;
181
                    }
182
                }
183
            }
184 View Code Duplication
            if ($tokens[$i][0] === T_TRAIT) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
185
                for ($j = $i + 1; $j < $iMax; $j++) {
186
                    if ($tokens[$j] === '{') {
187
                        $trait = $tokens[$i + 2][1];
188
                        $traits[] = $trait;
189
                    }
190
                }
191
            }
192
        }
193
    }
194
    return compact('namespace', 'classes', 'traits', 'interfaces');
195
}
196