Passed
Pull Request — master (#16)
by Frank
02:29
created

EventStub   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 38
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

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