Passed
Push — master ( 7dc569...e9ad93 )
by Mr
08:03
created

EventProjector   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 30
ccs 0
cts 10
cp 0
rs 10
c 1
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getEventExpressions() 0 3 1
A matches() 0 7 2
A getProjector() 0 3 1
A __construct() 0 4 1
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the daikon-cqrs/boot project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Daikon\Boot\ReadModel;
10
11
use Daikon\EventSourcing\Aggregate\Event\DomainEventInterface;
12
use Daikon\ReadModel\Projector\EventProjectorInterface;
13
use Daikon\ReadModel\Projector\ProjectorInterface;
14
15
final class EventProjector implements EventProjectorInterface
16
{
17
    private array $eventExpressions;
18
19
    private ProjectorInterface $projector;
20
21
    public function __construct(array $eventExpressions, ProjectorInterface $projector)
22
    {
23
        $this->eventExpressions = $eventExpressions;
24
        $this->projector = $projector;
25
    }
26
27
    public function matches(DomainEventInterface $event): bool
28
    {
29
        $eventFqcn = get_class($event);
30
        return array_reduce(
31
            $this->eventExpressions,
32
            fn(bool $carry, string $eventExpression): bool => $carry || $eventExpression === $eventFqcn,
33
            false
34
        );
35
    }
36
37
    public function getProjector(): ProjectorInterface
38
    {
39
        return $this->projector;
40
    }
41
42
    public function getEventExpressions(): array
43
    {
44
        return $this->eventExpressions;
45
    }
46
}
47