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

UserSubscribedFromMailingList::fromPayload()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 3
1
<?php
2
3
namespace Acme\BusinessProcess;
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 UserSubscribedFromMailingList implements Event
11
{
12
    /**
13
     * @var AggregateRootId
14
     */
15
    private $aggregateRootId;
16
17
    /**
18
     * @var string
19
     */
20
    private $username;
21
22
    /**
23
     * @var string
24
     */
25
    private $mailingList;
26
27
    /**
28
     * @var PointInTime
29
     */
30
    private $timeOfRecording;
31
32
    public function __construct(
33
        AggregateRootId $aggregateRootId,
34
        PointInTime $timeOfRecording,
35
        string $username,
36
        string $mailingList
37
    ) {
38
        $this->aggregateRootId = $aggregateRootId;
39
        $this->timeOfRecording = $timeOfRecording;
40
        $this->username = $username;
41
        $this->mailingList = $mailingList;
42
    }
43
44
    public function aggregateRootId(): AggregateRootId
45
    {
46
        return $this->aggregateRootId;
47
    }
48
49
    public function username(): string
50
    {
51
        return $this->username;
52
    }
53
54
    public function mailingList(): string
55
    {
56
        return $this->mailingList;
57
    }
58
59
    public function eventVersion(): int
60
    {
61
        return 1;
62
    }
63
64
    public function timeOfRecording(): PointInTime
65
    {
66
        return $this->timeOfRecording;
67
    }
68
69
    public static function fromPayload(
70
        array $payload,
71
        AggregateRootId $aggregateRootId,
72
        PointInTime $timeOfRecording): Event
73
    {
74
        return new UserSubscribedFromMailingList(
75
            $aggregateRootId,
76
            $timeOfRecording,
77
            (string) $payload['username'],
78
            (string) $payload['mailingList']
79
        );
80
    }
81
82
    public function toPayload(): array
83
    {
84
        return [
85
            'username' => (string) $this->username,
86
            'mailingList' => (string) $this->mailingList
87
        ];
88
    }
89
90
}
91
92
final class SubscribeToMailingList implements Command
93
{
94
    /**
95
     * @var PointInTime
96
     */
97
    private $timeOfRequest;
98
99
    /**
100
     * @var AggregateRootId
101
     */
102
    private $aggregateRootId;
103
104
    /**
105
     * @var string
106
     */
107
    private $username;
108
109
    /**
110
     * @var string
111
     */
112
    private $mailingList;
113
114
    public function __construct(
115
        AggregateRootId $aggregateRootId,
116
        PointInTime $timeOfRequest,
117
        string $username,
118
        string $mailingList
119
    ) {
120
        $this->aggregateRootId = $aggregateRootId;
121
        $this->timeOfRequest = $timeOfRequest;
122
        $this->username = $username;
123
        $this->mailingList = $mailingList;
124
    }
125
126
    public function timeOfRequest(): PointInTime
127
    {
128
        return $this->timeOfRequest;
129
    }
130
131
    public function aggregateRootId(): AggregateRootId
132
    {
133
        return $this->aggregateRootId;
134
    }
135
136
    public function username(): string
137
    {
138
        return $this->username;
139
    }
140
141
    public function mailingList(): string
142
    {
143
        return $this->mailingList;
144
    }
145
146
}
147
148
final class UnsubscribeFromMailingList implements Command
149
{
150
    /**
151
     * @var PointInTime
152
     */
153
    private $timeOfRequest;
154
155
    /**
156
     * @var AggregateRootId
157
     */
158
    private $aggregateRootId;
159
160
    /**
161
     * @var string
162
     */
163
    private $username;
164
165
    /**
166
     * @var string
167
     */
168
    private $mailingList;
169
170
    /**
171
     * @var string
172
     */
173
    private $reason;
174
175
    public function __construct(
176
        AggregateRootId $aggregateRootId,
177
        PointInTime $timeOfRequest,
178
        string $username,
179
        string $mailingList,
180
        string $reason
181
    ) {
182
        $this->aggregateRootId = $aggregateRootId;
183
        $this->timeOfRequest = $timeOfRequest;
184
        $this->username = $username;
185
        $this->mailingList = $mailingList;
186
        $this->reason = $reason;
187
    }
188
189
    public function timeOfRequest(): PointInTime
190
    {
191
        return $this->timeOfRequest;
192
    }
193
194
    public function aggregateRootId(): AggregateRootId
195
    {
196
        return $this->aggregateRootId;
197
    }
198
199
    public function username(): string
200
    {
201
        return $this->username;
202
    }
203
204
    public function mailingList(): string
205
    {
206
        return $this->mailingList;
207
    }
208
209
    public function reason(): string
210
    {
211
        return $this->reason;
212
    }
213
214
}
215