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.

Users::info()   A
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 9.1288
c 0
b 0
f 0
cc 5
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 Users extends AbstractApi
19
{
20
    /**
21
     * {@inheritdoc}
22
     *
23
     * @return Users
24
     */
25
    public function deletePhoto() {
26
27
        $this->setUrl("users.deletePhoto");
28
29
        // Send the request
30
        try {
31
            $client = new \GuzzleHttp\Client();
32
            $json_response = $client->request('GET', $this->getUrl(), []);
33
            $response = json_decode( $json_response->getBody() );
34
        }
35
        catch (RequestException $e) {
36
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
37
        }
38
39
        if($response->{'ok'} === FALSE) {
40
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
41
        }
42
43
        return $this;
44
    }
45
46
47
48
49
    /**
50
     * {@inheritdoc}
51
     *
52
     * @param  string $user
53
     * @return string
54
     */
55
    public function getPresence($user) {
56
57
        // Check if the type of the variables is valid.
58
        if (!is_string($user) || ($user != NULL)) {
59
            throw new InvalidArgumentException("The type of the user variable is not valid.");
60
        }
61
62
        // Set the arguments of the request
63
        $arguments = array(
64
            "user" => $user
65
        );
66
67
        $this->setUrl("users.getPresence", $arguments);
68
69
        // Send the request
70
        try {
71
            $client = new \GuzzleHttp\Client();
72
            $json_response = $client->request('GET', $this->getUrl(), []);
73
            $response = json_decode( $json_response->getBody() );
74
        }
75
        catch (RequestException $e) {
76
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
77
        }
78
79
        if($response->{'ok'} === FALSE) {
80
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
81
        }
82
83
        return $json_response->getBody();
84
    }
85
86
87
88
89
    /**
90
     * {@inheritdoc}
91
     *
92
     * @return string
93
     */
94
    public function identity() {
95
96
        $this->setUrl("users.identity", $arguments);
0 ignored issues
show
Bug introduced by
The variable $arguments does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
97
98
        // Send the request
99
        try {
100
            $client = new \GuzzleHttp\Client();
101
            $json_response = $client->request('GET', $this->getUrl(), []);
102
            $response = json_decode( $json_response->getBody() );
103
        }
104
        catch (RequestException $e) {
105
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
106
        }
107
108
        if($response->{'ok'} === FALSE) {
109
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
110
        }
111
112
        return $json_response->getBody();
113
    }
114
115
116
117
118
119
    /**
120
     * {@inheritdoc}
121
     *
122
     * @param  string $user
123
     * @return string
124
     */
125
    public function info($user) {
126
127
        // Check if the type of the variables is valid.
128
        if (!is_bool($user) || ($user == NULL)) {
129
            throw new InvalidArgumentException("The type of the user variable is not valid.");
130
        }
131
132
        // Set the arguments of the request
133
        $arguments = array(
134
            "user" => $users
0 ignored issues
show
Bug introduced by
The variable $users does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
135
        );
136
137
        $this->setUrl("users.info", $arguments);
138
139
        // Send the request
140
        try {
141
            $client = new \GuzzleHttp\Client();
142
            $json_response = $client->request('GET', $this->getUrl(), []);
143
            $response = json_decode( $json_response->getBody() );
144
        }
145
        catch (RequestException $e) {
146
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
147
        }
148
149
        if($response->{'ok'} === FALSE) {
150
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
151
        }
152
153
        return $json_response->getBody();
154
    }
155
156
157
158
159
    /**
160
     * {@inheritdoc}
161
     *
162
     * @param  bool $presence
163
     * @return string
164
     */
165 View Code Duplication
    public function list_users($presence = 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...
166
167
        // Check if the type of the variables is valid.
168
        if (!is_string($presence) && ($presence != NULL)) {
169
            throw new InvalidArgumentException("The type of the presence variable is not valid.");
170
        }
171
172
        // Set the arguments of the request
173
        $arguments = array();
174
175
        if ($presence != NULL) {
176
            $arguments["presence"] = $presence;
177
        }
178
179
        $this->setUrl("users.list", $arguments);
180
181
        // Send the request
182
        try {
183
            $client = new \GuzzleHttp\Client();
184
            $json_response = $client->request('GET', $this->getUrl(), []);
185
            $response = json_decode( $json_response->getBody() );
186
        }
187
        catch (RequestException $e) {
188
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
189
        }
190
191
        if($response->{'ok'} === FALSE) {
192
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
193
        }
194
195
        return $json_response->getBody();
196
    }
197
198
199
200
201
    /**
202
     * {@inheritdoc}
203
     *
204
     * @return Users
205
     */
206
    public function setActive() {
207
208
        $this->setUrl("users.setActive", $arguments);
0 ignored issues
show
Bug introduced by
The variable $arguments does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
209
210
        // Send the request
211
        try {
212
            $client = new \GuzzleHttp\Client();
213
            $json_response = $client->request('GET', $this->getUrl(), []);
214
            $response = json_decode( $json_response->getBody() );
215
        }
216
        catch (RequestException $e) {
217
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
218
        }
219
220
        if($response->{'ok'} === FALSE) {
221
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
222
        }
223
224
        return $this;
225
    }
226
227
228
229
230
    /**
231
     * {@inheritdoc}
232
     *
233
     * @param  string $image
234
     * @param  integer $crop_x
235
     * @param  integer $crop_y
236
     * @param  integer $crop_w
237
     * @return Users
238
     */
239
    public function setPhoto($image, $crop_x = NULL, $crop_y = NULL, $crop_w = NULL) {
240
241
        // Check if the type of the variables is valid.
242
        if (!is_string($image) || ($image == NULL)) {
243
            throw new InvalidArgumentException("The type of the image variable is not valid.");
244
        }
245
        if (!is_string($crop_x) && ($crop_x != NULL)) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $crop_x of type integer|null against null; this is ambiguous if the integer can be zero. Consider using a strict comparison !== instead.
Loading history...
246
            throw new InvalidArgumentException("The type of the crop_x variable is not valid.");
247
        }
248
        if (!is_string($crop_y) && ($crop_y != NULL)) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $crop_y of type integer|null against null; this is ambiguous if the integer can be zero. Consider using a strict comparison !== instead.
Loading history...
249
            throw new InvalidArgumentException("The type of the crop_y variable is not valid.");
250
        }
