Completed
Push — master ( 4803b3...959101 )
by Frank
03:46
created

UpcastedEventStub::aggregateRootId()   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 1
    public function __construct(AggregateRootId $aggregateRootId, PointInTime $timeOfRecording, string $property)
27
    {
28 1
        $this->aggregateRootId = $aggregateRootId;
29 1
        $this->timeOfRecording = $timeOfRecording;
30 1
        $this->property = $property;
31 1
    }
32
33 1
    public function aggregateRootId(): AggregateRootId
34
    {
35 1
        return $this->aggregateRootId;
36
    }
37
38 1
    public function eventVersion(): int
39
    {
40 1
        return 1;
41
    }
42
43 1
    public function timeOfRecording(): PointInTime
44
    {
45 1
        return $this->timeOfRecording;
46
    }
47
48 1
    public function toPayload(): array
49
    {
50 1
        return ['property' => $this->property];
51
    }
52
53 1
    public static function fromPayload(array $payload, AggregateRootId $aggregateRootId, PointInTime $timeOfRecording): Event
54
    {
55 1
        return new UpcastedEventStub($aggregateRootId, $timeOfRecording, $payload['property'] ?? 'undefined');
56
    }
57
}