Completed
Push — master ( 4803b3...959101 )
by Frank
03:46
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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A canUpcast() 0 4 2
A upcast() 0 7 1
A type() 0 4 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 1
    public function canUpcast(string $type, int $version): bool
12
    {
13 1
        return $this->type() === $type && $version < 1;
14
    }
15
16 1
    public function upcast(string $type, int $version, array $payload): Generator
17
    {
18 1
        $payload['data']['property'] = 'upcasted';
19 1
        $payload['version'] = 1;
20
21 1
        yield $payload;
22 1
    }
23
24 1
    public function type(): string
25
    {
26 1
        return EventType::fromClassName(UpcastedEventStub::class)->toEventName();
27
    }
28
}