RequestAwareEventListener   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 21
rs 10
ccs 12
cts 12
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getControllerMethod() 0 9 2
A onAction() 0 8 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