EnumDefinition   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 5
Bugs 1 Features 1
Metric Value
wmc 5
eloc 12
c 5
b 1
f 1
dl 0
loc 37
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A equals() 0 11 4
1
<?php
2
3
namespace Spatie\Enum;
4
5
/** @internal */
6
class EnumDefinition
7
{
8
    /** @var string|int */
9
    public $value;
10
11
    public string $label;
12
13
    private string $methodName;
14
15
    /**
16
     * @param string $methodName
17
     * @param string|int $value
18
     * @param string $label
19
     */
20
    public function __construct(string $methodName, $value, string $label)
21
    {
22
        $this->methodName = strtolower($methodName);
23
        $this->value = $value;
24
        $this->label = $label;
25
    }
26
27
    /**
28
     * @param string|int $input
29
     *
30
     * @return bool
31
     */
32
    public function equals($input): bool
33
    {
34
        if ($this->value === $input) {
35
            return true;
36
        }
37
38
        if (is_string($input) && $this->methodName === strtolower($input)) {
39
            return true;
40
        }
41
42
        return false;
43
    }
44
}
45