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

MapBased   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

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 get_class;
10
use function sprintf;
11
12
final class MapBased extends EventsHandler
13
{
14
    /** @var converter[] */
15
    private $conversionMap;
16
17
    /**
18
     * @param converter[] $conversionMap
19
     */
20
    public function __construct(OutboxMappedSuperclass $outboxMappedSuperclass, array $conversionMap)
21
    {
22
        $this->outboxMappedSuperclass = $outboxMappedSuperclass;
23
24
        foreach ($conversionMap as $converter) {
25
            if (! $converter instanceof Converter) {
26
                throw new InvalidArgumentException(
27
                    sprintf('%s class must implements Converter interface', get_class($converter))
28
                );
29
            }
30
        }
31
32
        $this->conversionMap = $conversionMap;
33
    }
34
35
    /**
36
     * @param DomainEvent[] $domainEvents
37
     *
38
     * @return OutboxEntry[]
39
     */
40
    public function convert(DomainEvent ...$domainEvents) : array
41
    {
42
        $outboxEntries = [];
43
44
        foreach ($domainEvents as $domainEvent) {
45
            if (! isset($this->conversionMap[get_class($domainEvent)])) {
46
                continue;
47
            }
48
49
            $converterClass = $this->conversionMap[get_class($domainEvent)];
50
51
            $outboxEntries[] = $converterClass->convert($domainEvent);
52
        }
53
54
        return $outboxEntries;
55
    }
56
}
57