EnumDefinition::equals()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 5
c 2
b 0
f 0
dl 0
loc 11
rs 10
cc 4
nc 3
nop 1
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