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.

Auth::test()   A
last analyzed

Complexity

Conditions 3
Paths 5

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
cc 3
nc 5
nop 0
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 Auth extends AbstractApi
19
{
20
    /**
21
     * {@inheritdoc}
22
     *
23
     * @param  string $token
24
     * @param  boolean $test
25
     * @return Auth
26
     */
27 View Code Duplication
    public function revoke($token = NULL, $test = FALSE) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
29
        // Check if the type of the variables is valid.
30
        if (($token != NULL) && !is_string($token)) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $token of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
31
            throw new InvalidArgumentException("The type of the token variable is not valid.");
32
        }
33
        if (!is_bool($test)) {
34
            throw new InvalidArgumentException("The type of the test variable is not valid.");
35
        }
36
37
        // Set the arguments of the request
38
        $arguments = array(
39
            "test" => $test
40
        );
41
42
        if($token != NULL) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $token of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
43
            $arguments["token"] = $token;
44
        }
45
46
        $this->setUrl("auth.revoke", $arguments);
47
48
        // Send the request
49
        try {
50
            $client = new \GuzzleHttp\Client();
51
            $json_response = $client->request('GET', $this->getUrl(), []);
52
            $response = json_decode( $json_response->getBody() );
53
        }
54
        catch (RequestException $e) {
55
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
56
        }
57
58
        if($response->{'ok'} === FALSE) {
59
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
60
        }
61
62
        return $this;
63
    }
64
65
66
    /**
67
     * {@inheritdoc}
68
     *
69
     * @return Auth
70
     */
71
    public function test() {
72
73
        $this->setUrl("auth.test");
74
75
        // Send the request
76
        try {
77
            $client = new \GuzzleHttp\Client();
78
            $json_response = $client->request('GET', $this->getUrl(), []);
79
            $response = json_decode( $json_response->getBody() );
80
        }
81
        catch (RequestException $e) {
82
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
83
        }
84
85
        if($response->{'ok'} === FALSE) {
86
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
87
        }
88
89
        return $json_response->getBody();
90
    }
91
}
92