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 ( 2facf7...f9d0ca )
by
unknown
02:28
created

LPTrackerRequest::sendRequest()   C

Complexity

Conditions 8
Paths 20

Size

Total Lines 43
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 5.3846
c 0
b 0
f 0
cc 8
eloc 25
nc 20
nop 5
1
<?php
2
3
namespace LPTracker;
4
5
use anlutro\cURL\cURL;
6
use anlutro\cURL\Request;
7
use LPTracker\authentication\AccessToken;
8
use LPTracker\exceptions\LPTrackerResponseException;
9
use LPTracker\exceptions\LPTrackerServerException;
10
11
/**
12
 * Class LPTrackerRequest
13
 * @package LPTracker
14
 */
15
class LPTrackerRequest
16
{
17
18
    /**
19
     * @param                    $actionUrl
20
     * @param array              $data
21
     * @param string             $method
22
     * @param AccessToken | null $token
23
     * @param string             $baseUrl
24
     *
25
     * @return mixed
26
     * @throws LPTrackerResponseException
27
     * @throws LPTrackerServerException
28
     */
29
    public static function sendRequest(
30
        $actionUrl,
31
        array $data = [],
32
        $method = 'GET',
33
        AccessToken $token = null,
34
        $baseUrl = ''
35
    ) {
36
        if (empty($baseUrl)) {
37
            $baseUrl = LPTrackerBase::DEFAULT_ADDRESS;
38
        }
39
40
        $url = $baseUrl.$actionUrl;
41
42
        $curl = new cURL();
43
        $request = $curl->newRequest($method, $url, $data, Request::ENCODING_JSON);
44
        $request->setHeader('Content-Type', 'application/json');
45
46
        if ($token instanceof AccessToken) {
47
            $request->setHeader('token', $token->getValue());
48
        }
49
50
        $response = $request->send();
51
52
        if ($response === false) {
53
            throw new LPTrackerServerException('Can`t get response from server');
54
        }
55
56
        $body = json_decode($response->body, true);
57
58
        if ($body === false) {
59
            throw new LPTrackerServerException('Can`t decode response');
60
        }
61
62
        if ( ! empty($body['errors'])) {
63
            throw new LPTrackerResponseException($body['errors'][0]);
64
        }
65
66
        if (empty($body['status']) || $body['status'] != 'success') {
67
            throw new LPTrackerResponseException('Unknown response error');
68
        }
69
70
        return $body['result'];
71
    }
72
}