TranslateResponseListener   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSubscribedEvents() 0 6 1
A translate() 0 12 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Rest\ServerBundle\EventListener;
5
6
use Innmind\Rest\ServerBundle\Translator\ResponseTranslator;
7
use Innmind\Http\Message\Response;
8
use Symfony\Component\{
9
    EventDispatcher\EventSubscriberInterface,
10
    HttpKernel\KernelEvents,
11
    HttpKernel\Event\GetResponseForControllerResultEvent
12
};
13
14
final class TranslateResponseListener implements EventSubscriberInterface
15
{
16
    private $translator;
17
18 6
    public function __construct(ResponseTranslator $translator)
19
    {
20 6
        $this->translator = $translator;
21 6
    }
22
23
    /**
24
     * {@inheritdoc}
25
     */
26 38
    public static function getSubscribedEvents()
27
    {
28
        return [
29 38
            KernelEvents::VIEW => [['translate', -255]],
30
        ];
31
    }
32
33 4
    public function translate(GetResponseForControllerResultEvent $event)
34
    {
35 4
        $data = $event->getControllerResult();
36
37 4
        if (!$data instanceof Response) {
38 2
            return;
39
        }
40
41 2
        $event->setResponse(
42 2
            $this->translator->translate($data)
43
        );
44 2
    }
45
}
46