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:18
created

MapBased::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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