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   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
eloc 17
dl 0
loc 49
rs 10
c 0
b 0
f 0
ccs 19
cts 19
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 4
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 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