RequestAcceptedListener::getSubscribedEvents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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