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

ProjectorService::handle()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
c 0
b 0
f 0
rs 9.2
cc 4
eloc 10
nc 4
nop 1
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