RequestListener::onKernelRequest()   B
last analyzed

Complexity

Conditions 5
Paths 9

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 15
rs 8.8571
cc 5
eloc 8
nc 9
nop 1
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\SettingsBundle\EventListener;
13
14
use ONGR\CookiesBundle\Cookie\Model\GenericCookie;
15
use ONGR\SettingsBundle\Service\SettingsManager;
16
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
17
18
class RequestListener
19
{
20
    /**
21
     * @var GenericCookie
22
     */
23
    private $profileCookie;
24
25
    /**
26
     * @var GenericCookie
27
     */
28
    private $experimentCookie;
29
30
    /**
31
     * @var SettingsManager
32
     */
33
    private $settingsManager;
34
35
    public function __construct($profileCookie, $experimentCookie, $settingsManager)
36
    {
37
        $this->profileCookie = $profileCookie;
38
        $this->experimentCookie = $experimentCookie;
39
        $this->settingsManager = $settingsManager;
40
    }
41
42
    public function onKernelRequest(GetResponseEvent $event)
43
    {
44
        if (!$event->isMasterRequest()) {
45
            return;
46
        }
47
48
        $profileCookie = $this->profileCookie->getValue() ? $this->profileCookie->getValue() : [];
49
        $expCookie = $this->experimentCookie->getValue() ? $this->experimentCookie->getValue() : [];
50
51
        $profiles = array_merge($profileCookie, $expCookie);
52
53
        if (is_array($profiles)) {
54
            $this->settingsManager->appendActiveProfilesList($profiles);
55
        }
56
    }
57
}
58