Completed
Push — master ( ae33d0...4cfbd0 )
by Rémi
03:25
created

ListenerTrait::getHandleMethod()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
ccs 0
cts 3
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
namespace MessageApp\Listener;
4
5
use League\Event\EventInterface;
6
7
trait ListenerTrait
8
{
9
    /**
10
     * @inheritDoc
11
     */
12
    public function handle(EventInterface $event)
13
    {
14
        $method = $this->getHandleMethod($event);
15
16
        if (! method_exists($this, $method)) {
17
            return;
18
        }
19
20
        $this->$method($event);
21
    }
22
23
    private function getHandleMethod(EventInterface $event)
24
    {
25
        $classParts = explode('\\', get_class($event));
26
27
        return 'handle' . end($classParts);
28
    }
29
30
    /**
31
     * @inheritDoc
32
     */
33
    public function isListener($listener)
34
    {
35
        return $listener === $this;
36
    }
37
}
38