Test Failed
Push — master ( deb397...eab8d5 )
by Mr
01:40
created

ProjectorService   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 27
c 0
b 0
f 0
wmc 5
lcom 1
cbo 4
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 17 4
1
<?php
2
3
namespace Daikon\Dbal\Projector;
4
5
use Assert\Assertion;
6
use Daikon\Cqrs\Aggregate\AggregatePrefix;
7
use Daikon\Cqrs\EventStore\CommitInterface;
8
use Daikon\Dbal\Exception\DbalException;
9
use Daikon\MessageBus\EnvelopeInterface;
10
11
final class ProjectorService implements ProjectorServiceInterface
12
{
13
    private $projectorMap;
14
15
    public function __construct(ProjectorMap $projectorMap)
16
    {
17
        $this->projectorMap = $projectorMap;
18
    }
19
20
    public function handle(EnvelopeInterface $envelope): bool
21
    {
22
        $commit = $envelope->getMessage();
23
        Assertion::implementsInterface($commit, CommitInterface::class);
24
25
        foreach ($commit->getEventLog() as $domainEvent) {
26
            $aggregatePrefix = AggregatePrefix::fromFqcn($domainEvent->getAggregateRootClass());
27
            $projectors = $this->projectorMap->filterByAggregatePrefix($aggregatePrefix);
28
            foreach ($projectors->getIterator() as $projector) {
29
                if (!$projector->handle($envelope)) {
30
                    throw new DbalException('Projector %s failed to handle message.');
31
                }
32
            }
33
        }
34
35
        return true;
36
    }
37
}
38