Completed
Pull Request — master (#15)
by Frank
06:50
created

EventStub::timeOfRecording()   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\Serialization;
4
5
use EventSauce\EventSourcing\Event;
6
use EventSauce\EventSourcing\PointInTime;
7
8
class EventStub implements Event
9
{
10
    /**
11
     * @var PointInTime
12
     */
13
    private $timeOfRecording;
14
15
    /**
16
     * @var string
17
     */
18
    private $value;
19
20 1
    public function __construct(PointInTime $timeOfRecording, string $value)
21
    {
22 1
        $this->timeOfRecording = $timeOfRecording;
23 1
        $this->value = $value;
24 1
    }
25
26 1
    public function timeOfRecording(): PointInTime
27
    {
28 1
        return $this->timeOfRecording;
29
    }
30
31 1
    public function toPayload(): array
32
    {
33 1
        return ['__event_version' => 2, 'value' => $this->value];
34
    }
35
36 1
    public static function fromPayload(array $payload, PointInTime $timeOfRecording): Event
37
    {
38 1
        return new EventStub($timeOfRecording, $payload['value'] ?? 'default');
39
    }
40
}