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 ( 62c2b4...64206a )
by François
28:20
created

CurlHttpClient   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 1
dl 0
loc 38
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B post() 0 35 4
1
<?php
2
/**
3
 * Copyright 2016 François Kooman <[email protected]>.
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
namespace fkooman\OAuth\Client;
18
19
use RuntimeException;
20
21
/**
22
 * Retrieve an access token using the cURL HTTP client.
23
 */
24
class CurlHttpClient implements HttpClientInterface
25
{
26
    public function post(Provider $provider, array $postData)
27
    {
28
        $ch = curl_init($provider->getTokenEndpoint());
29
30
        $optionsSet = curl_setopt_array(
31
            $ch,
32
            [
33
                CURLOPT_PROTOCOLS => CURLPROTO_HTTPS,
34
                CURLOPT_SSL_VERIFYPEER => true,
35
                CURLOPT_SSL_VERIFYHOST => 2,
36
                CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
37
                CURLOPT_USERPWD => sprintf('%s:%s', $provider->getId(), $provider->getSecret()),
38
                CURLOPT_POST => true,
39
                CURLOPT_POSTFIELDS => $postData,
40
                CURLOPT_RETURNTRANSFER => true,
41
            ]
42
        );
43
44
        if (!$optionsSet) {
45
            throw new RuntimeException('unable to set all cURL options');
46
        }
47
48
        $jsonResponse = curl_exec($ch);
49
        curl_close($ch);
50
        if (false === $jsonResponse) {
51
            return [];
52
        }
53
54
        $response = json_decode($jsonResponse, true);
55
        if (JSON_ERROR_NONE !== json_last_error()) {
56
            throw new OAuthException('malformed response from OAuth server token endpoint');
57
        }
58
59
        return $response;
60
    }
61
}
62