Completed
Pull Request — master (#478)
by Luc
02:08
created

Status::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CultuurNet\UDB3\Event\ValueObjects;
6
7
use InvalidArgumentException;
8
9
class Status
10
{
11
    private const SCHEDULED = 'scheduled';
12
    private const POSTPONED = 'postponed';
13
    private const CANCELLED = 'cancelled';
14
15
    /**
16
     * @var string
17
     */
18
    private $value;
19
20
    private function __construct(string $value)
21
    {
22
        if (!\in_array($value, $this->getAllowedValues())) {
23
            throw new InvalidArgumentException('Status does not support the value "' . $value . '"');
24
        }
25
        $this->value = $value;
26
    }
27
28
    private function getAllowedValues(): array
29
    {
30
        return [
31
            self::SCHEDULED,
32
            self::POSTPONED,
33
            self::CANCELLED,
34
        ];
35
    }
36
37
    public static function scheduled(): Status
38
    {
39
        return new Status(self::SCHEDULED);
40
    }
41
42
    public static function postponed(): Status
43
    {
44
        return new Status(self::POSTPONED);
45
    }
46
47
    public static function cancelled(): Status
48
    {
49
        return new Status(self::CANCELLED);
50
    }
51
52
    public function toNative(): string
53
    {
54
        return $this->value;
55
    }
56
57
    public static function fromNative(string $value): Status
58
    {
59
        return new Status($value);
60
    }
61
62
    public function equals(Status $status): bool
63
    {
64
        return $this->value === $status->toNative();
65
    }
66
}
67