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

MapBased   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
eloc 14
dl 0
loc 43
rs 10
c 0
b 0
f 0
ccs 16
cts 16
cp 1

2 Methods

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