Response   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A onKernelResponse() 0 15 2
A getSubscribedEvents() 0 6 1
1
<?php
2
3
namespace Dafiti\Silex\Listener;
4
5
use Symfony\Component\HttpKernel\Event\GetResponseForControllerResultEvent;
6
use Symfony\Component\HttpKernel\KernelEvents;
7
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
8
use Dafiti\Silex\Response\Factory;
9
10
class Response implements EventSubscriberInterface
11
{
12
    /**
13
     * @param GetResponseForControllerResultEvent $event
14
     *
15
     * @return GetResponseForControllerResultEvent
16
     */
17
    public function onKernelResponse(GetResponseForControllerResultEvent $event)
18
    {
19
        if ($event->hasResponse()) {
20
            return $event;
21
        }
22
23
        $accept = $event->getRequest()->get('_accept');
24
25
        $responseFactory = new Factory($accept);
26
        $response = $responseFactory->create($event->getControllerResult());
27
28
        $event->setResponse($response);
29
30
        return $event;
31
    }
32
33
    public static function getSubscribedEvents()
34
    {
35
        return [
36
            KernelEvents::VIEW => ['onKernelResponse', 100],
37
        ];
38
    }
39
}
40