TranslateResponseListener::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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