Completed
Pull Request — master (#480)
by Luc
01:59
created

EventStatusType::postponed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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