Completed
Push — master ( 119f00...f45d38 )
by Filipe
04:26
created

GreedyStrategy   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 19
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 10 2
1
<?php
2
3
/**
4
 * This file is part of slick/cqrs-tools
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\CQRSTools\Application\Projection\EventHandlingStrategy;
11
12
use Slick\CQRSTools\Application\Exception\InvalidProjectorUsageException;
13
use Slick\CQRSTools\Application\Projection\EventHandlingStrategy;
14
use Slick\CQRSTools\Application\Projection\GreedyProjector;
15
use Slick\CQRSTools\Application\Projection\Projector;
16
use Slick\CQRSTools\Event;
17
18
/**
19
 * GreedyStrategy
20
 *
21
 * @package Slick\CQRSTools\Application\Projection\EventHandlingStrategy
22
*/
23
final class GreedyStrategy implements EventHandlingStrategy
24
{
25
    /**
26
     * Handles the event processing into projector
27
     *
28
     * @param Event     $event
29
     * @param Projector $projector
30
     */
31
    public function handle(Event $event, Projector $projector): void
32
    {
33
        if (! $projector instanceof GreedyProjector) {
34
            throw new InvalidProjectorUsageException(
35
                "Need to use a greedy projector with a greedy event handling strategy."
36
            );
37
        }
38
39
        $projector->handle($event);
40
    }
41
}
42