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.

Enumeration::getConstantsForClass()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace UCD\Unicode\Character\Properties;
4
5
use UCD\Unicode\Comparable;
6
use UCD\Exception\InvalidArgumentException;
7
8
abstract class Enumeration implements Comparable
9
{
10
    /**
11
     * @var mixed
12
     */
13
    private $value;
14
15
    /**
16
     * @var array
17
     */
18
    private static $constantsCache = [];
19
20
    /**
21
     * @param mixed $value
22
     * @throws InvalidArgumentException
23
     */
24
    final public function __construct($value)
25
    {
26
        if ($this->isKnown($value) !== true) {
27
            throw new InvalidArgumentException(sprintf('"%s" is not recognised', var_export($value, true)));
28
        }
29
30
        $this->value = $value;
31
    }
32
33
    /**
34
     * @param string $value
35
     * @return static
36
     */
37
    final public static function fromValue($value)
38
    {
39
        return new static($value);
40
    }
41
42
    /**
43
     * @return mixed
44
     */
45
    final public function getValue()
46
    {
47
        return $this->value;
48
    }
49
50
    /**
51
     * @param mixed $other
52
     * @return bool
53
     */
54 View Code Duplication
    public function equals($other)
0 ignored issues
show
Duplication introduced by
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...
55
    {
56
        if ($this === $other) {
57
            return true;
58
        }
59
60
        return $other instanceof static
61
            && $other->value === $this->value;
62
    }
63
64
    /**
65
     * @param string $value
66
     * @return bool
67
     */
68
    private function isKnown($value)
69
    {
70
        return in_array($value, self::getConstants(), true);
71
    }
72
73
    /**
74
     * @return array
75
     */
76
    private static function getConstants()
77
    {
78
        $className = static::class;
79
80
        if (!array_key_exists($className, self::$constantsCache)) {
81
            self::$constantsCache[$className] = self::getConstantsForClass($className);
82
        }
83
84
        return self::$constantsCache[$className];
85
    }
86
87
    /**
88
     * @param string $className
89
     * @return array
90
     */
91
    private static function getConstantsForClass($className)
92
    {
93
        return (new \ReflectionClass($className))
94
            ->getConstants();
95
    }
96
97
    /**
98
     * @return string
99
     */
100
    public function __toString()
101
    {
102
        return (string)$this->value;
103
    }
104
}