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

UpcasterStub::upcast()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
crap 1
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
}