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.

RequestIdRequestResponseListener   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 7
dl 0
loc 43
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A onKernelRequest() 0 10 2
A onKernelResponse() 0 4 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 Surfnet\StepupBundle\Request\RequestId;
22
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
23
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
24
25
/**
26
 * When receiving a kernel request, reads the request ID from the X-Stepup-Request-Id header, if present, and sets it on
27
 * a RequestId instance.
28
 */
29
class RequestIdRequestResponseListener
30
{
31
    const HEADER_NAME = 'X-Stepup-Request-Id';
32
33
    /**
34
     * @var RequestId
35
     */
36
    private $requestId;
37
38
    /**
39
     * @param RequestId $requestId
40
     */
41
    public function __construct(RequestId $requestId)
42
    {
43
        $this->requestId = $requestId;
44
    }
45
46
    /**
47
     * If present, reads the request ID from the appropriate header and sets it on a RequestId instance.
48
     *
49
     * @param GetResponseEvent $event
50
     */
51
    public function onKernelRequest(GetResponseEvent $event)
52
    {
53
        $headers = $event->getRequest()->headers;
54
55
        if (!$headers->has(self::HEADER_NAME)) {
56
            return;
57
        }
58
59
        $this->requestId->set($headers->get(self::HEADER_NAME, null, true), true);
0 ignored issues
show
Unused Code introduced by
The call to HeaderBag::get() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
60
    }
61
62
    /**
63
     * If enabled, sets the request ID on the appropriate response header.
64
     *
65
     * @param FilterResponseEvent $event
66
     */
67
    public function onKernelResponse(FilterResponseEvent $event)
68
    {
69
        $event->getResponse()->headers->set(self::HEADER_NAME, $this->requestId->get());
70
    }
71
}
72