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 ( a0313d...5109b1 )
by Cees-Jan
03:24
created

psr7_request_decode()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 15
nc 3
nop 1
dl 0
loc 22
ccs 10
cts 10
cp 1
crap 3
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
namespace WyriHaximus;
4
5
use Psr\Http\Message\RequestInterface;
6
use Psr\Http\Message\ResponseInterface;
7
use RingCentral\Psr7\Request;
8
use RingCentral\Psr7\Response;
9
10
function psr7_response_json_encode(ResponseInterface $response): string
11
{
12 1
    return json_try_encode(psr7_response_encode($response));
13
}
14
15
function psr7_response_encode(ResponseInterface $response): array
16
{
17 2
    $json = [];
18 2
    $json['protocol_version'] = $response->getProtocolVersion();
19 2
    $json['status_code'] = $response->getStatusCode();
20 2
    $json['reason_phrase'] = $response->getReasonPhrase();
21 2
    $json['headers'] = $response->getHeaders();
22 2
    $json['body'] = base64_encode($response->getBody()->getContents());
23
24 2
    return $json;
25
}
26
27
/**
28
 * @throws NotAnEncodedResponseException
29
 */
30
function psr7_response_json_decode(string $json): ResponseInterface
31
{
32 1
    return psr7_response_decode(json_try_decode($json, true));
33
}
34
35
/**
36
 * @throws NotAnEncodedResponseException
37
 */
38
function psr7_response_decode(array $json): ResponseInterface
39
{
40
    $properties = [
41 2
        'protocol_version',
42
        'status_code',
43
        'reason_phrase',
44
        'headers',
45
        'body',
46
    ];
47
48 2
    foreach ($properties as $property) {
49 2
        if (!isset($json[$property])) {
50 2
            throw new NotAnEncodedResponseException($json);
51
        }
52
    }
53
54 2
    return new Response(
55 2
        $json['status_code'],
56 2
        $json['headers'],
57 2
        base64_decode($json['body'], true),
58 2
        $json['protocol_version'],
59 2
        $json['reason_phrase']
60
    );
61
}
62
63
function psr7_request_json_encode(RequestInterface $request): string
64
{
65 1
    return json_try_encode(psr7_request_encode($request));
66
}
67
68
function psr7_request_encode(RequestInterface $request): array
69
{
70 2
    $json = [];
71 2
    $json['protocol_version'] = $request->getProtocolVersion();
72 2
    $json['method'] = $request->getMethod();
73 2
    $json['uri'] = (string)$request->getUri();
74 2
    $json['headers'] = $request->getHeaders();
75 2
    $json['body'] = base64_encode($request->getBody()->getContents());
76
77 2
    return $json;
78
}
79
80
/**
81
 * @throws NotAnEncodedRequestException
82
 */
83
function psr7_request_json_decode(string $json): RequestInterface
84
{
85 1
    return psr7_request_decode(json_try_decode($json, true));
86
}
87
88
/**
89
 * @throws NotAnEncodedRequestException
90
 */
91
function psr7_request_decode(array $json): RequestInterface
92
{
93
    $properties = [
94 2
        'protocol_version',
95
        'method',
96
        'uri',
97
        'headers',
98
        'body',
99
    ];
100
101 2
    foreach ($properties as $property) {
102 2
        if (!isset($json[$property])) {
103 2
            throw new NotAnEncodedRequestException($json);
104
        }
105
    }
106
107 2
    return new Request(
108 2
        $json['method'],
109 2
        $json['uri'],
110 2
        $json['headers'],
111 2
        base64_decode($json['body'], true),
112 2
        $json['protocol_version']
113
    );
114
}
115