Event::getStreamName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Blixit\EventSourcing\Event;
6
7
use function time;
8
9
/**
10
 * Class DomainEvent
11
 *
12
 * @link    http://github.com/blixit
13
 */
14
class Event implements EventInterface
15
{
16
    /** @var mixed[] $payload */
17
    protected $payload = [];
18
19
    /** @var string $streamName */
20
    protected $streamName;
21
22
    /** @var mixed $aggregateId */
23
    protected $aggregateId;
24
25
    /** @var mixed $aggregateClass */
26
    protected $aggregateClass;
27
28
    /** @var int $timestamp */
29
    protected $timestamp;
30
31
    /** @var int $sequence */
32
    protected $sequence = 0;
33
34
    /**
35
     * @param mixed[] $payload
36
     */
37
    protected function __construct(string $aggregateId, array $payload)
38
    {
39
        $this->aggregateId = $aggregateId;
40
        $this->payload     = $payload;
41
        $this->timestamp   = time();
42
    }
43
44
    /**
45
     * @param mixed[] $payload
46
     */
47
    public static function occur(string $aggregateId, array $payload) : EventInterface
48
    {
49
        $lsbClass = static::class;
50
        return new $lsbClass($aggregateId, $payload);
51
    }
52
53
    /**
54
     * @return mixed
55
     */
56
    public function getAggregateId()
57
    {
58
        return $this->aggregateId;
59
    }
60
61
    public function getSequence() : int
62
    {
63
        return $this->sequence;
64
    }
65
66
    public function getAggregateClass() : ?string
67
    {
68
        return $this->aggregateClass;
69
    }
70
71
    public function getTimestamp() : int
72
    {
73
        return $this->timestamp;
74
    }
75
76
    public function getStreamName() : ?string
77
    {
78
        return $this->streamName;
79
    }
80
81
    /**
82
     * @return mixed[]
83
     */
84
    public function getPayload() : array
85
    {
86
        return $this->payload;
87
    }
88
}
89