GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#7)
by Fábio Tadeu da
02:54
created

MapBased   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
eloc 13
dl 0
loc 41
rs 10
c 0
b 0
f 0
ccs 17
cts 17
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addConverter() 0 9 2
A __construct() 0 3 1
A convert() 0 15 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Dsantang\DomainEventsDoctrine\Outbox;
6
7
use Dsantang\DomainEvents\DomainEvent;
8
use InvalidArgumentException;
9
use function class_exists;
10
use function get_class;
11
use function sprintf;
12
13
final class MapBased extends EventsHandler
14
{
15
    /** @var Converter[] */
16
    private $conversionMap;
17
18 6
    public function __construct(OutboxMappedSuperclass $outboxMappedSuperclass)
19
    {
20 6
        $this->outboxMappedSuperclass = $outboxMappedSuperclass;
21 6
    }
22
23 6
    public function addConverter(string $domainEventClass, Converter $converter) : void
24
    {
25 6
        if (! class_exists($domainEventClass)) {
26 1
            throw new InvalidArgumentException(
27 1
                sprintf('Domain Event \"%s\" does not exist', $domainEventClass)
28
            );
29
        }
30
31 5
        $this->conversionMap[$domainEventClass] = $converter;
32 5
    }
33
34
    /**
35
     * @return OutboxEntry[]
36
     *
37
     * @var DomainEvent[] $domainEvents
38
     */
39 5
    public function convert(DomainEvent ...$domainEvents) : array
40
    {
41 5
        $outboxEntries = [];
42
43 5
        foreach ($domainEvents as $domainEvent) {
44 4
            if (! isset($this->conversionMap[get_class($domainEvent)])) {
45 2
                continue;
46
            }
47
48 4
            $converterClass = $this->conversionMap[get_class($domainEvent)];
49
50 4
            $outboxEntries[] = $converterClass->convert($domainEvent);
51
        }
52
53 5
        return $outboxEntries;
54
    }
55
}
56