EventCopied   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 64
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 2
A getParentAggregateId() 0 4 1
A getOriginalEventId() 0 4 1
A getCalendar() 0 4 1
A serialize() 0 7 1
A deserialize() 0 8 1
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