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

FirstEvent::fromPayload()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 3
1
<?php
2
3
namespace Multiple\Events\DefinitionGroup;
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 FirstEvent implements Event
11
{
12
    /**
13
     * @var AggregateRootId
14
     */
15
    private $aggregateRootId;
16
17
    /**
18
     * @var string
19
     */
20
    private $firstField;
21
22
    /**
23
     * @var PointInTime
24
     */
25
    private $timeOfRecording;
26
27
    public function __construct(
28
        AggregateRootId $aggregateRootId,
29
        PointInTime $timeOfRecording,
30
        string $firstField
31
    ) {
32
        $this->aggregateRootId = $aggregateRootId;
33
        $this->timeOfRecording = $timeOfRecording;
34
        $this->firstField = $firstField;
35
    }
36
37
    public function aggregateRootId(): AggregateRootId
38
    {
39
        return $this->aggregateRootId;
40
    }
41
42
    public function firstField(): string
43
    {
44
        return $this->firstField;
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 FirstEvent(
63
            $aggregateRootId,
64
            $timeOfRecording,
65
            (string) $payload['firstField']
66
        );
67
    }
68
69
    public function toPayload(): array
70
    {
71
        return [
72
            'firstField' => (string) $this->firstField
73
        ];
74
    }
75
76
    public function withFirstField(string $firstField): FirstEvent
77
    {
78
        $this->firstField = $firstField;
79
        
80
        return $this;
81
    }
82
83
    public static function with(AggregateRootId $aggregateRootId, PointInTime $timeOfRecording): FirstEvent
84
    {
85
        return new FirstEvent(
86
            $aggregateRootId,
87
            $timeOfRecording,
88
            (string) 'FIRST'
89
        );
90
    }
91
92
}
93
94
final class SecondEvent implements Event
95
{
96
    /**
97
     * @var AggregateRootId
98
     */
99
    private $aggregateRootId;
100
101
    /**
102
     * @var string
103
     */
104
    private $secondField;
105
106
    /**
107
     * @var PointInTime
108
     */
109
    private $timeOfRecording;
110
111
    public function __construct(
112
        AggregateRootId $aggregateRootId,
113
        PointInTime $timeOfRecording,
114
        string $secondField
115
    ) {
116
        $this->aggregateRootId = $aggregateRootId;
117
        $this->timeOfRecording = $timeOfRecording;
118
        $this->secondField = $secondField;
119
    }
120
121
    public function aggregateRootId(): AggregateRootId
122
    {
123
        return $this->aggregateRootId;
124
    }
125
126
    public function secondField(): string
127
    {
128
        return $this->secondField;
129
    }
130
131
    public function eventVersion(): int
132
    {
133
        return 1;
134
    }
135
    
136
    public function timeOfRecording(): PointInTime
137
    {
138
        return $this->timeOfRecording;
139
    }
140
141
    public static function fromPayload(
142
        array $payload,
143
        AggregateRootId $aggregateRootId,
144
        PointInTime $timeOfRecording): Event
145
    {
146
        return new SecondEvent(
147
            $aggregateRootId,
148
            $timeOfRecording,
149
            (string) $payload['secondField']
150
        );
151
    }
152
153
    public function toPayload(): array
154
    {
155
        return [
156
            'secondField' => (string) $this->secondField
157
        ];
158
    }
159
160
    public function withSecondField(string $secondField): SecondEvent
161
    {
162
        $this->secondField = $secondField;
163
        
164
        return $this;
165
    }
166
167
    public static function with(AggregateRootId $aggregateRootId, PointInTime $timeOfRecording): SecondEvent
168
    {
169
        return new SecondEvent(
170
            $aggregateRootId,
171
            $timeOfRecording,
172
            (string) 'SECOND'
173
        );
174
    }
175
176
}
177
178
179