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

DomainEvent::getAggregateRevision()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

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
eloc 2
nc 1
nop 0
crap 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