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

EventProjector::matches()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
nc 1
nop 1
dl 0
loc 7
ccs 0
cts 3
cp 0
crap 6
rs 10
c 1
b 0
f 0
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