Completed
Pull Request — master (#26)
by Valentyn
02:41
created

LocaleListener::getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
crap 1
1
<?php
2
3
namespace App\Translation\EventListener;
4
5
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
6
use Symfony\Component\HttpKernel\KernelEvents;
7
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
8
9
class LocaleListener implements EventSubscriberInterface
10
{
11 19
    public function onKernelRequest(GetResponseEvent $event)
12
    {
13 19
        $request = $event->getRequest();
14
15 19
        if ($request->query->has('language') === false) {
16 17
            return;
17
        }
18
19 2
        $locale = $request->query->get('language');
20
21 2
        if (empty($locale) || !$locale) {
22
            return;
23
        }
24
25 2
        $request->setLocale($locale);
26 2
    }
27
28 1
    static public function getSubscribedEvents()
0 ignored issues
show
Coding Style introduced by
As per PSR2, the static declaration should come after the visibility declaration.
Loading history...
29
    {
30
        return [
31
            // must be registered before the default Locale listener
32 1
            KernelEvents::REQUEST => [['onKernelRequest', 17]],
33
        ];
34
    }
35
}