EventCopied::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 2
nc 2
nop 3
1
<?php
2
3
namespace CultuurNet\UDB3\Event\Events;
4
5
use CultuurNet\UDB3\Calendar;
6
use CultuurNet\UDB3\EventSourcing\AggregateCopiedEventInterface;
7
use CultuurNet\UDB3\Offer\Events\AbstractEvent;
8
9
final class EventCopied extends AbstractEvent implements AggregateCopiedEventInterface
10
{
11
    /**
12
     * @var string
13
     */
14
    private $originalEventId;
15
16
    /**
17
     * @var Calendar
18
     */
19
    private $calendar;
20
21
    public function __construct(
22
        string $eventId,
23
        string $originalEventId,
24
        Calendar $calendar
25
    ) {
26
        parent::__construct($eventId);
27
28
        if (!is_string($originalEventId)) {
29
            throw new \InvalidArgumentException(
30
                'Expected originalEventId to be a string, received ' . gettype($originalEventId)
31
            );
32
        }
33
34
        $this->originalEventId = $originalEventId;
35
        $this->calendar = $calendar;
36
    }
37
38
    public function getParentAggregateId(): string
39
    {
40
        return $this->originalEventId;
41
    }
42
43
    public function getOriginalEventId(): string
44
    {
45
        return $this->originalEventId;
46
    }
47
48
    /**
49
     * @return Calendar
50
     */
51
    public function getCalendar(): Calendar
52
    {
53
        return $this->calendar;
54
    }
55
56
    public function serialize(): array
57
    {
58
        return parent::serialize() + [
59
            'original_event_id' => $this->getOriginalEventId(),
60
            'calendar' => $this->calendar->serialize(),
61
        ];
62
    }
63
64
    public static function deserialize(array $data): EventCopied
65
    {
66
        return new self(
67
            $data['item_id'],
68
            $data['original_event_id'],
69
            Calendar::deserialize($data['calendar'])
70
        );
71
    }
72
}
73