Passed
Push — master ( eaff52...7bdb3a )
by Mr
02:17
created

ProjectorService::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
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\Boot\Service\Provisioner\MessageBusProvisioner;
0 ignored issues
show
Bug introduced by
The type Daikon\Boot\Service\Prov...r\MessageBusProvisioner was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Daikon\EventSourcing\EventStore\Commit\CommitInterface;
13
use Daikon\Interop\Assertion;
14
use Daikon\MessageBus\EnvelopeInterface;
15
use Daikon\MessageBus\MessageBusInterface;
16
use Daikon\ReadModel\Projector\EventProjectorMap;
17
use Daikon\ReadModel\Projector\ProjectorInterface;
18
use Daikon\ReadModel\Projector\ProjectorServiceInterface;
19
20
final class ProjectorService implements ProjectorServiceInterface
21
{
22
    private EventProjectorMap $eventProjectorMap;
23
24
    private MessageBusInterface $messageBus;
25
26
    public function __construct(EventProjectorMap $eventProjectorMap, MessageBusInterface $messageBus)
27
    {
28
        $this->eventProjectorMap = $eventProjectorMap;
29
        $this->messageBus = $messageBus;
30
    }
31
32
    public function handle(EnvelopeInterface $envelope): void
33
    {
34
        /** @var CommitInterface $commit */
35
        $commit = $envelope->getMessage();
36
        Assertion::implementsInterface($commit, CommitInterface::class);
37
38
        $metadata = $envelope->getMetadata();
39
        foreach ($commit->getEventLog() as $event) {
40
            $projectors = $this->eventProjectorMap->findFor($event);
41
            $projectors->map(fn(string $key, ProjectorInterface $projector) => $projector->handle($envelope));
42
            $this->messageBus->publish($event, MessageBusProvisioner::EVENTS_CHANNEL, $metadata);
43
        }
44
    }
45
}
46