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.

MapBased   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 12
c 1
b 0
f 0
dl 0
loc 34
rs 10
ccs 13
cts 13
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
10
use function class_exists;
11
use function sprintf;
12
13
final class MapBased extends EventsHandler
14
{
15
    /** @var Converter[] */
16
    private array $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
    public function convert(DomainEvent ...$domainEvents): array
33
    {
34 5
        $outboxEntries = [];
35
36 5
        foreach ($domainEvents as $domainEvent) {
37
            if (! isset($this->conversionMap[$domainEvent::class])) {
38 5
                continue;
39 4
            }
40 3
41
            $converter = $this->conversionMap[$domainEvent::class];
42
43 4
            $outboxEntries[] = $converter->convert($domainEvent);
44
        }
45 4
46
        return $outboxEntries;
47
    }
48
}
49