Passed
Push — master ( 6d1632...ddd5df )
by Thorsten
01:48
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 hasKnownAggregateRevision() 0 4 1
A __construct() 0 5 1
A toArray() 0 7 1
A getKnownAggregateRevision() 0 4 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;
12
13
abstract class Command implements CommandInterface
14
{
15
    /** @var AggregateIdInterface */
16
    private $aggregateId;
17
18
    /** @var AggregateRevision */
19
    private $knownAggregateRevision;
20
21 4
    public function getAggregateId(): AggregateIdInterface
22
    {
23 4
        return $this->aggregateId;
24
    }
25
26 1
    public function getKnownAggregateRevision(): AggregateRevision
27
    {
28 1
        return $this->knownAggregateRevision;
29
    }
30
31
    public function hasKnownAggregateRevision(): bool
32
    {
33
        return !$this->knownAggregateRevision->isEmpty();
34
    }
35
36 1
    public function toArray(): array
37
    {
38
        return [
39 1
            'aggregateId' => $this->aggregateId->toNative(),
40 1
            'knownAggregateRevision' => $this->knownAggregateRevision->toNative()
41
        ];
42
    }
43
44 5
    protected function __construct(AggregateIdInterface $aggregateId, AggregateRevision $knownAggregateRevision = null)
45
    {
46 5
        $this->aggregateId = $aggregateId;
47 5
        $this->knownAggregateRevision = $knownAggregateRevision ?? AggregateRevision::makeEmpty();
0 ignored issues
show
Documentation Bug introduced by
$knownAggregateRevision ...teRevision::makeEmpty() is of type object<Daikon\Entity\Val...t\ValueObjectInterface>, but the property $knownAggregateRevision was declared to be of type object<Daikon\EventSourc...gate\AggregateRevision>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
48 5
    }
49
}
50