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.

Rtm::start()   C
last analyzed

Complexity

Conditions 12
Paths 43

Size

Total Lines 44

Duplication

Lines 44
Ratio 100 %

Importance

Changes 0
Metric Value
dl 44
loc 44
rs 6.9666
c 0
b 0
f 0
cc 12
nc 43
nop 3

How to fix   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 Rtm extends AbstractApi
19
{
20
    /**
21
     * {@inheritdoc}
22
     *
23
     * @param  bool $simple_latest
24
     * @param  bool $no_unreads
25
     * @param  bool $mpim_aware
26
     * @return Reminders
27
     */
28 View Code Duplication
    public function start($simple_latest = NULL, $no_unreads = NULL, $mpim_aware = 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...
29
30
        // Check if the type of the variables is valid.
31
        if (($simple_latest != NULL) && !is_bool($simple_latest)) {
32
            throw new InvalidArgumentException("The type of the simple_latest variable is not valid.");
33
        }
34
        if (($no_unreads != NULL) && !is_bool($no_unreads)) {
35
            throw new InvalidArgumentException("The type of the no_unreads variable is not valid.");
36
        }
37
        if (($mpim_aware != NULL) && !is_bool($mpim_aware)) {
38
            throw new InvalidArgumentException("The type of the mpim_aware variable is not valid.");
39
        }
40
41
        // Set the arguments of the request
42
        $arguments = array();
43
44
        if ($simple_latest != NULL) {
45
            $arguments["simple_latest"] = $simple_latest;
46
        }
47
        if ($no_unreads != NULL) {
48
            $arguments["no_unreads"] = $no_unreads;
49
        }
50
        if ($mpim_aware != NULL) {
51
            $arguments["mpim_aware"] = $mpim_aware;
52
        }
53
54
        $this->setUrl("rtm.start", $arguments);
55
56
        // Send the request
57
        try {
58
            $client = new \GuzzleHttp\Client();
59
            $json_response = $client->request('GET', $this->getUrl(), []);
60
            $response = json_decode( $json_response->getBody() );
61
        }
62
        catch (RequestException $e) {
63
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
64
        }
65
66
        if($response->{'ok'} === FALSE) {
67
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
68
        }
69
70
        return $json_response->getBody();
71
    }
72
}
73