GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

LocaleCookieListener   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 55
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A onKernelResponse() 0 22 4
1
<?php
2
3
/**
4
 * Copyright 2014 SURFnet bv
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupBundle\EventListener;
20
21
use Psr\Log\LoggerInterface;
22
use Surfnet\StepupBundle\Http\CookieHelper;
23
use Surfnet\StepupBundle\Service\LocaleProviderService;
24
use Symfony\Component\HttpFoundation\Cookie;
25
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
26
27
final class LocaleCookieListener
28
{
29
    /**
30
     * @var Cookie
31
     */
32
    private $cookieHelper;
33
34
    /**
35
     * @var LocaleProviderService
36
     */
37
    private $localeProvider;
38
39
    /**
40
     * @var LoggerInterface
41
     */
42
    private $logger;
43
44
    public function __construct(
45
        CookieHelper $cookieHelper,
46
        LocaleProviderService $localeProvider,
47
        LoggerInterface $logger
48
    ) {
49
        $this->cookieHelper = $cookieHelper;
0 ignored issues
show
Documentation Bug introduced by
It seems like $cookieHelper of type object<Surfnet\StepupBundle\Http\CookieHelper> is incompatible with the declared type object<Symfony\Component\HttpFoundation\Cookie> of property $cookieHelper.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
50
        $this->localeProvider = $localeProvider;
51
        $this->logger = $logger;
52
    }
53
54
    /**
55
     * If there is a logged in user with a preferred language, set it as a cookie.
56
     *
57
     * @param FilterResponseEvent $event
58
     */
59
    public function onKernelResponse(FilterResponseEvent $event)
60
    {
61
        $locale = $this->localeProvider->determinePreferredLocale();
62
63
        // Unable to determine preferred locale? No need to hand out a cookie then.
64
        if (empty($locale)) {
65
            return;
66
        }
67
68
        // Did the request already contain the proper cookie value? No need to hand out a cookie then.
69
        $requestCookie = $this->cookieHelper->read($event->getRequest());
0 ignored issues
show
Bug introduced by
The method read() does not seem to exist on object<Symfony\Component\HttpFoundation\Cookie>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
70
        if ($requestCookie && $requestCookie->getValue() === $locale) {
71
            $this->logger->debug(sprintf(
72
                'Locale cookie already set to "%s", nothing to do here',
73
                $locale
74
            ));
75
            return;
76
        }
77
78
        $this->cookieHelper->write($event->getResponse(), $locale);
0 ignored issues
show
Bug introduced by
The method write() does not seem to exist on object<Symfony\Component\HttpFoundation\Cookie>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
79
        $this->logger->notice(sprintf("Set locale cookie to %s", $locale));
80
    }
81
}
82