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 ( 30655b...a8e9a1 )
by Romain
04:44
created

Pin::list()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 30
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 30
rs 8.5806
cc 4
eloc 15
nc 6
nop 1
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 Pin extends AbstractApi
19
{
20
    /**
21
     * {@inheritdoc}
22
     *
23
     * @param  string $channel
24
     * @param  string $file
25
     * @param  string $file_comment
26
     * @param  float $timestamp
27
     * @return Pin
28
     */
29 View Code Duplication
    public function add($channel, $file = NULL, $file_comment = NULL, $timestamp = 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...
30
31
        // Check if the type of the variables is valid.
32
        if (!is_string($channel)) {
33
            throw new InvalidArgumentException("The type of the channel variable is not valid.");
34
        }
35
        if (($file != NULL) && !is_string($file)) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $file of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
36
            throw new InvalidArgumentException("The type of the file variable is not valid.");
37
        }
38
        if (($file_comment != NULL) && !is_string($file_comment)) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $file_comment of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
39
            throw new InvalidArgumentException("The type of the file_comment variable is not valid.");
40
        }
41
        if (($timestamp != NULL) && !is_float($timestamp)) {
42
            throw new InvalidArgumentException("The type of the timestamp variable is not valid.");
43
        }
44
45
        // Set the arguments of the request
46
        $arguments = array(
47
            "channel" => $channel
48
        );
49
50
        if ($file != NULL) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $file of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
51
            $arguments["file"] = $file;
52
        }
53
        if ($file_comment != NULL) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $file_comment of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
54
            $arguments["file_comment"] = $file_comment;
55
        }
56
        if ($timestamp != NULL) {
57
            $arguments["timestamp"] = (string)$timestamp;
58
        }
59
60
        $this->setUrl("pin.add", $arguments);
61
62
        // Send the request
63
        try {
64
            $client = new \GuzzleHttp\Client();
65
            $json_response = $client->request('GET', $this->getUrl(), []);
66
            $response = json_decode( $json_response->getBody() );
67
        }
68
        catch (RequestException $e) {
69
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
70
        }
71
72
        if($response->{'ok'} === FALSE) {
73
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
74
        }
75
76
        return $this;
77
    }
78
79
80
81
82
    /**
83
     * {@inheritdoc}
84
     *
85
     * @param  string $channel
86
     * @return string
87
     */
88
    public function list_pin($channel) {
89
90
        // Check if the type of the variables is valid.
91
        if (!is_string($channel)) {
92
            throw new InvalidArgumentException("The type of the channel variable is not valid.");
93
        }
94
95
        // Set the arguments of the request
96
        $arguments = array(
0 ignored issues
show
Unused Code introduced by
$arguments is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
97
            "channel" => $channel
98
        );
99
100
        $this->setUrl("pin.list");
101
102
        // Send the request
103
        try {
104
            $client = new \GuzzleHttp\Client();
105
            $json_response = $client->request('GET', $this->getUrl(), []);
106
            $response = json_decode( $json_response->getBody() );
107
        }
108
        catch (RequestException $e) {
109
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
110
        }
111
112
        if($response->{'ok'} === FALSE) {
113
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
114
        }
115
116
        return $json_response->getBody();
117
    }
118
119
120
121
122
    /**
123
     * {@inheritdoc}
124
     *
125
     * @param  string $channel
126
     * @param  string $file
127
     * @param  string $file_comment
128
     * @param  float $timestamp
129
     * @return Pin
130
     */
131 View Code Duplication
    public function remove($channel, $file = NULL, $file_comment = NULL, $timestamp = 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...
132
133
        // Check if the type of the variables is valid.
134
        if (!is_string($channel)) {
135
            throw new InvalidArgumentException("The type of the channel variable is not valid.");
136
        }
137
        if (($file != NULL) && !is_string($file)) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $file of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
138
            throw new InvalidArgumentException("The type of the file variable is not valid.");
139
        }
140
        if (($file_comment != NULL) && !is_string($file_comment)) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $file_comment of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
141
            throw new InvalidArgumentException("The type of the file_comment variable is not valid.");
142
        }
143
        if (($timestamp != NULL) && !is_float($timestamp)) {
144
            throw new InvalidArgumentException("The type of the timestamp variable is not valid.");
145
        }
146
147
        // Set the arguments of the request
148
        $arguments = array(
149
            "channel" => $channel
150
        );
151
152
        if ($file != NULL) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $file of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
153
            $arguments["file"] = $file;
154
        }
155
        if ($file_comment != NULL) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $file_comment of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
156
            $arguments["file_comment"] = $file_comment;
157
        }
158
        if ($timestamp != NULL) {
159
            $arguments["timestamp"] = (string)$timestamp;
160
        }
161
162
        $this->setUrl("pin.remove", $arguments);
163
164
        // Send the request
165
        try {
166
            $client = new \GuzzleHttp\Client();
167
            $json_response = $client->request('GET', $this->getUrl(), []);
168
            $response = json_decode( $json_response->getBody() );
169
        }
170
        catch (RequestException $e) {
171
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
172
        }
173
174
        if($response->{'ok'} === FALSE) {
175
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
176
        }
177
178
        return $this;
179
    }
180
}
181