TranslateRequestListener::getSubscribedEvents()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
ccs 2
cts 2
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace Innmind\Rest\ServerBundle\EventListener;
5
6
use Innmind\Rest\ServerBundle\Translator\RequestTranslator;
7
use Symfony\Component\{
8
    EventDispatcher\EventSubscriberInterface,
9
    HttpKernel\KernelEvents,
10
    HttpKernel\Event\GetResponseEvent
11
};
12
13
final class TranslateRequestListener implements EventSubscriberInterface
14
{
15
    private $translator;
16
17 4
    public function __construct(RequestTranslator $translator)
18
    {
19 4
        $this->translator = $translator;
20 4
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 38
    public static function getSubscribedEvents()
26
    {
27
        return [
28 38
            KernelEvents::REQUEST => [['translate', 28]],
29
        ];
30
    }
31
32 2
    public function translate(GetResponseEvent $event)
33
    {
34 2
        $request = $event->getRequest();
35 2
        $request->attributes->set(
36 2
            '_innmind_request',
37 2
            $this->translator->translate($request)
38
        );
39 2
    }
40
}
41