Completed
Push — master ( c63c12...520404 )
by Frank
03:37 queued 01:34
created

EventName   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 83
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace With\EventFieldSerialization;
4
5
use EventSauce\EventSourcing\AggregateRootId;
6
use EventSauce\EventSourcing\Command;
7
use EventSauce\EventSourcing\Event;
8
use EventSauce\EventSourcing\PointInTime;
9
10
final class EventName implements Event
11
{
12
    /**
13
     * @var AggregateRootId
14
     */
15
    private $aggregateRootId;
16
17
    /**
18
     * @var string
19
     */
20
    private $title;
21
22
    /**
23
     * @var PointInTime
24
     */
25
    private $timeOfRecording;
26
27
    public function __construct(
28
        AggregateRootId $aggregateRootId,
29
        PointInTime $timeOfRecording,
30
        string $title
31
    ) {
32
        $this->aggregateRootId = $aggregateRootId;
33
        $this->timeOfRecording = $timeOfRecording;
34
        $this->title = $title;
35
    }
36
37
    public function aggregateRootId(): AggregateRootId
38
    {
39
        return $this->aggregateRootId;
40
    }
41
42
    public function title(): string
43
    {
44
        return $this->title;
45
    }
46
47
    public function eventVersion(): int
48
    {
49
        return 1;
50
    }
51
    
52
    public function timeOfRecording(): PointInTime
53
    {
54
        return $this->timeOfRecording;
55
    }
56
57
    public static function fromPayload(
58
        array $payload,
59
        AggregateRootId $aggregateRootId,
60
        PointInTime $timeOfRecording): Event
61
    {
62
        return new EventName(
63
            $aggregateRootId,
64
            $timeOfRecording,
65
            strtolower($payload['title'])
66
        );
67
    }
68
69
    public function toPayload(): array
70
    {
71
        return [
72
            'title' => strtoupper($this->title)
73
        ];
74
    }
75
76
    public function withTitle(string $title): EventName
77
    {
78
        $this->title = $title;
79
        
80
        return $this;
81
    }
82
83
    public static function with(AggregateRootId $aggregateRootId, PointInTime $timeOfRecording): EventName
84
    {
85
        return new EventName(
86
            $aggregateRootId,
87
            $timeOfRecording,
88
            strtolower('Title')
89
        );
90
    }
91
92
}
93
94
95