EventObjectRepresentation   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 71
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromEventInterface() 0 8 1
A fromArray() 0 8 1
A __construct() 0 8 3
1
<?php
2
/**
3
 * This file is part of the Simple EventStore Manager 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\Infrastructure\DataTransformers\Representations;
12
13
use SimpleEventStoreManager\Domain\Model\AggregateUuid;
14
use SimpleEventStoreManager\Domain\Model\Contracts\EventInterface;
15
16
class EventObjectRepresentation
17
{
18
    /**
19
     * @var AggregateUuid
20
     */
21
    private $uuid;
22
23
    /**
24
     * @var string
25
     */
26
    private $version;
27
28
    /**
29
     * @var string
30
     */
31
    private $payload;
32
33
    /**
34
     * @var string
35
     */
36
    private $type;
37
38
    /**
39
     * @var string
40
     */
41
    private $body;
42
43
    /**
44
     * @var \DateTimeImmutable
45
     */
46
    private $occurred_on;
47
48
    /**
49
     * EventObjectRepresentation constructor.
50
     * @param $event
51
     */
52
    public function __construct($event)
53
    {
54
        if (is_array($event)) {
55
            $this->fromArray($event);
56
        }
57
58
        if ($event instanceof EventInterface) {
59
            $this->fromEventInterface($event);
60
        }
61
    }
62
63
    /**
64
     * @param array $event
65
     */
66
    private function fromArray(array $event)
67
    {
68
        $this->uuid = $event['uuid'];
69
        $this->version = $event['version'];
70
        $this->payload = $event['payload'];
71
        $this->type = $event['type'];
72
        $this->body = $event['body'];
73
        $this->occurred_on = $event['occurred_on'];
74
    }
75
76
    /**
77
     * @param EventInterface $event
78
     */
79
    private function fromEventInterface(EventInterface $event)
80
    {
81
        $this->uuid = $event->uuid();
82
        $this->version = $event->version();
83
        $this->payload = $event->payload();
84
        $this->type = $event->type();
85
        $this->body = $event->body();
86
        $this->occurred_on = $event->occurredOn();
87
    }
88
}
89