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.

Oauth::access()   B
last analyzed

Complexity

Conditions 9
Paths 14

Size

Total Lines 45

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 45
rs 7.6444
c 0
b 0
f 0
cc 9
nc 14
nop 4
1
<?php
2
3
/*
4
 * This file is part of Slackify.
5
 *
6
 * (c) Strime <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Strime\Slackify\Api;
13
14
use Strime\Slackify\Exception\RuntimeException;
15
use Strime\Slackify\Exception\InvalidArgumentException;
16
use GuzzleHttp\Exception\RequestException;
17
18
class Oauth extends AbstractApi
19
{
20
    /**
21
     * {@inheritdoc}
22
     *
23
     * @param  string $client_id
24
     * @param  string $client_secret
25
     * @param  string $code
26
     * @param  string $redirect_uri
27
     * @return string $response
28
     */
29
    public function access($client_id, $client_secret, $code, $redirect_uri = NULL) {
30
31
        // Check if the type of the variables is valid.
32
        if (!is_string($client_id)) {
33
            throw new InvalidArgumentException("The type of the client_id variable is not valid.");
34
        }
35
        if (!is_string($client_secret)) {
36
            throw new InvalidArgumentException("The type of the client_secret variable is not valid.");
37
        }
38
        if (!is_string($code)) {
39
            throw new InvalidArgumentException("The type of the code variable is not valid.");
40
        }
41
        if (($redirect_uri != NULL) && !is_string($redirect_uri)) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $redirect_uri of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
42
            throw new InvalidArgumentException("The type of the redirect_uri variable is not valid.");
43
        }
44
45
        // Set the arguments of the request
46
        $arguments = array(
47
            "client_id" => $client_id,
48
            "client_secret" => $client_secret,
49
            "code" => $code
50
        );
51
52
        if($redirect_uri != NULL) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $redirect_uri of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
53
            $arguments["redirect_uri"] = $redirect_uri;
54
        }
55
56
        $this->setUrl("oauth.access", $arguments);
57
58
        // Send the request
59
        try {
60
            $client = new \GuzzleHttp\Client();
61
            $json_response = $client->request('GET', $this->getUrl(), []);
62
            $response = json_decode( $json_response->getBody() );
63
        }
64
        catch (RequestException $e) {
65
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
66
        }
67
68
        if($response->{'ok'} === FALSE) {
69
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
70
        }
71
72
        return $json_response->getBody();
73
    }
74
}
75