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.
Passed
Push — master ( c68e1e...f0b4a1 )
by Cees-Jan
01:48
created

psr7_server_request_json_decode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace WyriHaximus;
4
5
use Cake\Utility\Hash;
6
use Psr\Http\Message\RequestInterface;
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
use Psr\Http\Message\UploadedFileInterface;
10
use React\Http\Io\UploadedFile;
11
use RingCentral\Psr7\Request;
12
use RingCentral\Psr7\Response;
13
use RingCentral\Psr7\ServerRequest;
14
use function RingCentral\Psr7\stream_for;
15
16
function psr7_response_json_encode(ResponseInterface $response): string
17
{
18 1
    return json_try_encode(psr7_response_encode($response));
19
}
20
21
function psr7_response_encode(ResponseInterface $response): array
22
{
23 2
    $json = [];
24 2
    $json['protocol_version'] = $response->getProtocolVersion();
25 2
    $json['status_code'] = $response->getStatusCode();
26 2
    $json['reason_phrase'] = $response->getReasonPhrase();
27 2
    $json['headers'] = $response->getHeaders();
28 2
    $json['body'] = base64_encode($response->getBody()->getContents());
29
30 2
    return $json;
31
}
32
33
/**
34
 * @throws NotAnEncodedResponseException
35
 */
36
function psr7_response_json_decode(string $json): ResponseInterface
37
{
38 1
    return psr7_response_decode(json_try_decode($json, true));
39
}
40
41
/**
42
 * @throws NotAnEncodedResponseException
43
 */
44
function psr7_response_decode(array $json): ResponseInterface
45
{
46
    $properties = [
47 2
        'protocol_version',
48
        'status_code',
49
        'reason_phrase',
50
        'headers',
51
        'body',
52
    ];
53
54 2
    foreach ($properties as $property) {
55 2
        if (!isset($json[$property])) {
56 2
            throw new NotAnEncodedResponseException($json);
57
        }
58
    }
59
60 2
    return new Response(
61 2
        $json['status_code'],
62 2
        $json['headers'],
63 2
        base64_decode($json['body'], true),
64 2
        $json['protocol_version'],
65 2
        $json['reason_phrase']
66
    );
67
}
68
69
function psr7_request_json_encode(RequestInterface $request): string
70
{
71 1
    return json_try_encode(psr7_request_encode($request));
72
}
73
74
function psr7_request_encode(RequestInterface $request): array
75
{
76 2
    $json = [];
77 2
    $json['protocol_version'] = $request->getProtocolVersion();
78 2
    $json['method'] = $request->getMethod();
79 2
    $json['uri'] = (string)$request->getUri();
80 2
    $json['headers'] = $request->getHeaders();
81 2
    $json['body'] = base64_encode($request->getBody()->getContents());
82
83 2
    return $json;
84
}
85
86
/**
87
 * @throws NotAnEncodedRequestException
88
 */
89
function psr7_request_json_decode(string $json): RequestInterface
90
{
91 1
    return psr7_request_decode(json_try_decode($json, true));
92
}
93
94
/**
95
 * @throws NotAnEncodedRequestException
96
 */
97
function psr7_request_decode(array $json): RequestInterface
98
{
99
    $properties = [
100 2
        'protocol_version',
101
        'method',
102
        'uri',
103
        'headers',
104
        'body',
105
    ];
106
107 2
    foreach ($properties as $property) {
108 2
        if (!isset($json[$property])) {
109 2
            throw new NotAnEncodedRequestException($json);
110
        }
111
    }
112
113 2
    return new Request(
114 2
        $json['method'],
115 2
        $json['uri'],
116 2
        $json['headers'],
117 2
        base64_decode($json['body'], true),
118 2
        $json['protocol_version']
119
    );
120
}
121
122
function psr7_uploaded_file_json_encode(UploadedFileInterface $uploadedFile): string
123
{
124 1
    return json_try_encode(psr7_uploaded_file_encode($uploadedFile));
125
}
126
127
function psr7_uploaded_file_encode(UploadedFileInterface $uploadedFile): array
128
{
129 4
    $json = [];
130 4
    $json['filename'] = $uploadedFile->getClientFilename();
131 4
    $json['media_type'] = $uploadedFile->getClientMediaType();
132 4
    $json['error'] = $uploadedFile->getError();
133 4
    $json['size'] = $uploadedFile->getSize();
134 4
    $json['stream'] = base64_encode($uploadedFile->getStream()->getContents());
135
136 4
    return $json;
137
}
138
139
/**
140
 * @throws NotAnEncodedUploadedFileException
141
 */
