RequestAcceptedListener::onKernelView()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
ccs 8
cts 8
cp 1
rs 9.4285
cc 3
eloc 7
nc 3
nop 1
crap 3
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