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

DomainEvent   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 39
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getAggregateId() 0 4 1
A getAggregateRevision() 0 4 1
A withAggregateRevision() 0 6 1
A __construct() 0 5 1
A toArray() 0 7 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