Completed
Push — v4.0 ( 989be1...ff495d )
by Masiukevich
02:21
created

AggregateEvent::restore()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 5
dl 0
loc 9
ccs 0
cts 2
cp 0
crap 2
rs 10
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;
14
15
/**
16
 * Applied to aggregate event.
17
 *
18
 * @psalm-readonly
19
 */
20
final class AggregateEvent
21
{
22
    /**
23
     * Event id.
24
     */
25
    public string $id;
26
27
    /**
28
     * Playhead position.
29
     */
30
    public int $playhead;
31
32
    /**
33
     * Received event.
34
     */
35
    public object $event;
36
37
    /**
38
     * Occurred datetime.
39
     */
40
    public \DateTimeImmutable$occuredAt;
41
42
    /**
43
     * Recorded datetime.
44
     */
45
    public ?\DateTimeImmutable $recordedAt = null;
46
47 10
    public static function create(string $id, object $event, int $playhead, \DateTimeImmutable $occuredAt): self
48
    {
49 10
        return new self($id, $event, $playhead, $occuredAt, null);
50
    }
51
52
    public static function restore(
53
        string $id,
54
        object $event,
55
        int $playhead,
56
        \DateTimeImmutable $occuredAt,
57
        \DateTimeImmutable $recordedAt
58
    ): self
59
    {
60
        return new self($id, $event, $playhead, $occuredAt, $recordedAt);
61
    }
62
63 10
    private function __construct(
64
        string $id,
65
        object $event,
66
        int $playhead,
67
        \DateTimeImmutable $occuredAt,
68
        ?\DateTimeImmutable $recordedAt = null
69
    )
70
    {
71 10
        $this->id         = $id;
72 10
        $this->event      = $event;
73 10
        $this->playhead   = $playhead;
74 10
        $this->occuredAt  = $occuredAt;
75 10
        $this->recordedAt = $recordedAt;
76 10
    }
77
}
78