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.

PjaxHelper::setVersionGenerator()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace Strontium\PjaxBundle\Helper;
3
4
use Strontium\PjaxBundle\VersionGenerator\VersionGeneratorInterface;
5
use Symfony\Component\HttpFoundation\Request;
6
7
class PjaxHelper implements PjaxHelperInterface
8
{
9
    /**
10
     * @var VersionGeneratorInterface
11
     */
12
    protected $versionGenerator;
13
14
    public function setVersionGenerator(VersionGeneratorInterface $versionGenerator)
15
    {
16
        $this->versionGenerator = $versionGenerator;
17
    }
18
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function isPjaxRequest(Request $request)
23
    {
24
        return (bool)$request->headers->get('X-PJAX', false);
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function generateVersion(Request $request)
31
    {
32
        return $this->haveGenerator() ? $this->versionGenerator->generate($request) : null;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function haveGenerator()
39
    {
40
        return null !== $this->versionGenerator;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function getTarget(Request $request)
47
    {
48
        if (!$this->isPjaxRequest($request)) {
49
            return null;
50
        }
51
        $target = $request->query->get('_pjax', $request->headers->get('X-PJAX-Container'));
52
53
        if (!preg_match('/\[data-pjax-container="([^"]+)"\]/', $target, $m)) {
54
            return null;
55
        }
56
        $target = $m[1];
57
58
        $redirectTarget = $request->headers->get('X-PJAX-Redirect-Target');
59
        if ($redirectTarget && $request->cookies->get(sprintf('pjax_redirect_%s', $target))) {
60
            return $redirectTarget;
61
        }
62
63
        return $target;
64
    }
65
}
66