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

UpcastedEventStub::toPayload()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace EventSauce\EventSourcing\Integration\Upcasting;
4
5
use EventSauce\EventSourcing\AggregateRootId;
6
use EventSauce\EventSourcing\Event;
7
use EventSauce\EventSourcing\PointInTime;
8
9
class UpcastedEventStub implements Event
10
{
11
    /**
12
     * @var AggregateRootId
13
     */
14
    private $aggregateRootId;
15
16
    /**
17
     * @var PointInTime
18
     */
19
    private $timeOfRecording;
20
21
    /**
22
     * @var string
23
     */
24
    private $property;
25
26
    public function __construct(AggregateRootId $aggregateRootId, PointInTime $timeOfRecording, string $property)
27
    {
28
        $this->aggregateRootId = $aggregateRootId;
29
        $this->timeOfRecording = $timeOfRecording;
30
        $this->property = $property;
31
    }
32
33
    public function aggregateRootId(): AggregateRootId
34
    {
35
        return $this->aggregateRootId;
36
    }
37
38
    public function eventVersion(): int
39
    {
40
        return 1;
41
    }
42
43
    public function timeOfRecording(): PointInTime
44
    {
45
        return $this->timeOfRecording;
46
    }
47
48
    public function toPayload(): array
49
    {
50
        return ['property' => $this->property];
51
    }
52
53
    public static function fromPayload(array $payload, AggregateRootId $aggregateRootId, PointInTime $timeOfRecording): Event
54
    {
55
        return new UpcastedEventStub($aggregateRootId, $timeOfRecording, $payload['property'] ?? 'undefined');
56
    }
57
}