GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (2)

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/Enum/Enum.php (2 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
namespace Giritli\Enum;
4
5
use Giritli\Enum\Exception\NoDefaultValueException;
6
use Giritli\Enum\Exception\ValueNotFoundException;
7
use ReflectionClass;
8
use JsonSerializable;
9
10
abstract class Enum implements JsonSerializable
11
{
12
13
14
    /**
15
     * The value of the enum. Must be compatible with the enum constant values.
16
     * 
17
     * @var mixed
18
     */ 
19
    protected $value = null;
20
21
22
    /**
23
     * Name of the enum constant.
24
     * 
25
     * @var string
26
     */ 
27
    protected $key = null;
28
29
30
    /**
31
     * The ordinal of the enum value.
32
     * 
33
     * @var integer
34
     */
35
    protected $ordinal = -1;
36
37
38
    /**
39
     * The default value of the enum.
40
     * 
41
     * @var mixed
42
     */
43
    protected $default = null;
44
    
45
    
46
    /**
47
     * Can the enum be null?
48
     */
49
    protected $nullable = false;
50
51
52
    /**
53
     * Static cache of all loaded enum values.
54
     * 
55
     * @var array
56
     */
57
    protected static $cache = [];
58
59
60
    /**
61
     * Static cache of all the ordinals of enum values.
62
     * 
63
     * @var array
64
     */
65
    protected static $ordinals = [];
66
67
68
    /**
69
     * Instantiate a new enum value.
70
     *
71
     * @param mixed $value
72
     * @throws NoDefaultValueException
73
     */
74 11
    public function __construct($value = null)
75
    {
76 11
        if (is_null($value))
77 11
        {
78 6
            if ($this->nullable)
79 6
            {
80
                static::generateCache();
81
                
82
                return;
83
            }
84
            
85 6
            if ($this->default)
86 6
            {
87 5
                return $this->__construct($this->default);
0 ignored issues
show
Constructors do not have meaningful return values, anything that is returned from here is discarded. Are you sure this is correct?
Loading history...
88
            }
89
            else
90
            {
91 1
                throw new NoDefaultValueException('No enum default exists.');
92
            }
93
        }
94
95 10
        static::generateCache();
96
97 10
        if ($value instanceof Enum)
98 10
        {
99 1
            $this->loadValue($value->getValue());
100 1
        }
101
        else
102
        {
103 10
            $this->loadValue($value);
104
        }
105 8
    }
106
107
108
    /**
109
     * Generate cache for current class and also cache the
110
     * ordinal value.
111
     */
112 13
    protected static function generateCache()
113
    {
114 13
        $class = static::class;
115
116 13
        if (!isset(static::$cache[$class]))
117 13
        {
118 2
            $reflection = new ReflectionClass($class);
119 2
            static::$cache[$class] = $reflection->getConstants();
120 2
            $i = 0;
121 2
            foreach (static::$cache[$class] as $constant => $value)
122
            {
123 2
                static::$ordinals[$class][$constant] = $i++;
124 2
            }
125 2
        }
126
127 13
    }
128
129
130
    /**
131
     * Load the value of the enum.
132
     * 
133
     * @param mixed $value
134
     * @throws ValueNotFoundException
135
     */
136 10
    protected function loadValue($value)
137
    {
138 10
        $class = static::class;
139 10
        $key = array_search($value, static::$cache[$class], true);
140
141 10
        if ($key === false)
142 10
        {
143 2
            throw new ValueNotFoundException('Enum value not found.');
144
        }
145
146 8
        $this->key = $key;
147 8
        $this->value = $value;
148 8
        $this->ordinal = static::$ordinals[$class][$key];
149 8
    }
150
151
152
    /**
153
     * Allow instantiation of enum by calling Enum::key() and
154
     * returning a new instance of an enum.
155
     * 
156
     * @param string $name
157
     * @param array $arguments
158
     * @return Enum
159
     */
160 2
    public static function __callStatic($name, $arguments)
161
    {
162 2
        static::generateCache();
163 2
        $class = static::class;
164
165 2
        if (isset(static::$cache[$class][$name]))
166 2
        {
167 1
            return new static(static::$cache[$class][$name]);
168
        }
169
170 1
        return new static($name);
171
    }
172
173
174
    /**
175
     * Get all enum values.
176
     * 
177
     * @return mixed[]
178
     */
179 1
    public static function getValues()
180
    {
181 1
        static::generateCache();
182
183 1
        return static::$cache[static::class];
184
    }
185
186
187
    /**
188
     * Get all enum value ordinals.
189
     * 
190
     * @return int[]
191
     */
192 1
    public static function getOrdinals()
193
    {
194 1
        static::generateCache();
195
196 1
        return static::$ordinals[static::class];
197
    }
198
199
200
    /**
201
     * Get all enum keys.
202
     * 
203
     * @return array
204
     */
205 1
    public static function getKeys()
206
    {
207 1
        static::generateCache();
208
209 1
        return array_keys(static::$ordinals[static::class]);
210
    }
211
212
213
    /**
214
     * Get the enum value.
215
     * 
216
     * @return mixed
217
     */
218 6
    public function getValue()
219
    {
220 6
        return $this->value;
221
    }
222
223
224
    /**
225
     * Get the enum value's key.
226
     * 
227
     * @return string;
0 ignored issues
show
The doc-type string; could not be parsed: Expected "|" or "end of type", but got ";" at position 6. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
228
     */
229 1
    public function getKey()
230
    {
231 1
        return $this->key;
232
    }
233
234
235
    /**
236
     * Get the current ordinal value of the enum.
237
     * 
238
     * @return integer
239
     */
240 1
    public function getOrdinal()
241
    {
242 1
        return $this->ordinal;
243
    }
244
    
245
    
246
    /**
247
     * Compare current value to given value.
248
     * 
249
     * @returns boolean;
250
     */
251 1
    public function is($value)
252
    {
253 1
        return (string) $this->getValue() === (string) $value;
254
    }
255
256
257
    /**
258
     * Return string representation of enum value.
259
     * 
260
     * @return string
261
     */
262 3
    public function __toString()
263
    {
264 3
        return (string) $this->getValue();
265
    }
266
    
267
    
268
    /**
269
     * Return string value for json representation.
270
     * 
271
     * @return string
272
     */
273
    public function jsonSerialize()
274
    {
275
        return $this->__toString();
276
    }
277
}
278