StatusType   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 2
cbo 0
dl 0
loc 58
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A available() 0 4 1
A temporarilyUnavailable() 0 4 1
A unavailable() 0 4 1
A toNative() 0 4 1
A fromNative() 0 4 1
A equals() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CultuurNet\UDB3\Event\ValueObjects;
6
7
use InvalidArgumentException;
8
9
final class StatusType
10
{
11
    private const AVAILABLE = 'Available';
12
    private const TEMPORARILY_UNAVAILABLE = 'TemporarilyUnavailable';
13
    private const UNAVAILABLE = 'Unavailable';
14
15
    /**
16
     * @var string
17
     */
18
    private $value;
19
20
    /**
21
     * @var string[]
22
     */
23
    private const ALLOWED_VALUES = [
24
        self::AVAILABLE,
25
        self::TEMPORARILY_UNAVAILABLE,
26
        self::UNAVAILABLE,
27
    ];
28
29
    private function __construct(string $value)
30
    {
31
        if (!\in_array($value, self::ALLOWED_VALUES, true)) {
32
            throw new InvalidArgumentException('Status does not support the value "' . $value . '"');
33
        }
34
        $this->value = $value;
35
    }
36
37
    public static function available(): StatusType
38
    {
39
        return new StatusType(self::AVAILABLE);
40
    }
41
42
    public static function temporarilyUnavailable(): StatusType
43
    {
44
        return new StatusType(self::TEMPORARILY_UNAVAILABLE);
45
    }
46
47
    public static function unavailable(): StatusType
48
    {
49
        return new StatusType(self::UNAVAILABLE);
50
    }
51
52
    public function toNative(): string
53
    {
54
        return $this->value;
55
    }
56
57
    public static function fromNative(string $value): StatusType
58
    {
59
        return new StatusType($value);
60
    }
61
62
    public function equals(StatusType $status): bool
63
    {
64
        return $this->value === $status->toNative();
65
    }
66
}
67