Role::equals()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 1
1
<?php declare(strict_types=1);
2
3
namespace VSV\GVQ_API\User\ValueObjects;
4
5
class Role
6
{
7
    const ADMIN = 'admin';
8
    const VSV = 'vsv';
9
    const CONTACT = 'contact';
10
11
    /**
12
     * @var string
13
     */
14
    private $value;
15
16
    /**
17
     * @var string[]
18
     */
19
    private $allowedValues = [
20
        'admin',
21
        'vsv',
22
        'contact',
23
    ];
24
25
    /**
26
     * @param string $value
27
     */
28
    public function __construct(string $value)
29
    {
30
        if (!in_array($value, $this->allowedValues)) {
31
            throw new \InvalidArgumentException('Invalid value: '.$value.' for role.');
32
        }
33
        $this->value = $value;
34
    }
35
36
    /**
37
     * @return string
38
     */
39
    public function toNative(): string
40
    {
41
        return $this->value;
42
    }
43
44
    /**
45
     * @param Role $role
46
     * @return bool
47
     */
48
    public function equals(Role $role): bool
49
    {
50
        return $this->toNative() === $role->toNative();
51
    }
52
}
53