Completed
Push — feature/VSVGVQ-24 ( 890c4d...a3069c )
by Luc
05:52 queued 02:46
created

Role   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 42
rs 10
c 0
b 0
f 0

3 Methods

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