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.

UserGroups::update()   F
last analyzed

Complexity

Conditions 20
Paths 166

Size

Total Lines 61

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 61
rs 3.6166
c 0
b 0
f 0
cc 20
nc 166
nop 6

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 UserGroups extends AbstractApi
19
{
20
    /**
21
     * {@inheritdoc}
22
     *
23
     * @param  string $name
24
     * @param  string $handle
25
     * @param  string $description
26
     * @param  string $channels
27
     * @param  bool $include_count
28
     * @return string
29
     */
30
    public function create($name, $handle = NULL, $description = NULL, $channels = NULL, $include_count = NULL) {
31
32
        // Check if the type of the variables is valid.
33
        if (!is_string($name) || ($name == NULL)) {
34
            throw new InvalidArgumentException("The type of the name variable is not valid.");
35
        }
36
        if (!is_string($handle) &&  ($name != NULL)) {
37
            throw new InvalidArgumentException("The type of the handle variable is not valid.");
38
        }
39
        if (!is_string($description) &&  ($description != NULL)) {
40
            throw new InvalidArgumentException("The type of the description variable is not valid.");
41
        }
42
        if (!is_string($channels) &&  ($channels != NULL)) {
43
            throw new InvalidArgumentException("The type of the channels variable is not valid.");
44
        }
45
        if (!is_bool($include_count) &&  ($include_count != NULL)) {
46
            throw new InvalidArgumentException("The type of the channels variable is not valid.");
47
        }
48
49
        // Set the arguments of the request
50
        $arguments = array(
51
            "name" => $name
52
        );
53
54
        if ($handle != NULL) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $handle of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
55
            $arguments["handle"] = $handle;
56
        }
57
        if ($description != NULL) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $description of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
58
            $arguments["description"] = $description;
59
        }
60
        if ($channels != NULL) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $channels of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
61
            $arguments["channels"] = $channels;
62
        }
63
        if ($include_count != NULL) {
64
            $arguments["include_count"] = $include_count;
65
        }
