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:01 queued 55s
created

MapBased::__construct()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 19
rs 9.9666
c 0
b 0
f 0
ccs 10
cts 10
cp 1
cc 4
nc 4
nop 2
crap 4
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
    /**
19
     * @param converter[] $conversionMap
20
     */
21 5
    public function __construct(OutboxMappedSuperclass $outboxMappedSuperclass, array $conversionMap)
22
    {
23 5
        $this->outboxMappedSuperclass = $outboxMappedSuperclass;
24
25 5
        foreach ($conversionMap as $domainEvent => $converter) {
26 5
            if (! class_exists($domainEvent)) {
27 1
                throw new InvalidArgumentException(
28 1
                    sprintf('Domain Event \"%s\" does not exist', $domainEvent)
29
                );
30
            }
31
32 4
            if (! $converter instanceof Converter) {
33 1
                throw new InvalidArgumentException(
34 4
                    sprintf('%s class must implements Converter interface', get_class($converter))
35
                );
36
            }
37
        }
38
39 3
        $this->conversionMap = $conversionMap;
40 3
    }
41
42
    /**
43
     * @param DomainEvent[] $domainEvents
44
     *
45
     * @return OutboxEntry[]
46
     */
47 3
    public function convert(DomainEvent ...$domainEvents) : array
48
    {
49 3
        $outboxEntries = [];
50
51 3
        foreach ($domainEvents as $domainEvent) {
52 3
            if (! isset($this->conversionMap[get_class($domainEvent)])) {
53 2
                continue;
54
            }
55
56 3
            $converterClass = $this->conversionMap[get_class($domainEvent)];
57
58 3
            $outboxEntries[] = $converterClass->convert($domainEvent);
59
        }
60
61 3
        return $outboxEntries;
62
    }
63
}
64