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

EventStub   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 33
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A timeOfRecording() 0 4 1
A toPayload() 0 4 1
A fromPayload() 0 4 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
}