Completed
Push — master ( 860638...4d5894 )
by Frank
02:47 queued 01:15
created

SecondEvent::withSecondField()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
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
    /**
77
     * @codeCoverageIgnore
78
     */
79
    public function withFirstField(string $firstField): FirstEvent
80
    {
81
        $this->firstField = $firstField;
82
83
        return $this;
84
    }
85
86
    public static function with(AggregateRootId $aggregateRootId, PointInTime $timeOfRecording): FirstEvent
87
    {
88
        return new FirstEvent(
89
            $aggregateRootId,
90
            $timeOfRecording,
91
            (string) 'FIRST'
92
        );
93
    }
94
95
}
96
97
final class SecondEvent implements Event
98
{
99
    /**
100
     * @var AggregateRootId
101
     */
102
    private $aggregateRootId;
103
104
    /**
105
     * @var string
106
     */
107
    private $secondField;
108
109
    /**
110
     * @var PointInTime
111
     */
112
    private $timeOfRecording;
113
114
    public function __construct(
115
        AggregateRootId $aggregateRootId,
116
        PointInTime $timeOfRecording,
117
        string $secondField
118
    ) {
119
        $this->aggregateRootId = $aggregateRootId;
120
        $this->timeOfRecording = $timeOfRecording;
121
        $this->secondField = $secondField;
122
    }
123
124
    public function aggregateRootId(): AggregateRootId
125
    {
126
        return $this->aggregateRootId;
127
    }
128
129
    public function secondField(): string
130
    {
131
        return $this->secondField;
132
    }
133
134
    public function eventVersion(): int
135
    {
136
        return 1;
137
    }
138
139
    public function timeOfRecording(): PointInTime
140
    {
141
        return $this->timeOfRecording;
142
    }
143
144
    public static function fromPayload(
145
        array $payload,
146
        AggregateRootId $aggregateRootId,
147
        PointInTime $timeOfRecording): Event
148
    {
149
        return new SecondEvent(
150
            $aggregateRootId,
151
            $timeOfRecording,
152
            (string) $payload['secondField']
153
        );
154
    }
155
156
    public function toPayload(): array
157
    {
158
        return [
159
            'secondField' => (string) $this->secondField
160
        ];
161
    }
162
163
    /**
164
     * @codeCoverageIgnore
165
     */
166
    public function withSecondField(string $secondField): SecondEvent
167
    {
168
        $this->secondField = $secondField;
169
170
        return $this;
171
    }
172
173
    public static function with(AggregateRootId $aggregateRootId, PointInTime $timeOfRecording): SecondEvent
174
    {
175
        return new SecondEvent(
176
            $aggregateRootId,
177
            $timeOfRecording,
178
            (string) 'SECOND'
179
        );
180
    }
181
182
}
183