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.

KernelResponseListener   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 7
Bugs 2 Features 0
Metric Value
wmc 7
c 7
b 2
f 0
lcom 1
cbo 7
dl 0
loc 49
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A addPjaxVersion() 0 9 3
A pjaxRedirect() 0 15 3
1
<?php
2
namespace Strontium\PjaxBundle\EventListener;
3
4
use Strontium\PjaxBundle\Helper\PjaxHelperInterface;
5
use Symfony\Component\HttpFoundation\Cookie;
6
use Symfony\Component\HttpFoundation\Response;
7
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
8
9
class KernelResponseListener
10
{
11
    /**
12
     * @var PjaxHelperInterface
13
     */
14
    protected $pjax;
15
16
    /**
17
     * @param PjaxHelperInterface $pjax
18
     */
19
    public function __construct(PjaxHelperInterface $pjax)
20
    {
21
        $this->pjax = $pjax;
22
    }
23
24
    /**
25
     * @param FilterResponseEvent $event
26
     */
27
    public function addPjaxVersion(FilterResponseEvent $event)
28
    {
29
        $request = $event->getRequest();
30
31
        if ($this->pjax->isPjaxRequest($request) && $this->pjax->haveGenerator()) {
32
            $response = $event->getResponse();
33
            $response->headers->set('X-PJAX-Version', $this->pjax->generateVersion($request));
34
        }
35
    }
36
37
    /**
38
     * @param FilterResponseEvent $event
39
     *
40
     * @return Response
41
     */
42
    public function pjaxRedirect(FilterResponseEvent $event)
43
    {
44
        $request = $event->getRequest();
45
        $response = $event->getResponse();
46
47
        if ($this->pjax->isPjaxRequest($request) && $response->isRedirect()) {
48
            $redirectCookieName = sprintf('pjax_redirect_%s', $request->headers->get('X-PJAX-Target'));
49
            $redirectTo = $response->headers->get('Location');
50
            $response->headers->setCookie(
51
                new Cookie(rawurlencode($redirectCookieName), $redirectTo, 0, '/', null, false, false)
0 ignored issues
show
Bug introduced by
It seems like $redirectTo defined by $response->headers->get('Location') on line 49 can also be of type array; however, Symfony\Component\HttpFo...n\Cookie::__construct() does only seem to accept string|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
52
            );
53
        }
54
55
        return $response;
56
    }
57
}
58