AbstractEnum::introspectKeys()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
/**
3
 * Copyright (c) 2010–2019 Ryan Parman <http://ryanparman.com>.
4
 * Copyright (c) 2016–2019 Contributors.
5
 *
6
 * http://opensource.org/licenses/Apache2.0
7
 */
8
9
declare(strict_types=1);
10
11
namespace SimplePie\UtilityPack\Enum;
12
13
use ReflectionClass;
14
15
/**
16
 * The base enum class that all other enum classes extend from. It does the
17
 * heavy lifting of implementing `EnumInterface` so that extending enum classes
18
 * can focus on defining enums.
19
 */
20
abstract class AbstractEnum implements EnumInterface
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25 3
    public static function introspect(): array
26
    {
27 3
        $refl = new ReflectionClass(\get_called_class());
28
29 3
        return $refl->getConstants();
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 1
    public static function introspectKeys(): array
36
    {
37 1
        return \array_keys(static::introspect());
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 1
    public static function hasValue(string $value): bool
44
    {
45 1
        $arr = \array_flip(static::introspect());
46
47 1
        return isset($arr[$value]);
48
    }
49
}
50