142
function psr7_uploaded_file_json_decode(string $json): UploadedFileInterface
143
{
144 1
    return psr7_uploaded_file_decode(json_try_decode($json, true));
145
}
146
147
/**
148
 * @throws NotAnEncodedUploadedFileException
149
 */
150
function psr7_uploaded_file_decode(array $json): UploadedFileInterface
151
{
152
    $properties = [
153 4
        'stream',
154
        'size',
155
        'error',
156
        'filename',
157
        'media_type',
158
    ];
159
160 4
    foreach ($properties as $property) {
161 4
        if (!isset($json[$property])) {
162 4
            throw new NotAnEncodedUploadedFileException($json);
163
        }
164
    }
165
166 4
    return new UploadedFile(
167 4
        stream_for(base64_decode($json['stream'], true)),
168 4
        $json['size'],
169 4
        $json['error'],
170 4
        $json['filename'],
171 4
        $json['media_type']
172
    );
173
}
174
175
function psr7_server_request_json_encode(ServerRequestInterface $request): string
176
{
177 1
    return json_try_encode(psr7_server_request_encode($request));
178
}
179
180
function psr7_server_request_encode(ServerRequestInterface $request): array
181
{
182 2
    $json = [];
183 2
    $json['protocol_version'] = $request->getProtocolVersion();
184 2
    $json['method'] = $request->getMethod();
185 2
    $json['uri'] = (string)$request->getUri();
186 2
    $json['query_params'] = $request->getQueryParams();
187 2
    $json['cookie_params'] = $request->getCookieParams();
188 2
    $json['server_params'] = $request->getServerParams();
189 2
    $json['headers'] = $request->getHeaders();
190 2
    $json['attributes'] = $request->getAttributes();
191 2
    $json['body'] = base64_encode($request->getBody()->getContents());
192 2
    $json['parsed_body'] = $request->getParsedBody();
193 2
    $json['files'] = $request->getUploadedFiles();
194 2
    $json['files'] = Hash::flatten($json['files']);
195 2
    foreach ($json['files'] as $key => $file) {
196 2
        $json['files'][$key] = psr7_uploaded_file_encode($file);
197
    }
198
199 2
    return $json;
200
}
201
202
/**
203
 * @throws NotAnEncodedServerRequestException
204
 * @throws NotAnEncodedUploadedFileException
205
 */
206
function psr7_server_request_json_decode(string $json): ServerRequestInterface
207
{
208 1
    return psr7_server_request_decode(json_try_decode($json, true));
209
}
210
211
/**
212
 * @throws NotAnEncodedServerRequestException
213
 * @throws NotAnEncodedUploadedFileException
214
 */
215
function psr7_server_request_decode(array $json): ServerRequestInterface
216
{
217
    $properties = [
218 2
        'protocol_version',
219
        'method',
220
        'uri',
221
        'query_params',
222
        'cookie_params',
223
        'server_params',
224
        'headers',
225
        'attributes',
226
        'body',
227
        'parsed_body',
228
    ];
229
230 2
    foreach ($properties as $property) {
231 2
        if (!isset($json[$property])) {
232 2
            throw new NotAnEncodedServerRequestException($json);
233
        }
234
    }
235
236 2
    $request = (new ServerRequest(
237 2
        $json['method'],
238 2
        $json['uri'],
239 2
        $json['headers'],
240 2
        base64_decode($json['body'], true),
241 2
        $json['protocol_version'],
242 2
        $json['server_params']
243
    ))->
244 2
        withParsedBody($json['parsed_body'])->
245 2
        withUploadedFiles($json['files'])->
246 2
        withQueryParams($json['query_params'])->
247 2
        withCookieParams($json['cookie_params'])
248
    ;
249
250 2
    foreach ($json['attributes'] as $key => $value) {
251 2
        $request = $request->withAttribute($key, $value);
252
    }
253
254 2
    if (count($json['files']) > 0) {
255 2
        foreach ($json['files'] as $key => $file) {
256 2
            $json['files'][$key] = psr7_uploaded_file_decode($file);
257
        }
258 2
        $json['files'] = Hash::expand($json['files']);
259 2
        $request = $request->withUploadedFiles($json['files']);
260
    }
261
262 2
    return $request;
263
}
264