Event   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 102
rs 10
c 0
b 0
f 0
wmc 9

7 Methods

Rating   Name   Duplication   Size   Complexity  
A type() 0 3 1
A body() 0 3 1
A payload() 0 3 1
A version() 0 3 1
A __construct() 0 13 3
A occurredOn() 0 3 1
A uuid() 0 3 1
1
<?php
2
/**
3
 * This file is part of the EventStoreManager package.
4
 *
5
 * (c) Mauro Cassani<https://github.com/mauretto78>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace SimpleEventStoreManager\Domain\Model;
12
13
use SimpleEventStoreManager\Domain\Model\Contracts\EventInterface;
14
15
class Event implements EventInterface
16
{
17
    /**
18
     * @var AggregateUuid
19
     */
20
    private $uuid;
21
22
    /**
23
     * @var string
24
     */
25
    private $type;
26
27
    /**
28
     * @var int
29
     */
30
    private $version;
31
32
    /**
33
     * @var string
34
     */
35
    private $payload;
36
37
    /**
38
     * @var mixed
39
     */
40
    private $body;
41
42
    /**
43
     * @var \DateTimeImmutable
44
     */
45
    private $occurred_on;
46
47
    /**
48
     * Event constructor.
49
     *
50
     * @param AggregateUuid $eventId
51
     * @param $type
52
     * @param $body
53
     * @param null $version
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $occurred_on is correct as it would always require null to be passed?
Loading history...
Documentation Bug introduced by
Are you sure the doc-type for parameter $version is correct as it would always require null to be passed?
Loading history...
54
     * @param null $occurred_on
55
     */
56
    public function __construct(
57
        AggregateUuid $eventId,
58
        $type,
59
        $body,
60
        $version = null,
61
        $occurred_on = null
62
    ) {
63
        $this->uuid = $eventId;
64
        $this->type = $type;
65
        $this->body = $body;
66
        $this->payload = get_class($this);
67
        $this->version = ($version) ?: 0;
68
        $this->occurred_on = ($occurred_on) ? new \DateTimeImmutable($occurred_on) : new \DateTimeImmutable();
69
    }
70
71
    /**
72
     * @return AggregateUuid
73
     */
74
    public function uuid()
75
    {
76
        return $this->uuid;
77
    }
78
79
    /**
80
     * @return string
81
     */
82
    public function type()
83
    {
84
        return $this->type;
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    public function version()
91
    {
92
        return $this->version;
93
    }
94
95
    /**
96
     * @return string
97
     */
98
    public function payload()
99
    {
100
        return $this->payload;
101
    }
102
103
    /**
104
     * @return mixed
105
     */
106
    public function body()
107
    {
108
        return $this->body;
109
    }
110
111
    /**
112
     * @return \DateTimeImmutable
113
     */
114
    public function occurredOn()
115
    {
116
        return $this->occurred_on;
117
    }
118
}
119