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

Command   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 84.62%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 37
ccs 11
cts 13
cp 0.8462
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getAggregateId() 0 4 1
A getKnownAggregateRevision() 0 4 1
A hasKnownAggregateRevision() 0 4 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\Command;
12
13
use Daikon\EventSourcing\Aggregate\AggregateIdInterface;
14
use Daikon\EventSourcing\Aggregate\AggregateRevision;
15
16
abstract class Command implements CommandInterface
17
{
18
    /** @var AggregateIdInterface */
19
    private $aggregateId;
20
21
    /** @var AggregateRevision */
22
    private $knownAggregateRevision;
23
24 3
    public function getAggregateId(): AggregateIdInterface
25
    {
26 3
        return $this->aggregateId;
27
    }
28
29 1
    public function getKnownAggregateRevision(): AggregateRevision
30
    {
31 1
        return $this->knownAggregateRevision;
32
    }
33
34
    public function hasKnownAggregateRevision(): bool
35
    {
36
        return !$this->knownAggregateRevision->isEmpty();
37
    }
38
39 1
    public function toArray(): array
40
    {
41
        return [
42 1
            'aggregateId' => $this->aggregateId->toNative(),
43 1
            'knownAggregateRevision' => $this->knownAggregateRevision->toNative()
44
        ];
45
    }
46
47 4
    protected function __construct(AggregateIdInterface $aggregateId, AggregateRevision $knownAggregateRevision = null)
48
    {
49 4
        $this->aggregateId = $aggregateId;
50 4
        $this->knownAggregateRevision = $knownAggregateRevision ?? AggregateRevision::makeEmpty();
51 4
    }
52
}
53