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.

FormAuthenticationHook::executeBefore()   B
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 32
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 8.439
c 0
b 0
f 0
cc 5
eloc 16
nc 6
nop 2
1
<?php
2
3
/**
4
 * eduVPN - End-user friendly VPN.
5
 *
6
 * Copyright: 2016-2017, The Commons Conservancy eduVPN Programme
7
 * SPDX-License-Identifier: AGPL-3.0+
8
 */
9
10
namespace SURFnet\VPN\Common\Http;
11
12
use fkooman\SeCookie\SessionInterface;
13
use SURFnet\VPN\Common\TplInterface;
14
15
class FormAuthenticationHook implements BeforeHookInterface
16
{
17
    /** @var \fkooman\SeCookie\SessionInterface */
18
    private $session;
19
20
    /** @var \SURFnet\VPN\Common\TplInterface */
21
    private $tpl;
22
23
    public function __construct(SessionInterface $session, TplInterface $tpl)
24
    {
25
        $this->session = $session;
26
        $this->tpl = $tpl;
27
    }
28
29
    public function executeBefore(Request $request, array $hookData)
30
    {
31
        if ('POST' === $request->getRequestMethod()) {
32
            // ignore POST to verify endpoint
33
            if ('/_form/auth/verify' === $request->getPathInfo()) {
34
                return;
35
            }
36
            // ignore POST to token endpoint
37
            if ('/_oauth/token' === $request->getPathInfo()) {
38
                return;
39
            }
40
        }
41
42
        if ($this->session->has('_form_auth_user')) {
43
            return $this->session->get('_form_auth_user');
44
        }
45
46
        // any other URL, enforce authentication
47
        $response = new Response(200, 'text/html');
48
        $response->setBody(
49
            $this->tpl->render(
50
                'formAuthentication',
51
                [
52
                    '_form_auth_invalid_credentials' => false,
53
                    '_form_auth_redirect_to' => $request->getUri(),
54
                    '_form_auth_login_page' => true,
55
                ]
56
            )
57
        );
58
59
        return $response;
60
    }
61
}
62