AggregateEvent::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

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