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
03:02
created

MapBased   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 12
dl 0
loc 36
rs 10
c 0
b 0
f 0
ccs 14
cts 14
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addConverter() 0 9 2
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 addConverter(string $domainEventClass, Converter $converter) : void
19
    {
20 6
        if (! class_exists($domainEventClass)) {
21 1
            throw new InvalidArgumentException(
22 1
                sprintf('Domain Event \"%s\" does not exist', $domainEventClass)
23
            );
24
        }
25
26 5
        $this->conversionMap[$domainEventClass] = $converter;
27 5
    }
28
29
    /**
30
     * @return OutboxEntry[]
31
     *
32
     * @var DomainEvent[] $domainEvents
33
     */
34 5
    public function convert(DomainEvent ...$domainEvents) : array
35
    {
36 5
        $outboxEntries = [];
37
38 5
        foreach ($domainEvents as $domainEvent) {
39 4
            if (! isset($this->conversionMap[get_class($domainEvent)])) {
40 2
                continue;
41
            }
42
43 4
            $converter = $this->conversionMap[get_class($domainEvent)];
44
45 4
            $outboxEntries[] = $converter->convert($domainEvent);
46
        }
47
48 5
        return $outboxEntries;
49
    }
50
}
51