MethodNameStrategy   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 12 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
     * @return bool
30
     */
31
    public function handle(Event $event, Projector $projector): bool
32
    {
33
        $classNamespaces = explode("\\", get_class($event));
34
        $eventName = end($classNamespaces);
35
        $methodName = "when{$eventName}";
36
        if (method_exists($projector, $methodName)) {
37
            $projector->$methodName($event);
38
            return true;
39
        }
40
41
        return false;
42
    }
43
}
44