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.

Groups   F
last analyzed

Complexity

Total Complexity 80

Size/Duplication

Total Lines 739
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 80
lcom 1
cbo 5
dl 0
loc 739
rs 1.861
c 0
b 0
f 0

17 Methods

Rating   Name   Duplication   Size   Complexity  
A archive() 0 30 4
A close() 0 30 4
A create() 0 30 4
A createChild() 0 30 4
B history() 0 50 9
A info() 0 30 4
A invite() 0 34 5
A kick() 0 34 5
A leave() 0 30 4
A list_groups() 0 30 4
A mark() 0 34 5
A open() 0 30 4
A rename() 0 34 5
A replies() 0 34 5
A setPurpose() 0 34 5
A setTopic() 0 34 5
A unarchive() 0 30 4

How to fix   Complexity   

Complex Class

Complex classes like Groups often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Groups, and based on these observations, apply Extract Interface, too.

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 Groups extends AbstractApi
19
{
20
    /**
21
     * {@inheritdoc}
22
     *
23
     * @param  string $channel
24
     * @return Groups
25
     */
26
    public function archive($channel) {
27
28
        // Check if the type of the variables is valid.
29
        if (!is_string($channel)) {
30
            throw new InvalidArgumentException("The type of the channel variable is not valid.");
31
        }
32
33
        // Set the arguments of the request
34
        $arguments = array(
35
            "channel" => $channel
36
        );
37
38
        $this->setUrl("groups.archive", $arguments);
39
40
        // Send the request
41
        try {
42
            $client = new \GuzzleHttp\Client();
43
            $json_response = $client->request('GET', $this->getUrl(), []);
44
            $response = json_decode( $json_response->getBody() );
45
        }
46
        catch (RequestException $e) {
47
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
48
        }
49
50
        if($response->{'ok'} === FALSE) {
51
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
52
        }
53
54
        return $this;
55
    }
56
57
58
59
60
    /**
61
     * {@inheritdoc}
62
     *
63
     * @param  string $channel
64
     * @return Groups
65
     */
66
    public function close($channel) {
67
68
        // Check if the type of the variables is valid.
69
        if (!is_string($channel)) {
70
            throw new InvalidArgumentException("The type of the channel variable is not valid.");
71
        }
72
73
        // Set the arguments of the request
74
        $arguments = array(
75
            "channel" => $channel
76
        );
77
78
        $this->setUrl("groups.close", $arguments);
79
80
        // Send the request
81
        try {
82
            $client = new \GuzzleHttp\Client();
83
            $json_response = $client->request('GET', $this->getUrl(), []);
84
            $response = json_decode( $json_response->getBody() );
85
        }
86
        catch (RequestException $e) {
87
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
88
        }
89
90
        if($response->{'ok'} === FALSE) {
91
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
92
        }
93
94
        return $json_response->getBody();
95
    }
96
97
98
99
100
    /**
101
     * {@inheritdoc}
102
     *
103
     * @param  string $name
104
     * @return Groups
105
     */
106
    public function create($name) {
107
108
        // Check if the type of the variables is valid.
109
        if (!is_string($name)) {
110
            throw new InvalidArgumentException("The type of the name variable is not valid.");
111
        }
112
113
        // Set the arguments of the request
114
        $arguments = array(
115
            "name" => $name
116
        );
117
118
        $this->setUrl("groups.create", $arguments);
119
120
        // Send the request
121
        try {
122
            $client = new \GuzzleHttp\Client();
123
            $json_response = $client->request('GET', $this->getUrl(), []);
124
            $response = json_decode( $json_response->getBody() );
125
        }
126
        catch (RequestException $e) {
127
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
128
        }
129
130
        if($response->{'ok'} === FALSE) {
131
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
132
        }
133
134
        return $json_response->getBody();
135
    }
136
137
138
139
140
    /**
141
     * {@inheritdoc}
142
     *
143
     * @param  string $channel
144
     * @return Groups
145
     */
146
    public function createChild($channel) {
147
148
        // Check if the type of the variables is valid.
149
        if (!is_string($channel)) {
150
            throw new InvalidArgumentException("The type of the channel variable is not valid.");
151
        }
152
153
        // Set the arguments of the request
154
        $arguments = array(
155
            "channel" => $channel
156
        );
157
158
        $this->setUrl("groups.createChild", $arguments);
159
160
        // Send the request
161
        try {
162
            $client = new \GuzzleHttp\Client();
163
            $json_response = $client->request('GET', $this->getUrl(), []);
164
            $response = json_decode( $json_response->getBody() );
165
        }
166
        catch (RequestException $e) {
167
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
168
        }
169
170
        if($response->{'ok'} === FALSE) {
171
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
172
        }
173
174
        return $json_response->getBody();
175
    }
176
177
178
179
180
    /**
181
     * {@inheritdoc}
182
     *
183
     * @param  string $channel
184
     * @param  string $latest
185
     * @param  string $oldest
186
     * @param  integer $inclusive
187
     * @param  integer $count
188
     * @param  integer $unreads
189
     * @return Groups
190
     */
191
    public function history($channel, $latest = "now", $oldest = "0", $inclusive = 0, $count = 100, $unreads = 0) {
192
193
        // Check if the type of the variables is valid.
194
        if (!is_string($channel)) {
195
            throw new InvalidArgumentException("The type of the channel variable is not valid.");
196
        }
197
        if (!is_string($latest)) {
198
            throw new InvalidArgumentException("The type of the latest variable is not valid.");
199
        }
200
        if (!is_string($oldest)) {
201
            throw new InvalidArgumentException("The type of the oldest variable is not valid.");
202
        }
203
        if (!is_integer($inclusive)) {
204
            throw new InvalidArgumentException("The type of the inclusive variable is not valid.");
205
        }
206
        if (!is_integer($count)) {
207
            throw new InvalidArgumentException("The type of the count variable is not valid.");
208
        }
209
        if (!is_integer($unreads)) {
210
            throw new InvalidArgumentException("The type of the unreads variable is not valid.");
211
        }
212
213
        // Set the arguments of the request
214
        $arguments = array(
215
            "channel" => $channel,
216
            "latest" => $latest,
217
            "oldest" => $oldest,
218
            "inclusive" => (string)$inclusive,
219
            "count" => (string)$count,
220
            "unreads" => (string)$unreads
221
        );
222
223
        $this->setUrl("groups.history", $arguments);
224
225
        // Send the request
226
        try {
227
            $client = new \GuzzleHttp\Client();
228
            $json_response = $client->request('GET', $this->getUrl(), []);
229
            $response = json_decode( $json_response->getBody() );
230
        }
231
        catch (RequestException $e) {
232
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
233
        }
234
235
        if($response->{'ok'} === FALSE) {
236
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
237
        }
238
239
        return $json_response->getBody();
240
    }
241
242
243
244
245
    /**
246
     * {@inheritdoc}
247
     *
248
     * @param  string $channel
249
     * @return Groups
250
     */
251
    public function info($channel) {
252
253
        // Check if the type of the variables is valid.
254
        if (!is_string($channel)) {
255
            throw new InvalidArgumentException("The type of the channel variable is not valid.");
256
        }
257
258
        // Set the arguments of the request
259
        $arguments = array(
260
            "channel" => $channel
261
        );
262
263
        $this->setUrl("groups.info", $arguments);
264
265
        // Send the request
266
        try {
267
            $client = new \GuzzleHttp\Client();
268
            $json_response = $client->request('GET', $this->getUrl(), []);
269
            $response = json_decode( $json_response->getBody() );
270
        }
271
        catch (RequestException $e) {
272
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
273
        }
274
275
        if($response->{'ok'} === FALSE) {
276
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
277
        }
278
279
        return $json_response->getBody();
280
    }
281
282
283
284
285
    /**
286
     * {@inheritdoc}
287
     *
288
     * @param  string $channel
289
     * @param  string $user
290
     * @return Groups
291
     */
292
    public function invite($channel, $user) {
293
294
        // Check if the type of the variables is valid.
295
        if (!is_string($channel)) {
296
            throw new InvalidArgumentException("The type of the channel variable is not valid.");
297
        }
298
        if (!is_string($user)) {
299
            throw new InvalidArgumentException("The type of the user variable is not valid.");
300
        }
301
302
        // Set the arguments of the request
303
        $arguments = array(
304
            "channel" => $channel,
305
            "user" => $user
306
        );
307
308
        $this->setUrl("groups.invite", $arguments);
309
310
        // Send the request
311
        try {
312
            $client = new \GuzzleHttp\Client();
313
            $json_response = $client->request('GET', $this->getUrl(), []);
314
            $response = json_decode( $json_response->getBody() );
315
        }
316
        catch (RequestException $e) {
317
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
318
        }
319
320
        if($response->{'ok'} === FALSE) {
321
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
322
        }
323
324
        return $json_response->getBody();
325
    }
326
327
328
329
330
    /**
331
     * {@inheritdoc}
332
     *
333
     * @param  string $channel
334
     * @param  string $user
335
     * @return Groups
336
     */
337
    public function kick($channel, $user) {
338
339
        // Check if the type of the variables is valid.
340
        if (!is_string($channel)) {
341
            throw new InvalidArgumentException("The type of the channel variable is not valid.");
342
        }
343
        if (!is_string($user)) {
344
            throw new InvalidArgumentException("The type of the user variable is not valid.");
345
        }
346
347
        // Set the arguments of the request
348
        $arguments = array(
349
            "channel" => $channel,
350
            "user" => $user
351
        );
352
353
        $this->setUrl("groups.kick", $arguments);
354
355
        // Send the request
356
        try {
357
            $client = new \GuzzleHttp\Client();
358
            $json_response = $client->request('GET', $this->getUrl(), []);
359
            $response = json_decode( $json_response->getBody() );
360
        }
361
        catch (RequestException $e) {
362
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
363
        }
364
365
        if($response->{'ok'} === FALSE) {
366
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
367
        }
368
369
        return $this;
370
    }
371
372
373
374
375
    /**
376
     * {@inheritdoc}
377
     *
378
     * @param  string $channel
379
     * @return Groups
380
     */
381
    public function leave($channel) {
382
383
        // Check if the type of the variables is valid.
384
        if (!is_string($channel)) {
385
            throw new InvalidArgumentException("The type of the channel variable is not valid.");
386
        }
387
388
        // Set the arguments of the request
389
        $arguments = array(
390
            "channel" => $channel
391
        );
392
393
        $this->setUrl("groups.leave", $arguments);
394
395
        // Send the request
396
        try {
397
            $client = new \GuzzleHttp\Client();
398
            $json_response = $client->request('GET', $this->getUrl(), []);
399
            $response = json_decode( $json_response->getBody() );
400
        }
401
        catch (RequestException $e) {
402
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
403
        }
404
405
        if($response->{'ok'} === FALSE) {
406
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
407
        }
408
409
        return $this;
410
    }
411
412
413
414
415
    /**
416
     * {@inheritdoc}
417
     *
418
     * @param  integer $exclude_archived
419
     * @return Groups
420
     */
421
    public function list_groups($exclude_archived = 0) {
422
423
        // Check if the type of the variables is valid.
424
        if (!is_integer($exclude_archived)) {
425
            throw new InvalidArgumentException("The type of the exclude_archived variable is not valid.");
426
        }
427
428
        // Set the arguments of the request
429
        $arguments = array(
430
            "exclude_archived" => (string)$exclude_archived
431
        );
432
433
        $this->setUrl("groups.list", $arguments);
434
435
        // Send the request
436
        try {
437
            $client = new \GuzzleHttp\Client();
438
            $json_response = $client->request('GET', $this->getUrl(), []);
439
            $response = json_decode( $json_response->getBody() );
440
        }
441
        catch (RequestException $e) {
442
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
443
        }
444
445
        if($response->{'ok'} === FALSE) {
446
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
447
        }
448
449
        return $json_response->getBody();
450
    }
451
452
453
454
455
    /**
456
     * {@inheritdoc}
457
     *
458
     * @param  string $channel
459
     * @param  string $ts
460
     * @return Groups
461
     */
462
    public function mark($channel, $ts) {
463
464
        // Check if the type of the variables is valid.
465
        if (!is_string($channel)) {
466
            throw new InvalidArgumentException("The type of the channel variable is not valid.");
467
        }
468
        if (!is_string($ts)) {
469
            throw new InvalidArgumentException("The type of the ts variable is not valid.");
470
        }
471
472
        // Set the arguments of the request
473
        $arguments = array(
474
            "channel" => $channel,
475
            "ts" => $ts
476
        );
477
478
        $this->setUrl("groups.mark", $arguments);
479
480
        // Send the request
481
        try {
482
            $client = new \GuzzleHttp\Client();
483
            $json_response = $client->request('GET', $this->getUrl(), []);
484
            $response = json_decode( $json_response->getBody() );
485
        }
486
        catch (RequestException $e) {
487
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
488
        }
489
490
        if($response->{'ok'} === FALSE) {
491
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
492
        }
493
494
        return $this;
495
    }
496
497
498
499
500
    /**
501
     * {@inheritdoc}
502
     *
503
     * @param  string $channel
504
     * @return Groups
505
     */
506
    public function open($channel) {
507
508
        // Check if the type of the variables is valid.
509
        if (!is_string($channel)) {
510
            throw new InvalidArgumentException("The type of the channel variable is not valid.");
511
        }
512
513
        // Set the arguments of the request
514
        $arguments = array(
515
            "channel" => $channel
516
        );
517
518
        $this->setUrl("groups.open", $arguments);
519
520
        // Send the request
521
        try {
522
            $client = new \GuzzleHttp\Client();
523
            $json_response = $client->request('GET', $this->getUrl(), []);
524
            $response = json_decode( $json_response->getBody() );
525
        }
526
        catch (RequestException $e) {
527
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
528
        }
529
530
        if($response->{'ok'} === FALSE) {
531
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
532
        }
533
534
        return $json_response->getBody();
535
    }
536
537
538
539
540
    /**
541
     * {@inheritdoc}
542
     *
543
     * @param  string $channel
544
     * @param  string $name
545
     * @return Groups
546
     */
547
    public function rename($channel, $name) {
548
549
        // Check if the type of the variables is valid.
550
        if (!is_string($channel)) {
551
            throw new InvalidArgumentException("The type of the channel variable is not valid.");
552
        }
553
        if (!is_string($name)) {
554
            throw new InvalidArgumentException("The type of the name variable is not valid.");
555
        }
556
557
        // Set the arguments of the request
558
        $arguments = array(
559
            "channel" => $channel,
560
            "name" => $name
561
        );
562
563
        $this->setUrl("groups.rename", $arguments);
564
565
        // Send the request
566
        try {
567
            $client = new \GuzzleHttp\Client();
568
            $json_response = $client->request('GET', $this->getUrl(), []);
569
            $response = json_decode( $json_response->getBody() );
570
        }
571
        catch (RequestException $e) {
572
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
573
        }
574
575
        if($response->{'ok'} === FALSE) {
576
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
577
        }
578
579
        return $json_response->getBody();
580
    }
581
582
583
584
585
    /**
586
     * {@inheritdoc}
587
     *
588
     * @param  string $channel
589
     * @param  float $thread_ts
590
     * @return Groups
591
     */
592
    public function replies($channel, $thread_ts) {
593
594
        // Check if the type of the variables is valid.
595
        if (!is_string($channel)) {
596
            throw new InvalidArgumentException("The type of the channel variable is not valid.");
597
        }
598
        if (!is_float($thread_ts)) {
599
            throw new InvalidArgumentException("The type of the thread_ts variable is not valid.");
600
        }
601
602
        // Set the arguments of the request
603
        $arguments = array(
604
            "channel" => $channel,
605
            "thread_ts" => (string)$thread_ts
606
        );
607
608
        $this->setUrl("groups.replies", $arguments);
609
610
        // Send the request
611
        try {
612
            $client = new \GuzzleHttp\Client();
613
            $json_response = $client->request('GET', $this->getUrl(), []);
614
            $response = json_decode( $json_response->getBody() );
615
        }
616
        catch (RequestException $e) {
617
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
618
        }
619
620
        if($response->{'ok'} === FALSE) {
621
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
622
        }
623
624
        return $json_response->getBody();
625
    }
626
627
628
629
630
    /**
631
     * {@inheritdoc}
632
     *
633
     * @param  string $channel
634
     * @param  string $purpose
635
     * @return Groups
636
     */
637
    public function setPurpose($channel, $purpose) {
638
639
        // Check if the type of the variables is valid.
640
        if (!is_string($channel)) {
641
            throw new InvalidArgumentException("The type of the channel variable is not valid.");
642
        }
643
        if (!is_string($purpose)) {
644
            throw new InvalidArgumentException("The type of the purpose variable is not valid.");
645
        }
646
647
        // Set the arguments of the request
648
        $arguments = array(
649
            "channel" => $channel,
650
            "purpose" => $purpose
651
        );
652
653
        $this->setUrl("groups.setPurpose", $arguments);
654
655
        // Send the request
656
        try {
657
            $client = new \GuzzleHttp\Client();
658
            $json_response = $client->request('GET', $this->getUrl(), []);
659
            $response = json_decode( $json_response->getBody() );
660
        }
661
        catch (RequestException $e) {
662
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
663
        }
664
665
        if($response->{'ok'} === FALSE) {
666
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
667
        }
668
669
        return $this;
670
    }
671
672
673
674
675
    /**
676
     * {@inheritdoc}
677
     *
678
     * @param  string $channel
679
     * @param  string $topic
680
     * @return Groups
681
     */
682
    public function setTopic($channel, $topic) {
683
684
        // Check if the type of the variables is valid.
685
        if (!is_string($channel)) {
686
            throw new InvalidArgumentException("The type of the channel variable is not valid.");
687
        }
688
        if (!is_string($topic)) {
689
            throw new InvalidArgumentException("The type of the topic variable is not valid.");
690
        }
691
692
        // Set the arguments of the request
693
        $arguments = array(
694
            "channel" => $channel,
695
            "topic" => $topic
696
        );
697
698
        $this->setUrl("groups.setTopic", $arguments);
699
700
        // Send the request
701
        try {
702
            $client = new \GuzzleHttp\Client();
703
            $json_response = $client->request('GET', $this->getUrl(), []);
704
            $response = json_decode( $json_response->getBody() );
705
        }
706
        catch (RequestException $e) {
707
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
708
        }
709
710
        if($response->{'ok'} === FALSE) {
711
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
712
        }
713
714
        return $this;
715
    }
716
717
718
719
720
    /**
721
     * {@inheritdoc}
722
     *
723
     * @param  string $channel
724
     * @return Groups
725
     */
726
    public function unarchive($channel) {
727
728
        // Check if the type of the variables is valid.
729
        if (!is_string($channel)) {
730
            throw new InvalidArgumentException("The type of the channel variable is not valid.");
731
        }
732
733
        // Set the arguments of the request
734
        $arguments = array(
735
            "channel" => $channel
736
        );
737
738
        $this->setUrl("groups.unarchive", $arguments);
739
740
        // Send the request
741
        try {
742
            $client = new \GuzzleHttp\Client();
743
            $json_response = $client->request('GET', $this->getUrl(), []);
744
            $response = json_decode( $json_response->getBody() );
745
        }
746
        catch (RequestException $e) {
747
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
748
        }
749
750
        if($response->{'ok'} === FALSE) {
751
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
752
        }
753
754
        return $this;
755
    }
756
}
757