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

Commit::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

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