StoredAggregateEvent   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 90
ccs 11
cts 11
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 8 1
A restore() 0 9 1
A __construct() 0 14 1
1
<?php
2
3
/**
4
 * Event Sourcing implementation.
5
 *
6
 * @author  Maksim Masiukevich <[email protected]>
7
 * @license MIT
8
 * @license https://opensource.org/licenses/MIT
9
 */
10
11
declare(strict_types = 1);
12
13
namespace ServiceBus\EventSourcing\EventStream\Store;
14
15
/**
16
 * Aggregate event data.
17
 *
18
 * @psalm-immutable
19
 */
20
final class StoredAggregateEvent
21
{
22
    /**
23
     * Event ID.
24
     *
25
     * @var string
26
     */
27
    public $eventId;
28
29
    /**
30
     * Playhead position.
31
     *
32
     * @var int
33
     */
34
    public $playheadPosition;
35
36
    /**
37
     * Serialized event data.
38
     *
39
     * @var string
40
     */
41
    public $eventData;
42
43
    /**
44
     * Event class.
45
     *
46
     * @psalm-var class-string
47
     *
48
     * @var string
49
     */
50
    public $eventClass;
51
52
    /**
53
     * Occured at datetime.
54
     *
55
     * @var string
56
     */
57
    public $occuredAt;
58
59
    /**
60
     * Recorded at datetime.
61
     *
62
     * @var string|null
63
     */
64
    public $recordedAt = null;
65
66
    /**
67
     * @psalm-param class-string $eventClass
68
     */
69 7
    public static function create(
70
        string $eventId,
71
        int $playheadPosition,
72
        string $eventData,
73
        string $eventClass,
74
        string $occuredAt
75
    ): self {
76 7
        return new self($eventId, $playheadPosition, $eventData, $eventClass, $occuredAt);
77
    }
78
79
    /**
80
     * @psalm-param class-string $eventClass
81
     */
82 4
    public static function restore(
83
        string $eventId,
84
        int $playheadPosition,
85
        string $eventData,
86
        string $eventClass,
87
        string $occuredAt,
88
        string $recordedAt
89
    ): self {
90 4
        return new self($eventId, $playheadPosition, $eventData, $eventClass, $occuredAt, $recordedAt);
91
    }
92
93
    /**
94
     * @psalm-param class-string $eventClass
95
     */
96 7
    private function __construct(
97
        string $eventId,
98
        int $playheadPosition,
99
        string $eventData,
100
        string $eventClass,
101
        string $occuredAt,
102
        ?string $recordedAt = null
103
    ) {
104 7
        $this->eventId          = $eventId;
105 7
        $this->playheadPosition = $playheadPosition;
106 7
        $this->eventData        = $eventData;
107 7
        $this->eventClass       = $eventClass;
108 7
        $this->occuredAt        = $occuredAt;
109 7
        $this->recordedAt       = $recordedAt;
110 7
    }
111
}
112