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 ( 5109b1...d4f75a )
by Cees-Jan
02:08
created

psr7_server_request_encode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 16
nc 2
nop 1
dl 0
loc 20
ccs 16
cts 16
cp 1
crap 2
rs 9.4285
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 RingCentral\Psr7\Request;
11
use RingCentral\Psr7\Response;
12
13
function psr7_response_json_encode(ResponseInterface $response): string
14
{
15 1
    return json_try_encode(psr7_response_encode($response));
16
}
17
18
function psr7_response_encode(ResponseInterface $response): array
19
{
20 2
    $json = [];
21 2
    $json['protocol_version'] = $response->getProtocolVersion();
22 2
    $json['status_code'] = $response->getStatusCode();
23 2
    $json['reason_phrase'] = $response->getReasonPhrase();
24 2
    $json['headers'] = $response->getHeaders();
25 2
    $json['body'] = base64_encode($response->getBody()->getContents());
26
27 2
    return $json;
28
}
29
30
/**
31
 * @throws NotAnEncodedResponseException
32
 */
33
function psr7_response_json_decode(string $json): ResponseInterface
34
{
35 1
    return psr7_response_decode(json_try_decode($json, true));
36
}
37
38
/**
39
 * @throws NotAnEncodedResponseException
40
 */
41
function psr7_response_decode(array $json): ResponseInterface
42
{
43
    $properties = [
44 2
        'protocol_version',
45
        'status_code',
46
        'reason_phrase',
47
        'headers',
48
        'body',
49
    ];
50
51 2
    foreach ($properties as $property) {
52 2
        if (!isset($json[$property])) {
53 2
            throw new NotAnEncodedResponseException($json);
54
        }
55
    }
56
57 2
    return new Response(
58 2
        $json['status_code'],
59 2
        $json['headers'],
60 2
        base64_decode($json['body'], true),
61 2
        $json['protocol_version'],
62 2
        $json['reason_phrase']
63
    );
64
}
65
66
function psr7_request_json_encode(RequestInterface $request): string
67
{
68 1
    return json_try_encode(psr7_request_encode($request));
69
}
70
71
function psr7_request_encode(RequestInterface $request): array
72
{
73 2
    $json = [];
74 2
    $json['protocol_version'] = $request->getProtocolVersion();
75 2
    $json['method'] = $request->getMethod();
76 2
    $json['uri'] = (string)$request->getUri();
77 2
    $json['headers'] = $request->getHeaders();
78 2
    $json['body'] = base64_encode($request->getBody()->getContents());
79
80 2
    return $json;
81
}
82
83
/**
84
 * @throws NotAnEncodedRequestException
85
 */
86
function psr7_request_json_decode(string $json): RequestInterface
87
{
88 1
    return psr7_request_decode(json_try_decode($json, true));
89
}
90
91
/**
92
 * @throws NotAnEncodedRequestException
93
 */
94
function psr7_request_decode(array $json): RequestInterface
95
{
96
    $properties = [
97 2
        'protocol_version',
98
        'method',
99
        'uri',
100
        'headers',
101
        'body',
102
    ];
103
104 2
    foreach ($properties as $property) {
105 2
        if (!isset($json[$property])) {
106 2
            throw new NotAnEncodedRequestException($json);
107
        }
108
    }
109
110 2
    return new Request(
111 2
        $json['method'],
112 2
        $json['uri'],
113 2
        $json['headers'],
114 2
        base64_decode($json['body'], true),
115 2
        $json['protocol_version']
116
    );
117
}
118
119
function psr7_uploaded_file_json_encode(UploadedFileInterface $uploadedFile): string
120
{
121 1
    return json_try_encode(psr7_uploaded_file_encode($uploadedFile));
122
}
123
124
function psr7_uploaded_file_encode(UploadedFileInterface $uploadedFile): array
125
{
126 4
    $json = [];
127 4
    $json['filename'] = $uploadedFile->getClientFilename();
128 4
    $json['media_type'] = $uploadedFile->getClientMediaType();
129 4
    $json['error'] = $uploadedFile->getError();
130 4
    $json['size'] = $uploadedFile->getSize();
131 4
    $json['stream'] = $uploadedFile->getStream()->getContents();
132
133 4
    return $json;
134
}
135
136
function psr7_server_request_json_encode(ServerRequestInterface $request): string
137
{
138 1
    return json_try_encode(psr7_server_request_encode($request));
139
}
140
141
function psr7_server_request_encode(ServerRequestInterface $request): array
142
{
143 2
    $json = [];
144 2
    $json['protocol_version'] = $request->getProtocolVersion();
145 2
    $json['method'] = $request->getMethod();
146 2
    $json['uri'] = (string)$request->getUri();
147 2
    $json['query_params'] = $request->getQueryParams();
148 2
    $json['cookie_params'] = $request->getCookieParams();
149 2
    $json['server_params'] = $request->getServerParams();
150 2
    $json['headers'] = $request->getHeaders();
151 2
    $json['attributes'] = $request->getAttributes();
152 2
    $json['body'] = base64_encode($request->getBody()->getContents());
153 2
    $json['parsed_body'] = $request->getParsedBody();
154 2
    $json['files'] = $request->getUploadedFiles();
155 2
    $json['files'] = Hash::flatten($json['files']);
156 2
    foreach ($json['files'] as $key => $file) {
157 2
        $json['files'][$key] = psr7_uploaded_file_encode($file);
158
    }
159
160 2
    return $json;
161
}
162