Issues (3)

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.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 Paillechat\Enum;
4
5
use Paillechat\Enum\Exception\EnumException;
6
7
abstract class Enum
8
{
9
    /** @var Enum[] */
10
    private static $instances = [];
11
    /** @var \ReflectionClassConstant[] */
12
    private static $constReflections = [];
13
    /** @var \ReflectionClass[] */
14
    private static $reflections = [];
15
    /** @var string */
16
    private $name;
17
18
    /**
19
     * @param string $name
20
     */
21 3
    final private function __construct(string $name)
22
    {
23 3
        $this->name = $name;
24 3
    }
25
26
    /**
27
     * Creates enum instance by name
28
     *
29
     * @param string $name
30
     *
31
     * @return static
32
     *
33
     * @throws EnumException
34
     */
35 8
    final public static function createByName(string $name)
36
    {
37 8
        $canonicalName = strtoupper($name);
38 8
        if ($canonicalName !== $name) {
39 1
            $name = $canonicalName;
40 1
            trigger_error('PSR-1 requires constant to be declared in upper case.', E_USER_NOTICE);
41
        }
42
43 7
        $const = static::getConstList();
44
45 7
        if (!\in_array($name, $const, true)) {
46 1
            throw EnumException::becauseUnknownMember(static::class, $name);
47
        }
48
49 6
        return static::createNamedInstance($name);
50
    }
51
52
    /**
53
     * Creates enum instance with short static constructor
54
     *
55
     * @param string $name
56
     * @param array $arguments
57
     *
58
     * @return static
59
     *
60
     * @throws EnumException
61
     */
62 7
    final public static function __callStatic(string $name, array $arguments)
63
    {
64 7
        return static::createByName($name);
65
    }
66
67 8
    public static function getConstList(): array
68
    {
69 8
        return array_keys(self::getEnumReflection(static::class)->getConstants());
70
    }
71
72 6 View Code Duplication
    private static function getConstantReflection(string $class, string $name): \ReflectionClassConstant
0 ignored issues
show
This method seems to be duplicated in 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...
73
    {
74 6
        $key = self::getConstKey($class, $name);
75 6
        if (!array_key_exists($key, self::$constReflections)) {
76 4
            $refl = self::getEnumReflection(static::class);
77
78 4
            self::$constReflections[$key] = $refl->getReflectionConstant($name);
79
        }
80
81 6
        return self::$constReflections[$key];
82
    }
83
84 6
    private static function getConstKey(string $class, string $name): string
85
    {
86 6
        return $class . '::' . $name;
87
    }
88
89 6
    private static function findParentClassForConst(string $name): string
90
    {
91 6
        return self::getConstantReflection(static::class, $name)->getDeclaringClass()->getName();
92
    }
93
94 8
    private static function getEnumReflection(string $class): \ReflectionClass
95
    {
96 8
        if (!array_key_exists($class, self::$reflections)) {
97
            try {
98 3
                self::$reflections[$class] = new \ReflectionClass($class);
99
                // @codeCoverageIgnoreStart
100
            } catch (\ReflectionException $e) {
101
                throw new \LogicException('Class should be valid FQCN. Fix internal calls.');
102
                // @codeCoverageIgnoreEnd
103
            }
104
        }
105
106 8
        return self::$reflections[$class];
107
    }
108
109
    /**
110
     * Create named enum instance
111
     *
112
     * @param string $name
113
     *
114
     * @return static
115
     */
116 6 View Code Duplication
    private static function createNamedInstance(string $name)
0 ignored issues
show
This method seems to be duplicated in 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...
117
    {
118 6
        $class = self::findParentClassForConst($name);
119
120 6
        $key = self::getConstKey($class, $name);
121
122 6
        if (!array_key_exists($key, self::$instances)) {
123 3
            self::$instances[$key] = new static($name);
124
        }
125
126 6
        return self::$instances[$key];
127
    }
128
129 1
    final public function getName(): string
130
    {
131 1
        return $this->name;
132
    }
133
134
    /**
135
     * {@inheritdoc}
136
     */
137 1
    final public function __toString(): string
138
    {
139 1
        return $this->getName();
140
    }
141
}
142