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

MethodNameStrategy   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 9 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\Projection\EventHandlingStrategy;
13
use Slick\CQRSTools\Application\Projection\Projector;
14
use Slick\CQRSTools\Event;
15
16
/**
17
 * MethodNameStrategy
18
 *
19
 * @package Slick\CQRSTools\Application\Projection\EventHandlingStrategy
20
*/
21
final class MethodNameStrategy implements EventHandlingStrategy
22
{
23
    /**
24
     * Handles the event processing into projector
25
     *
26
     * @param Event     $event
27
     * @param Projector $projector
28
     */
29
    public function handle(Event $event, Projector $projector): void
30
    {
31
        $classNamespaces = explode("\\", get_class($event));
32
        $eventName = end($classNamespaces);
33
        $methodName = "when{$eventName}";
34
        if (method_exists($projector, $methodName)) {
35
            $projector->$methodName($event);
36
        }
37
    }
38
}
39