Completed
Push — master ( eb0ddf...6e23e2 )
by Daniel
03:16
created

DomainEvent::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 4
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 94
    public function __construct($data, array $metadata = [], \DateTimeImmutable $occurredOn, $version = null)
38
    {
39 94
        $this->data = $data;
40 94
        $this->metadata = new Metadata($metadata);
41 94
        $this->occurredOn = $occurredOn;
42 94
        $this->version = $version;
43 94
    }
44
45
    /**
46
     * @param mixed $data
47
     * @param array $metadata
48
     * @param Version|null $version
49
     * @return DomainEvent
50
     */
51 78
    public static function produceNow($data, array $metadata = [], $version = null)
52
    {
53 78
        return new self($data, $metadata, new \DateTimeImmutable(), $version);
54
    }
55
56
    /**
57
     * @return mixed
58
     */
59 88
    public function data()
60
    {
61 88
        return $this->data;
62
    }
63
64
    /**
65
     * @return Metadata
66
     */
67 49
    public function metadata()
68
    {
69 49
        return $this->metadata;
70
    }
71
72
    /**
73
     * @return \DateTimeImmutable
74
     */
75 73
    public function occurredOn()
76
    {
77 73
        return $this->occurredOn;
78
    }
79
80
    /**
81
     * @return Version|null
82
     */
83 41
    public function version()
84
    {
85 41
        return $this->version;
86
    }
87
}
88