RequestAwareEventListener::onAction()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
ccs 6
cts 6
cp 1
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Pgs\RestfonyBundle\EventListener;
4
5
use Pgs\RestfonyBundle\Event\RequestAwareEventInterface;
6
use Symfony\Component\HttpFoundation\Request;
7
8
/**
9
 * ControllerEventListener
10
 * @author Karol Joński <[email protected]>
11
 */
12
abstract class RequestAwareEventListener
13
{
14 2
    protected function getControllerMethod(Request $request)
15
    {
16 2
        $controller = $request->attributes->get('_controller');
17 2
        if ($controller) {
18 1
            $params = explode(':', $controller);
19 1
            return $params[1];
20
        }
21 1
        return false;
22
    }
23
24 2
    public function onAction(RequestAwareEventInterface $event)
25
    {
26 2
        $action = $this->getControllerMethod($event->getRequest());
27 2
        $listenerMethodName = sprintf('on%s', ucfirst($action));
28 2
        if (method_exists($this, $listenerMethodName)) {
29 1
            $this->{$listenerMethodName}($event);
30
        }
31 2
    }
32
}
33