Passed
Push — master ( e12bb8...365767 )
by Thorsten
01:58
created

DomainEvent   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 39
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getAggregateId() 0 4 1
A getAggregateRevision() 0 4 1
A withAggregateRevision() 0 6 1
A toArray() 0 7 1
A __construct() 0 5 1
1
<?php
2
/**
3
 * This file is part of the daikon-cqrs/cqrs project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
declare(strict_types=1);
10
11
namespace Daikon\EventSourcing\Aggregate\Event;
12
13
use Daikon\EventSourcing\Aggregate\AggregateIdInterface;
14
use Daikon\EventSourcing\Aggregate\AggregateRevision;
15
16
abstract class DomainEvent implements DomainEventInterface
17
{
18
    /** @var AggregateIdInterface */
19
    private $aggregateId;
20
21
    /** @var AggregateRevision */
22
    private $aggregateRevision;
23
24 6
    public function getAggregateId(): AggregateIdInterface
25
    {
26 6
        return $this->aggregateId;
27
    }
28
29 3
    public function getAggregateRevision(): AggregateRevision
30
    {
31 3
        return $this->aggregateRevision;
32
    }
33
34 2
    public function withAggregateRevision(AggregateRevision $aggregateRevision): DomainEventInterface
35
    {
36 2
        $copy = clone $this;
37 2
        $copy->aggregateRevision = $aggregateRevision;
38 2
        return $copy;
39
    }
40
41 1
    public function toArray(): array
42
    {
43
        return [
44 1
            'aggregateId' => $this->aggregateId->toNative(),
45 1
            'aggregateRevision' => $this->aggregateRevision->toNative()
46
        ];
47
    }
48
49 7
    protected function __construct(AggregateIdInterface $aggregateId, AggregateRevision $aggregateRevision = null)
50
    {
51 7
        $this->aggregateId = $aggregateId;
52 7
        $this->aggregateRevision = $aggregateRevision ?? AggregateRevision::makeEmpty();
53 7
    }
54
}
55