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 ( 4cd0f0...30655b )
by Romain
04:55
created

Api   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 48
Duplicated Lines 79.17 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
D test() 38 38 9

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 Api extends AbstractApi
19
{
20
    /**
21
     * {@inheritdoc}
22
     *
23
     * @param  string $error
24
     * @param  string $foo
25
     * @return Api
26
     */
27 View Code Duplication
    public function test($error = NULL, $foo = NULL) {
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 (($error != NULL) && !is_string($error)) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $error 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 error variable is not valid.");
32
        }
33
        if (($foo != NULL) && !is_string($foo)) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $foo of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
34
            throw new InvalidArgumentException("The type of the foo variable is not valid.");
35
        }
36
37
        // Set the arguments of the request
38
        $arguments = array();
39
40
        if($error != NULL) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $error of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
41
            $arguments["error"] = $error;
42
        }
43
        if($foo != NULL) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $foo of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
44
            $arguments["foo"] = $foo;
45
        }
46
47
        $this->setUrl("api.test", $arguments);
48
49
        // Send the request
50
        try {
51
            $client = new \GuzzleHttp\Client();
52
            $json_response = $client->request('GET', $this->getUrl(), []);
53
            $response = json_decode( $json_response->getBody() );
54
        }
55
        catch (RequestException $e) {
56
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
57
        }
58
59
        if($response->{'ok'} === FALSE) {
60
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
61
        }
62
63
        return $this;
64
    }
65
}
66