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:04
created

LocaleCookieListener::onKernelResponse()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 22
rs 9.2
cc 3
eloc 12
nc 3
nop 1
1
<?php
2
3
namespace Surfnet\StepupBundle\EventListener;
4
5
use Psr\Log\LoggerInterface;
6
use Surfnet\StepupBundle\Service\LocaleProviderService;
7
use Surfnet\StepupBundle\Value\CookieSettings;
8
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
9
10
final class LocaleCookieListener
11
{
12
    /**
13
     * @var CookieSettings
14
     */
15
    private $cookieSettings;
16
17
    /**
18
     * @var LocaleProviderService
19
     */
20
    private $localeProvider;
21
22
    /**
23
     * @var LoggerInterface
24
     */
25
    private $logger;
26
27
    public function __construct(
28
        CookieSettings $cookieSettings,
29
        LocaleProviderService $localeProvider,
30
        LoggerInterface $logger
31
    ) {
32
        $this->cookieSettings = $cookieSettings;
33
        $this->localeProvider = $localeProvider;
34
        $this->logger = $logger;
35
    }
36
37
    /**
38
     * If there is a logged in user with a preferred language, set it as a cookie.
39
     *
40
     * @param FilterResponseEvent $event
41
     */
42
    public function onKernelResponse(FilterResponseEvent $event)
43
    {
44
        $locale = $this->localeProvider->determinePreferredLocale();
45
46
        // Unable to determine preferred locale.
47
        if (!$locale) {
48
            return;
49
        }
50
51
        $valueFromCookie = $this->cookieSettings->value($event->getRequest());
52
        if ($valueFromCookie === $locale) {
53
            $this->logger->info(sprintf(
54
                'Locale cookie already set to "%s", nothing to do here',
55
                $locale
56
            ));
57
            return;
58
        }
59
60
        $event->getResponse()->headers->setCookie($this->cookieSettings->toCookie($locale));
61
62
        $this->logger->info(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...
63
    }
64
}
65