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

EventWithDescription::description()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Group\With\Defaults;
4
5
use EventSauce\EventSourcing\AggregateRootId;
6
use EventSauce\EventSourcing\Command;
7
use EventSauce\EventSourcing\Event;
8
use EventSauce\EventSourcing\PointInTime;
9
10
final class EventWithDescription implements Event
11
{
12
    /**
13
     * @var AggregateRootId
14
     */
15
    private $aggregateRootId;
16
17
    /**
18
     * @var string
19
     */
20
    private $description;
21
22
    /**
23
     * @var PointInTime
24
     */
25
    private $timeOfRecording;
26
27
    public function __construct(
28
        AggregateRootId $aggregateRootId,
29
        PointInTime $timeOfRecording,
30
        string $description
31
    ) {
32
        $this->aggregateRootId = $aggregateRootId;
33
        $this->timeOfRecording = $timeOfRecording;
34
        $this->description = $description;
35
    }
36
37
    public function aggregateRootId(): AggregateRootId
38
    {
39
        return $this->aggregateRootId;
40
    }
41
42
    public function description(): string
43
    {
44
        return $this->description;
45
    }
46
47
    public function eventVersion(): int
48
    {
49
        return 1;
50
    }
51
52
    public function timeOfRecording(): PointInTime
53
    {
54
        return $this->timeOfRecording;
55
    }
56
57
    public static function fromPayload(
58
        array $payload,
59
        AggregateRootId $aggregateRootId,
60
        PointInTime $timeOfRecording): Event
61
    {
62
        return new EventWithDescription(
63
            $aggregateRootId,
64
            $timeOfRecording,
65
            (string) $payload['description']
66
        );
67
    }
68
69
    public function toPayload(): array
70
    {
71
        return [
72
            'description' => (string) $this->description
73
        ];
74
    }
75
76
    /**
77
     * @codeCoverageIgnore
78
     */
79
    public function withDescription(string $description): EventWithDescription
80
    {
81
        $this->description = $description;
82
83
        return $this;
84
    }
85
86
    public static function with(AggregateRootId $aggregateRootId, PointInTime $timeOfRecording): EventWithDescription
87
    {
88
        return new EventWithDescription(
89
            $aggregateRootId,
90
            $timeOfRecording,
91
            (string) 'This is a description.'
92
        );
93
    }
94
95
}
96