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::convert()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 15
rs 10
ccs 7
cts 7
cp 1
cc 3
nc 3
nop 1
crap 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