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.
Completed
Pull Request — develop (#34)
by Boy
03:11
created

LocaleCookieListener::onKernelResponse()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 22
rs 8.9197
cc 4
eloc 12
nc 3
nop 1
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));
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal Set locale cookie to %s does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
80
    }
81
}
82