Completed
Push — master ( ae76e5...dc17f4 )
by Constantin
06:11
created

MetaData   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 0
dl 0
loc 85
ccs 29
cts 29
cp 1
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 1
A getDateCreated() 0 4 1
A getAggregateId() 0 4 1
A getAggregateClass() 0 4 1
A getAuthenticatedUserId() 0 4 1
A getCommandMetadata() 0 4 1
A addTimeZone() 0 5 3
A withSequenceAndIndex() 0 7 1
A getSequence() 0 4 1
A getIndex() 0 4 1
1
<?php
2
/******************************************************************************
3
 * Copyright (c) 2016 Constantin Galbenu <[email protected]>             *
4
 ******************************************************************************/
5
6
namespace Gica\Cqrs\Event;
7
8
9
class MetaData
10
{
11
12
    /**
13
     * @var \DateTimeImmutable
14
     */
15
    private $dateCreated;
16
17
    private $aggregateId;
18
    private $authenticatedUserId;
19
20
    /* @var string */
21
    private $aggregateClass;
22
    private $commandMetadata;
23
24
    /** @var int */
25
    private $sequence = null;
26
27
    /** @var int */
28
    private $index = null;
29
30 20
    public function __construct(
31
        $aggregateId,
32
        string $aggregateClass,
33
        \DateTimeImmutable $dateCreated,
34
        $authenticatedUserId = null,
35
        $commandMetadata = null
36
    )
37
    {
38 20
        $this->dateCreated = $this->addTimeZone($dateCreated);
39 20
        $this->aggregateId = $aggregateId;
40 20
        $this->authenticatedUserId = $authenticatedUserId;
41 20
        $this->aggregateClass = $aggregateClass;
42 20
        $this->commandMetadata = $commandMetadata;
43 20
    }
44
45 1
    public function getDateCreated(): \DateTimeImmutable
46
    {
47 1
        return $this->dateCreated;
48
    }
49
50 2
    public function getAggregateId()
51
    {
52 2
        return $this->aggregateId;
53
    }
54
55 2
    public function getAggregateClass()
56
    {
57 2
        return $this->aggregateClass;
58
    }
59
60 1
    public function getAuthenticatedUserId()
61
    {
62 1
        return $this->authenticatedUserId;
63
    }
64
65 1
    public function getCommandMetadata()
66
    {
67 1
        return $this->commandMetadata;
68
    }
69
70 20
    private function addTimeZone(\DateTimeImmutable $dateCreated): \DateTimeImmutable
71
    {
72 20
        return $dateCreated->getTimezone() ? $dateCreated :
73 20
            ($dateCreated->setTimezone(new \DateTimeZone('Europe/Bucharest')) ?: $dateCreated);
74
    }
75
76 4
    public function withSequenceAndIndex(int $sequence, int $index):self
77
    {
78 4
        $other = clone $this;
79 4
        $other->sequence = $sequence;
80 4
        $other->index = $index;
81 4
        return $other;
82
    }
83
84 1
    public function getSequence(): ?int
85
    {
86 1
        return $this->sequence;
87
    }
88
89 1
    public function getIndex(): ?int
90
    {
91 1
        return $this->index;
92
    }
93
}