66
67
        $this->setUrl("usergroups.create", $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
     * @param  string $usergroup
93
     * @param  bool $include_count
94
     * @return string
95
     */
96 View Code Duplication
    public function disable($usergroup, $include_count = 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...
97
98
        // Check if the type of the variables is valid.
99
        if (!is_string($usergroup) || ($usergroup != NULL)) {
100
            throw new InvalidArgumentException("The type of the usergroup variable is not valid.");
101
        }
102
        if (!is_bool($include_count) &&  ($include_count != NULL)) {
103
            throw new InvalidArgumentException("The type of the include_count variable is not valid.");
104
        }
105
106
        // Set the arguments of the request
107
        $arguments = array(
108
            "usergroup" => $usergroup
109
        );
110
111
        if ($include_count != NULL) {
112
            $arguments["include_count"] = $include_count;
113
        }
114
115
        $this->setUrl("usergroups.disable", $arguments);
116
117
        // Send the request
118
        try {
119
            $client = new \GuzzleHttp\Client();
120
            $json_response = $client->request('GET', $this->getUrl(), []);
121
            $response = json_decode( $json_response->getBody() );
122
        }
123
        catch (RequestException $e) {
124
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
125
        }
126
127
        if($response->{'ok'} === FALSE) {
128
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
129
        }
130
131
        return $json_response->getBody();
132
    }
133
134
135
136
137
    /**
138
     * {@inheritdoc}
139
     *
140
     * @param  string $usergroup
141
     * @param  bool $include_count
142
     * @return string
143
     */
144 View Code Duplication
    public function enable($usergroup, $include_count = 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...
145
146
        // Check if the type of the variables is valid.
147
        if (!is_string($usergroup) || ($usergroup != NULL)) {
148
            throw new InvalidArgumentException("The type of the usergroup variable is not valid.");
149
        }
150
        if (!is_bool($include_count) &&  ($include_count != NULL)) {
151
            throw new InvalidArgumentException("The type of the include_count variable is not valid.");
152
        }
153
154
        // Set the arguments of the request
155
        $arguments = array(
156
            "usergroup" => $usergroup
157
        );
158
159
        if ($include_count != NULL) {
160
            $arguments["include_count"] = $include_count;
161
        }
162
163
        $this->setUrl("usergroups.enable", $arguments);
164
165
        // Send the request
166
        try {
167
            $client = new \GuzzleHttp\Client();
168
            $json_response = $client->request('GET', $this->getUrl(), []);
169
            $response = json_decode( $json_response->getBody() );
170
        }
171
        catch (RequestException $e) {
172
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
173
        }
174
175
        if($response->{'ok'} === FALSE) {
176
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
177
        }
178
179
        return $json_response->getBody();
180
    }
181
182
183
184
185
186
    /**
187
     * {@inheritdoc}
188
     *
189
     * @param  bool $include_disabled
190
     * @param  bool $include_count
191
     * @param  bool $include_users
192
     * @return string
193
     */
194 View Code Duplication
    public function list_usergroups($include_disabled = NULL, $include_count = NULL, $include_users = 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...
195
196
        // Check if the type of the variables is valid.
197
        if (!is_bool($include_disabled) &&  ($include_disabled != NULL)) {
198
            throw new InvalidArgumentException("The type of the include_disabled variable is not valid.");
199
        }
200
        if (!is_bool($include_count) &&  ($include_count != NULL)) {
201
            throw new InvalidArgumentException("The type of the include_count variable is not valid.");
202
        }
203
        if (!is_bool($include_users) &&  ($include_users != NULL)) {
204
            throw new InvalidArgumentException("The type of the include_users variable is not valid.");
205
        }
206
207
        // Set the arguments of the request
208
        $arguments = array();
209
210
        if ($include_disabled != NULL) {
211
            $arguments["include_disabled"] = $include_disabled;
212
        }
213
        if ($include_count != NULL) {
214
            $arguments["include_count"] = $include_count;
215
        }
216
        if ($include_users != NULL) {
217
            $arguments["include_users"] = $include_users;
218
        }
219
220
        $this->setUrl("usergroups.list", $arguments);
221
222
        // Send the request
223
        try {
224
            $client = new \GuzzleHttp\Client();
225
            $json_response = $client->request('GET', $this->getUrl(), []);
226
            $response = json_decode( $json_response->getBody() );
227
        }
228
        catch (RequestException $e) {
229
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
230
        }
231
232
        if($response->{'ok'} === FALSE) {
233
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
234
        }
235
236
        return $json_response->getBody();
237
    }
238
239
240
241
242
    /**
243
     * {@inheritdoc}
244
     *
245
     * @param  string $usergroup
246
     * @param  string $name
247
     * @param  string $handle
248
     * @param  string $description
249
     * @param  string $channels
250
     * @param  bool $include_count
251
     * @return string
252
     */
253
    public function update($usergroup, $name = NULL, $handle = NULL, $description = NULL, $channels = NULL, $include_count = NULL) {
254
255
        // Check if the type of the variables is valid.
256
        if (!is_string($usergroup) || ($usergroup == NULL)) {
257
            throw new InvalidArgumentException("The type of the usergroup variable is not valid.");
258
        }
259
        if (!is_string($name) && ($name != NULL)) {
260
            throw new InvalidArgumentException("The type of the name variable is not valid.");
261
        }
262
        if (!is_string($handle) &&  ($name != NULL)) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $name of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
263
            throw new InvalidArgumentException("The type of the handle variable is not valid.");
264
        }
265
        if (!is_string($description) &&  ($description != NULL)) {
266
            throw new InvalidArgumentException("The type of the description variable is not valid.");
267
        }
268
        if (!is_string($channels) &&  ($channels != NULL)) {
269
            throw new InvalidArgumentException("The type of the channels variable is not valid.");
270
        }
271
        if (!is_bool($include_count) &&  ($include_count != NULL)) {
272
            throw new InvalidArgumentException("The type of the include_count variable is not valid.");
273
        }
274
275
        // Set the arguments of the request
276
        $arguments = array(
277
            "usergroup" => $usergroup
278
        );
279
280
        if ($name != NULL) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $name of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
281
            $arguments["name"] = $name;
282
        }
283
        if ($handle != NULL) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $handle of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
