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

Commit   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 60%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 4
dl 0
loc 81
ccs 18
cts 30
cp 0.6
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getStreamId() 0 4 1
A getMetadata() 0 4 1
A make() 0 8 1
A fromArray() 0 9 1
A getStreamRevision() 0 4 1
A getAggregateRevision() 0 4 1
A getEventLog() 0 4 1
A toArray() 0 10 1
A __construct() 0 11 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\EventStore;
12
13
use Daikon\EventSourcing\Aggregate\AggregateRevision;
14
use Daikon\EventSourcing\Aggregate\DomainEventSequence;
15
use Daikon\MessageBus\MessageInterface;
16
use Daikon\MessageBus\Metadata\Metadata;
17
18
final class Commit implements CommitInterface
19
{
20
    /** @var StreamId */
21
    private $streamId;
22
23
    /** @var StreamRevision */
24
    private $streamRevision;
25
26
    /** @var DomainEventSequence */
27
    private $eventLog;
28
29
    /** @var Metadata */
30
    private $metadata;
31
32
    public static function make(
33
        StreamId $streamId,
34
        StreamRevision $streamRevision,
35
        DomainEventSequence $eventLog,
36
        Metadata $metadata
37
    ): CommitInterface {
38
        return new self($streamId, $streamRevision, $eventLog, $metadata);
39
    }
40
41 1
    public static function fromArray(array $state): MessageInterface
42
    {
43 1
        return new self(
44 1
            StreamId::fromNative($state['streamId']),
0 ignored issues
show
Compatibility introduced by
\Daikon\EventSourcing\Ev...ive($state['streamId']) of type object<Daikon\Entity\Val...t\ValueObjectInterface> is not a sub-type of object<Daikon\EventSourcing\EventStore\StreamId>. It seems like you assume a concrete implementation of the interface Daikon\Entity\ValueObject\ValueObjectInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
45 1
            StreamRevision::fromNative((int)$state['streamRevision']),
0 ignored issues
show
Compatibility introduced by
\Daikon\EventSourcing\Ev...tate['streamRevision']) of type object<Daikon\Entity\Val...t\ValueObjectInterface> is not a sub-type of object<Daikon\EventSourc...ntStore\StreamRevision>. It seems like you assume a concrete implementation of the interface Daikon\Entity\ValueObject\ValueObjectInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
46 1
            DomainEventSequence::fromArray($state['eventLog']),
47 1
            Metadata::fromArray($state['metadata'])
48
        );
49
    }
50
51
    public function getStreamId(): StreamId
52
    {
53
        return $this->streamId;
54
    }
55
56
    public function getStreamRevision(): StreamRevision
57
    {
58
        return $this->streamRevision;
59
    }
60
61
    public function getAggregateRevision(): AggregateRevision
62
    {
63
        return $this->eventLog->getHeadRevision();
64
    }
65
66
    public function getEventLog(): DomainEventSequence
67
    {
68
        return $this->eventLog;
69
    }
70
71
    public function getMetadata(): Metadata
72
    {
73
        return $this->metadata;
74
    }
75
76 1
    public function toArray(): array
77
    {
78
        return [
79 1
            '@type' => static::class,
80 1
            'streamId' => $this->streamId->toNative(),
81 1
            'streamRevision' => $this->streamRevision->toNative(),
82 1
            'eventLog' => $this->eventLog->toNative(),
83 1
            'metadata' => $this->metadata->toArray()
84
        ];
85
    }
86
87 1
    private function __construct(
88
        StreamId $streamId,
89
        StreamRevision $streamRevision,
90
        DomainEventSequence $eventLog,
91
        Metadata $metadata
92
    ) {
93 1
        $this->streamId = $streamId;
94 1
        $this->streamRevision = $streamRevision;
95 1
        $this->eventLog = $eventLog;
96 1
        $this->metadata = $metadata;
97 1
    }
98
}
99