Completed
Pull Request — master (#480)
by Luc
03:04 queued 44s
created

Status   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

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

9 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
A deserialize() 0 4 1
A serialize() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CultuurNet\UDB3\Event\ValueObjects;
6
7
use Broadway\Serializer\SerializableInterface;
8
use InvalidArgumentException;
9
10
class Status implements SerializableInterface
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(): Status
39
    {
40
        return new Status(self::SCHEDULED);
41
    }
42
43
    public static function postponed(): Status
44
    {
45
        return new Status(self::POSTPONED);
46
    }
47
48
    public static function cancelled(): Status
49
    {
50
        return new Status(self::CANCELLED);
51
    }
52
53
    public function toNative(): string
54
    {
55
        return $this->value;
56
    }
57
58
    public static function fromNative(string $value): Status
59
    {
60
        return new Status($value);
61
    }
62
63
    public function equals(Status $status): bool
64
    {
65
        return $this->value === $status->toNative();
66
    }
67
68
    public static function deserialize(array $data): Status
69
    {
70
        return new Status($data['eventStatus']);
71
    }
72
73
    public function serialize(): array
74
    {
75
        return [
76
            'eventStatus' => $this->value,
77
        ];
78
    }
79
}
80