Completed
Push — master ( 860638...4d5894 )
by Frank
02:47 queued 01:15
created

UpcasterStub::canUpcast()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 2
crap 2
1
<?php
2
3
namespace EventSauce\EventSourcing\Integration\Upcasting;
4
5
use EventSauce\EventSourcing\Serialization\EventType;
6
use EventSauce\EventSourcing\Upcasting\DelegatableUpcaster;
7
use Generator;
8
9
class UpcasterStub implements DelegatableUpcaster
10
{
11
    public function canUpcast(string $type, int $version): bool
12
    {
13
        return $this->type() === $type && $version < 1;
14
    }
15
16
    public function upcast(string $type, int $version, array $payload): Generator
17
    {
18
        $payload['data']['property'] = 'upcasted';
19
        $payload['version'] = 1;
20
21
        yield $payload;
22
    }
23
24
    public function type(): string
25
    {
26
        return EventType::fromClassName(UpcastedEventStub::class)->toEventName();
27
    }
28
}