Completed
Push — master ( 024186...18bea3 )
by Peter
06:06
created

SwitchListenerTrait::getMethodNameFromEvent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * GpsLab component.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2016, Peter Gribanov
7
 * @license   http://opensource.org/licenses/MIT
8
 */
9
10
namespace GpsLab\Domain\Event\Listener;
11
12
use GpsLab\Domain\Event\EventInterface;
13
use GpsLab\Domain\Event\NameResolver\NameResolverContainer;
14
15
trait SwitchListenerTrait
16
{
17
    /**
18
     * @param EventInterface $event
19
     */
20 1 View Code Duplication
    public function handle(EventInterface $event)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
    {
22 1
        $method = $this->getMethodNameFromEvent($event);
23
24
        // if method is not exists is not a critical error
25 1
        if (method_exists($this, $method)) {
26 1
            call_user_func([$this, $method], $event);
27 1
        }
28 1
    }
29
30
    /**
31
     * Get handler method name from event.
32
     *
33
     * Override this method if you want to change algorithm to generate the handler method name.
34
     *
35
     * @param EventInterface $event
36
     *
37
     * @return string
38
     */
39 1
    protected function getMethodNameFromEvent(EventInterface $event)
40
    {
41 1
        return 'handle'.NameResolverContainer::getResolver()->getEventName($event);
42
    }
43
}
44