Completed
Push — master ( bd434e...913de5 )
by
unknown
34s queued 15s
created

EventStatusType   A

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 scheduled() 0 4 1
A postponed() 0 4 1
A cancelled() 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
//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