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
Push — master ( 9c7e9d...edcf5e )
by François
03:25
created

Request::getPostParameters()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 *  Copyright (C) 2016 SURFnet.
4
 *
5
 *  This program is free software: you can redistribute it and/or modify
6
 *  it under the terms of the GNU Affero General Public License as
7
 *  published by the Free Software Foundation, either version 3 of the
8
 *  License, or (at your option) any later version.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU Affero General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU Affero General Public License
16
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
namespace SURFnet\VPN\Common\Http;
20
21
use SURFnet\VPN\Common\Http\Exception\HttpException;
22
23
class Request
24
{
25
    /** @var array */
26
    private $serverData;
27
28
    /** @var array */
29
    private $getData;
30
31
    /** @var array */
32
    private $postData;
33
34
    public function __construct(array $serverData, array $getData = [], array $postData = [])
35
    {
36
        $requiredHeaders = [
37
            'REQUEST_METHOD',
38
            'SERVER_NAME',
39
            'SERVER_PORT',
40
            'REQUEST_URI',
41
            'SCRIPT_NAME',
42
        ];
43
44
        foreach ($requiredHeaders as $key) {
45
            if (!array_key_exists($key, $serverData)) {
46
                // this indicates something wrong with the interaction between
47
                // the web server and PHP, these headers MUST always be available
48
                throw new HttpException(sprintf('missing header "%s"', $key), 500);
49
            }
50
        }
51
        $this->serverData = $serverData;
52
        $this->getData = $getData;
53
        $this->postData = $postData;
54
    }
55
56
    public function getAuthority()
57
    {
58
        // scheme
59
        if (!array_key_exists('REQUEST_SCHEME', $this->serverData)) {
60
            $requestScheme = 'http';
61
        } else {
62
            $requestScheme = $this->serverData['REQUEST_SCHEME'];
63
        }
64
65
        // server_name
66
        $serverName = $this->serverData['SERVER_NAME'];
67
68
        // port
69
        $serverPort = (int) $this->serverData['SERVER_PORT'];
70
71
        $usePort = false;
72
        if ('https' === $requestScheme && 443 !== $serverPort) {
73
            $usePort = true;
74
        }
75
        if ('http' === $requestScheme && 80 !== $serverPort) {
76
            $usePort = true;
77
        }
78
79
        if ($usePort) {
80
            return sprintf('%s://%s:%d', $requestScheme, $serverName, $serverPort);
81
        }
82
83
        return sprintf('%s://%s', $requestScheme, $serverName);
84
    }
85
86
    public function getUri()
87
    {
88
        $requestUri = $this->serverData['REQUEST_URI'];
89
90
        return sprintf('%s%s', $this->getAuthority(), $requestUri);
91
    }
92
93
    public function getRoot()
94
    {
95
        $rootDir = dirname($this->serverData['SCRIPT_NAME']);
96
        if ('/' !== $rootDir) {
97
            return sprintf('%s/', $rootDir);
98
        }
99
100
        return $rootDir;
101
    }
102
103
    public function getRootUri()
104
    {
105
        return sprintf('%s%s', $this->getAuthority(), $this->getRoot());
106
    }
107
108
    public function getRequestMethod()
109
    {
110
        return $this->serverData['REQUEST_METHOD'];
111
    }
112
113
    public function getServerName()
114
    {
115
        return $this->serverData['SERVER_NAME'];
116
    }
117
118
    public function isBrowser()
119
    {
120
        if (!array_key_exists('HTTP_ACCEPT', $this->serverData)) {
121
            return false;
122
        }
123
124
        return false !== mb_strpos($this->serverData['HTTP_ACCEPT'], 'text/html');
125
    }
126
127
    public function getPathInfo()
128
    {
129
        // remove the query string
130
        $requestUri = $this->serverData['REQUEST_URI'];
131
        if (false !== $pos = mb_strpos($requestUri, '?')) {
132
            $requestUri = mb_substr($requestUri, 0, $pos);
133
        }
134
135
        // remove script_name (if it is part of request_uri
136
        if (0 === mb_strpos($requestUri, $this->serverData['SCRIPT_NAME'])) {
137
            return substr($requestUri, mb_strlen($this->serverData['SCRIPT_NAME']));
138
        }
139
140
        // remove the root
141
        if ('/' !== $this->getRoot()) {
142
            return mb_substr($requestUri, mb_strlen($this->getRoot()) - 1);
143
        }
144
145
        return $requestUri;
146
    }
147
148
    public function getQueryParameters()
149
    {
150
        return $this->getData;
151
    }
152
153
    public function getQueryParameter($key, $isRequired = true, $defaultValue = null)
154
    {
155
        return Utils::getValueFromArray($this->getData, $key, $isRequired, $defaultValue);
156
    }
157
158
    public function getPostParameters()
159
    {
160
        return $this->postData;
161
    }
162
163
    public function getPostParameter($key, $isRequired = true, $defaultValue = null)
164
    {
165
        return Utils::getValueFromArray($this->postData, $key, $isRequired, $defaultValue);
166
    }
167
168
    public function getHeader($key, $isRequired = true, $defaultValue = null)
169
    {
170
        return Utils::getValueFromArray($this->serverData, $key, $isRequired, $defaultValue);
171
    }
172
}
173