ListenerTrait::getHandleMethod()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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