RequestAcceptedListener   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A onKernelView() 0 13 3
A getSubscribedEvents() 0 4 1
1
<?php
2
3
namespace Alchemy\RestBundle\EventListener;
4
5
use Alchemy\Rest\Result\RequestAcceptedResult;
6
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
7
use Symfony\Component\HttpFoundation\JsonResponse;
8
use Symfony\Component\HttpFoundation\Response;
9
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
10
use Symfony\Component\HttpKernel\KernelEvents;
11
12
class RequestAcceptedListener implements EventSubscriberInterface
13
{
14
15 6
    public function onKernelView(GetResponseForControllerResultEvent $event)
16
    {
17 6
        $result = $event->getControllerResult();
18
19 6
        if (! $result instanceof RequestAcceptedResult) {
20 2
            return;
21
        }
22
23 4
        $metadata = $result->getMetadata();
24 4
        $response = empty($metadata) ? new Response('', 202) : new JsonResponse($metadata, 202);
25
26 4
        $event->setControllerResult($response);
27 4
    }
28
29 2
    public static function getSubscribedEvents()
30
    {
31 2
        return array(KernelEvents::VIEW => 'onKernelView');
32
    }
33
}
34