251
        if (!is_string($crop_w) && ($crop_w != NULL)) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $crop_w of type integer|null against null; this is ambiguous if the integer can be zero. Consider using a strict comparison !== instead.
Loading history...
252
            throw new InvalidArgumentException("The type of the crop_w variable is not valid.");
253
        }
254
255
        // Set the arguments of the request
256
        $arguments = array(
257
            array(
258
                "name" => "file",
259
                "contents" => fopen($video, "r"),
0 ignored issues
show
Bug introduced by
The variable $video does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
260
                "filename" => $image
261
            )
262
        );
263
264
        if ($crop_x != NULL) {
265
            $arguments[] = array("name" => "crop_x", "content" => $crop_x);
266
        }
267
        if ($crop_y != NULL) {
268
            $arguments[] = array("name" => "crop_y", "content" => $crop_y);
269
        }
270
        if ($crop_w != NULL) {
271
            $arguments[] = array("name" => "crop_w", "content" => $crop_w);
272
        }
273
274
        $this->setUrl("users.setPhoto");
275
276
        // Send the request
277
        try {
278
            $client = new \GuzzleHttp\Client();
279
            $json_response = $client->request('POST', $this->getUrl(), [
280
                'http_errors' => false,
281
                'multipart' => $arguments
282
            ]);
283
            $response = json_decode( $json_response->getBody() );
284
        }
285
        catch (RequestException $e) {
286
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
287
        }
288
289
        if($response->{'ok'} === FALSE) {
290
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
291
        }
292
293
        return $this;
294
    }
295
296
297
298
299
    /**
300
     * {@inheritdoc}
301
     *
302
     * @param  string $presence
303
     * @return Users
304
     */
305
    public function setPresence($presence) {
306
307
        // Check if the type of the variables is valid.
308
        if (!is_string($presence) || ($presence == NULL)) {
309
            throw new InvalidArgumentException("The type of the presence variable is not valid.");
310
        }
311
312
        // Set the arguments of the request
313
        $arguments = array(
314
            "presence" => $presence
315
        );
316
317
        $this->setUrl("users.setPresence", $arguments);
318
319
        // Send the request
320
        try {
321
            $client = new \GuzzleHttp\Client();
322
            $json_response = $client->request('GET', $this->getUrl(), []);
323
            $response = json_decode( $json_response->getBody() );
324
        }
325
        catch (RequestException $e) {
326
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
327
        }
328
329
        if($response->{'ok'} === FALSE) {
330
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
331
        }
332
333
        return $this;
334
    }
335
}
336