DomainEvent::occurredOn()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace DDDominio\EventSourcing\Common;
4
5
use DDDominio\Common\EventInterface;
6
use DDDominio\EventSourcing\Versioning\Version;
7
use DDDominio\EventSourcing\Versioning\VersionableInterface;
8
9
class DomainEvent implements EventInterface, VersionableInterface
10
{
11
    /**
12
     * @var mixed
13
     */
14
    private $data;
15
16
    /**
17
     * @var Metadata
18
     */
19
    private $metadata;
20
21
    /**
22
     * @var \DateTimeImmutable
23
     */
24
    private $occurredOn;
25
26
    /**
27
     * @var Version
28
     */
29
    private $version;
30
31
    /**
32
     * @param mixed $data
33
     * @param array $metadata
34
     * @param \DateTimeImmutable $occurredOn
35
     * @param Version|null $version
36
     */
37 97
    public function __construct($data, array $metadata = [], \DateTimeImmutable $occurredOn, $version = null)
38
    {
39 97
        $this->data = $data;
40 97
        $this->metadata = new Metadata($metadata);
41 97
        $this->occurredOn = $occurredOn;
42 97
        $this->version = $version;
43 97
    }
44
45
    /**
46
     * @param mixed $data
47
     * @param array $metadata
48
     * @param Version|null $version
49
     * @return DomainEvent
50
     */
51 81
    public static function produceNow($data, array $metadata = [], $version = null)
52
    {
53 81
        return new self($data, $metadata, new \DateTimeImmutable(), $version);
54
    }
55
56
    /**
57
     * @return mixed
58
     */
59 91
    public function data()
60
    {
61 91
        return $this->data;
62
    }
63
64
    /**
65
     * @return Metadata
66
     */
67 51
    public function metadata()
68
    {
69 51
        return $this->metadata;
70
    }
71
72
    /**
73
     * @return \DateTimeImmutable
74
     */
75 75
    public function occurredOn()
76
    {
77 75
        return $this->occurredOn;
78
    }
79
80
    /**
81
     * @return Version|null
82
     */
83 43
    public function version()
84
    {
85 43
        return $this->version;
86
    }
87
}
88