BadRequestListener   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 21
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\BadRequestResult;
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 BadRequestListener implements EventSubscriberInterface
13
{
14 4
    public function onKernelView(GetResponseForControllerResultEvent $event)
15
    {
16 4
        $result = $event->getControllerResult();
17
18 4
        if (! $result instanceof BadRequestResult) {
19 2
            return;
20
        }
21
22 2
        $metadata = $result->getMetadata();
23 2
        $response = empty($metadata) ? new Response('', 400) : new JsonResponse($metadata, 400);
24
25 2
        $event->setControllerResult($response);
26 2
    }
27
28 2
    public static function getSubscribedEvents()
29
    {
30 2
        return array(KernelEvents::VIEW => 'onKernelView');
31
    }
32
}
33