Passed
Push — master ( 6d1632...ddd5df )
by Thorsten
01:48
created

DomainEvent::withAggregateRevision()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
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;
12
13
abstract class DomainEvent implements DomainEventInterface
14
{
15
    /** @var AggregateIdInterface */
16
    private $aggregateId;
17
18
    /** @var AggregateRevision */
19
    private $aggregateRevision;
20
21 7
    public function getAggregateId(): AggregateIdInterface
22
    {
23 7
        return $this->aggregateId;
24
    }
25
26 3
    public function getAggregateRevision(): AggregateRevision
27
    {
28 3
        return $this->aggregateRevision;
29
    }
30
31 3
    public function withAggregateRevision(AggregateRevision $aggregateRevision): DomainEventInterface
32
    {
33 3
        $copy = clone $this;
34 3
        $copy->aggregateRevision = $aggregateRevision;
35 3
        return $copy;
36
    }
37
38 2
    public function toArray(): array
39
    {
40
        return [
41 2
            'aggregateId' => $this->aggregateId->toNative(),
42 2
            'aggregateRevision' => $this->aggregateRevision->toNative()
43
        ];
44
    }
45
46 8
    protected function __construct(AggregateIdInterface $aggregateId, AggregateRevision $aggregateRevision = null)
47
    {
48 8
        $this->aggregateId = $aggregateId;
49 8
        $this->aggregateRevision = $aggregateRevision ?? AggregateRevision::makeEmpty();
0 ignored issues
show
Documentation Bug introduced by
$aggregateRevision ?? \D...teRevision::makeEmpty() is of type object<Daikon\Entity\Val...t\ValueObjectInterface>, but the property $aggregateRevision 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...
50 8
    }
51
}
52