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

UpcasterStub   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 20
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0
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
}