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   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 74
Duplicated Lines 50 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 5
dl 37
loc 74
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B revoke() 37 37 7
A test() 0 20 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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