Passed
Push — master ( 2279c5...1edf79 )
by Mr
06:36
created

EventProjectorMap::findFor()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 9
ccs 0
cts 9
cp 0
crap 12
rs 10
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the daikon-cqrs/read-model 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\ReadModel\Projector;
10
11
use Daikon\DataStructure\TypedMapInterface;
12
use Daikon\DataStructure\TypedMapTrait;
0 ignored issues
show
Bug introduced by
The type Daikon\DataStructure\TypedMapTrait 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...
13
use Daikon\EventSourcing\Aggregate\Event\DomainEventInterface;
14
15
final class EventProjectorMap implements TypedMapInterface
16
{
17
    use TypedMapTrait;
18
19
    public function __construct(iterable $eventProjectors = [])
20
    {
21
        $this->init($eventProjectors, [EventProjectorInterface::class]);
22
    }
23
24
    public function findFor(DomainEventInterface $event): ProjectorMap
25
    {
26
        $projectors = [];
27
        foreach ($this as $projectorKey => $eventProjector) {
28
            if ($eventProjector->matches($event)) {
29
                $projectors[$projectorKey] = $eventProjector->getProjector();
30
            }
31
        }
32
        return new ProjectorMap($projectors);
33
    }
34
}
35