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 ( 994736...366350 )
by François
08:25 queued 05:01
created

Request::getAuthority()   C

Complexity

Conditions 7
Paths 16

Size

Total Lines 29
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 15
nc 16
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 fkooman\RemoteStorage\Http;
20
21
use fkooman\RemoteStorage\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
    /** @var string|null */
35
    private $rawData;
36
37
    public function __construct(array $serverData, array $getData = [], array $postData = [], $rawData = null)
38
    {
39
        $requiredHeaders = [
40
            'REQUEST_METHOD',
41
            'SERVER_NAME',
42
            'SERVER_PORT',
43
            'REQUEST_URI',
44
            'SCRIPT_NAME',
45
        ];
46
47
        foreach ($requiredHeaders as $key) {
48
            if (!array_key_exists($key, $serverData)) {
49
                // this indicates something wrong with the interaction between
50
                // the web server and PHP, these headers MUST always be available
51
                throw new HttpException(sprintf('missing header "%s"', $key), 500);
52
            }
53
        }
54
        $this->serverData = $serverData;
55
        $this->getData = $getData;
56
        $this->postData = $postData;
57
        $this->rawData = $rawData;
58
    }
59
60
    public function getAuthority()
61
    {
62
        // scheme
63
        if (!array_key_exists('REQUEST_SCHEME', $this->serverData)) {
64
            $requestScheme = 'http';
65
        } else {
66
            $requestScheme = $this->serverData['REQUEST_SCHEME'];
67
        }
68
69
        // server_name
70
        $serverName = $this->serverData['SERVER_NAME'];
71
72
        // port
73
        $serverPort = (int) $this->serverData['SERVER_PORT'];
74
75
        $usePort = false;
76
        if ('https' === $requestScheme && 443 !== $serverPort) {
77
            $usePort = true;
78
        }
79
        if ('http' === $requestScheme && 80 !== $serverPort) {
80
            $usePort = true;
81
        }
82
83
        if ($usePort) {
84
            return sprintf('%s://%s:%d', $requestScheme, $serverName, $serverPort);
85
        }
86
87
        return sprintf('%s://%s', $requestScheme, $serverName);
88
    }
89
90
    public function getUri()
91
    {
92
        $requestUri = $this->serverData['REQUEST_URI'];
93
94
        return sprintf('%s%s', $this->getAuthority(), $requestUri);
95
    }
96
97
    public function getRoot()
98
    {
99
        $rootDir = dirname($this->serverData['SCRIPT_NAME']);
100
        if ('/' !== $rootDir) {
101
            return sprintf('%s/', $rootDir);
102
        }
103
104
        return $rootDir;
105
    }
106
107
    public function getRootUri()
108
    {
109
        return sprintf('%s%s', $this->getAuthority(), $this->getRoot());
110
    }
111
112
    public function getRequestMethod()
113
    {
114
        return $this->serverData['REQUEST_METHOD'];
115
    }
116
117
    public function getServerName()
118
    {
119
        return $this->serverData['SERVER_NAME'];
120
    }
121
122
    public function isBrowser()
123
    {
124
        if (!array_key_exists('HTTP_ACCEPT', $this->serverData)) {
125
            return false;
126
        }
127
128
        return false !== mb_strpos($this->serverData['HTTP_ACCEPT'], 'text/html');
129
    }
130
131
    public function getPathInfo()
132
    {
133
        // remove the query string
134
        $requestUri = $this->serverData['REQUEST_URI'];
135
        if (false !== $pos = mb_strpos($requestUri, '?')) {
136
            $requestUri = mb_substr($requestUri, 0, $pos);
137
        }
138
139
        // remove script_name (if it is part of request_uri
140
        if (0 === mb_strpos($requestUri, $this->serverData['SCRIPT_NAME'])) {
141
            return substr($requestUri, mb_strlen($this->serverData['SCRIPT_NAME']));
142
        }
143
144
        // remove the root
145
        if ('/' !== $this->getRoot()) {
146
            return mb_substr($requestUri, mb_strlen($this->getRoot()) - 1);
147
        }
148
149
        return $requestUri;
150
    }
151
152
    public function getQueryParameter($key, $isRequired = true, $defaultValue = null)
153
    {
154
        return Utils::getValueFromArray($this->getData, $key, $isRequired, $defaultValue);
155
    }
156
157
    public function getPostParameter($key, $isRequired = true, $defaultValue = null)
158
    {
159
        return Utils::getValueFromArray($this->postData, $key, $isRequired, $defaultValue);
160
    }
161
162
    public function getHeader($key, $isRequired = true, $defaultValue = null)
163
    {
164
        return Utils::getValueFromArray($this->serverData, $key, $isRequired, $defaultValue);
165
    }
166
167
    public function getBody()
168
    {
169
        return $this->rawData;
170
    }
171
}
172