GreedyStrategy   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 11 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
     * @return bool
32
     */
33
    public function handle(Event $event, Projector $projector): bool
34
    {
35
        if (! $projector instanceof GreedyProjector) {
36
            throw new InvalidProjectorUsageException(
37
                "Need to use a greedy projector with a greedy event handling strategy."
38
            );
39
        }
40
41
        $projector->handle($event);
42
        return true;
43
    }
44
}
45