284
            $arguments["handle"] = $handle;
285
        }
286
        if ($description != NULL) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $description of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
287
            $arguments["description"] = $description;
288
        }
289
        if ($channels != NULL) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $channels of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
290
            $arguments["channels"] = $channels;
291
        }
292
        if ($include_count != NULL) {
293
            $arguments["include_count"] = $include_count;
294
        }
295
296
        $this->setUrl("usergroups.update", $arguments);
297
298
        // Send the request
299
        try {
300
            $client = new \GuzzleHttp\Client();
301
            $json_response = $client->request('GET', $this->getUrl(), []);
302
            $response = json_decode( $json_response->getBody() );
303
        }
304
        catch (RequestException $e) {
305
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
306
        }
307
308
        if($response->{'ok'} === FALSE) {
309
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
310
        }
311
312
        return $json_response->getBody();
313
    }
314
315
316
317
318
    /**
319
     * {@inheritdoc}
320
     *
321
     * @param  string $usergroup
322
     * @param  bool $include_disabled
323
     * @return string
324
     */
325 View Code Duplication
    public function usersList($usergroup, $include_disabled = 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...
326
327
        // Check if the type of the variables is valid.
328
        if (!is_string($usergroup) || ($usergroup == NULL)) {
329
            throw new InvalidArgumentException("The type of the usergroup variable is not valid.");
330
        }
331
        if (!is_bool($include_disabled) &&  ($include_disabled != NULL)) {
332
            throw new InvalidArgumentException("The type of the include_disabled variable is not valid.");
333
        }
334
335
        // Set the arguments of the request
336
        $arguments = array(
337
            "usergroup" => $usergroup
338
        );
339
340
        if ($include_disabled != NULL) {
341
            $arguments["include_disabled"] = $include_disabled;
342
        }
343
344
        $this->setUrl("usergroups.users.list", $arguments);
345
346
        // Send the request
347
        try {
348
            $client = new \GuzzleHttp\Client();
349
            $json_response = $client->request('GET', $this->getUrl(), []);
350
            $response = json_decode( $json_response->getBody() );
351
        }
352
        catch (RequestException $e) {
353
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
354
        }
355
356
        if($response->{'ok'} === FALSE) {
357
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
358
        }
359
360
        return $json_response->getBody();
361
    }
362
363
364
365
366
    /**
367
     * {@inheritdoc}
368
     *
369
     * @param  string $usergroup
370
     * @param  string $users
371
     * @param  bool $include_count
0 ignored issues
show
Bug introduced by
There is no parameter named $include_count. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
372
     * @return string
373
     */
374
    public function usersUpdate($usergroup, $users, $include_disabled = NULL) {
0 ignored issues
show
Unused Code introduced by
The parameter $include_disabled is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
375
376
        // Check if the type of the variables is valid.
377
        if (!is_string($usergroup) || ($usergroup == NULL)) {
378
            throw new InvalidArgumentException("The type of the usergroup variable is not valid.");
379
        }
380
        if (!is_string($users) || ($users == NULL)) {
381
            throw new InvalidArgumentException("The type of the users variable is not valid.");
382
        }
383
        if (!is_bool($include_count) &&  ($include_count != NULL)) {
0 ignored issues
show
Bug introduced by
The variable $include_count 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...
384
            throw new InvalidArgumentException("The type of the include_count variable is not valid.");
385
        }
386
387
        // Set the arguments of the request
388
        $arguments = array(
389
            "usergroup" => $usergroup,
390
            "users" => $users
391
        );
392
393
        if ($include_count != NULL) {
394
            $arguments["include_count"] = $include_count;
395
        }
396
397
        $this->setUrl("usergroups.users.update", $arguments);
398
399
        // Send the request
400
        try {
401
            $client = new \GuzzleHttp\Client();
402
            $json_response = $client->request('GET', $this->getUrl(), []);
403
            $response = json_decode( $json_response->getBody() );
404
        }
405
        catch (RequestException $e) {
406
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
407
        }
408
409
        if($response->{'ok'} === FALSE) {
410
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
411
        }
412
413
        return $json_response->getBody();
414
    }
415
}
416