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

Command::hasKnownAggregateRevision()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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