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.

Dnd::teamInfo()   B
last analyzed

Complexity

Conditions 6
Paths 11

Size

Total Lines 32

Duplication

Lines 32
Ratio 100 %

Importance

Changes 0
Metric Value
dl 32
loc 32
rs 8.7857
c 0
b 0
f 0
cc 6
nc 11
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 Dnd extends AbstractApi
19
{
20
    /**
21
     * {@inheritdoc}
22
     *
23
     * @return Dnd
24
     */
25
    public function endDnd() {
26
27
        $this->setUrl("dnd.endDnd");
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
     * {@inheritdoc}
49
     *
50
     * @return Dnd
51
     */
52
    public function endSnooze() {
53
54
        $this->setUrl("dnd.endSnooze");
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
74
    /**
75
     * {@inheritdoc}
76
     *
77
     * @param  string $user
78
     * @return Dnd
79
     */
80 View Code Duplication
    public function info($user = 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...
81
82
        // Check if the type of the variables is valid.
83
        if (($user != NULL) && !is_string($user)) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $user of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
84
            throw new InvalidArgumentException("The type of the user variable is not valid.");
85
        }
86
87
        // Set the arguments of the request
88
        $arguments = array();
89
90
        if($user != NULL) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $user of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
91
            $arguments["user"] = $user;
92
        }
93
94
        $this->setUrl("dnd.info", $arguments);
95
96
        // Send the request
97
        try {
98
            $client = new \GuzzleHttp\Client();
99
            $json_response = $client->request('GET', $this->getUrl(), []);
100
            $response = json_decode( $json_response->getBody() );
101
        }
102
        catch (RequestException $e) {
103
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
104
        }
105
106
        if($response->{'ok'} === FALSE) {
107
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
108
        }
109
110
        return $json_response->getBody();
111
    }
112
113
114
    /**
115
     * {@inheritdoc}
116
     *
117
     * @param  integer $num_minutes
118
     * @return Dnd
119
     */
120
    public function setSnooze($num_minutes) {
121
122
        // Check if the type of the variables is valid.
123
        if (!is_integer($num_minutes)) {
124
            throw new InvalidArgumentException("The type of the num_minutes variable is not valid.");
125
        }
126
127
        // Set the arguments of the request
128
        $arguments = array(
129
            "num_minutes" => $num_minutes
130
        );
131
132
        $this->setUrl("dnd.setSnooze", $arguments);
133
134
        // Send the request
135
        try {
136
            $client = new \GuzzleHttp\Client();
137
            $json_response = $client->request('GET', $this->getUrl(), []);
138
            $response = json_decode( $json_response->getBody() );
139
        }
140
        catch (RequestException $e) {
141
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
142
        }
143
144
        if($response->{'ok'} === FALSE) {
145
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
146
        }
147
148
        return $json_response->getBody();
149
    }
150
151
152
    /**
153
     * {@inheritdoc}
154
     *
155
     * @param  string $users
156
     * @return Dnd
157
     */
158 View Code Duplication
    public function teamInfo($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...
159
160
        // Check if the type of the variables is valid.
161
        if (($user != NULL) && !is_string($user)) {
0 ignored issues
show
Bug introduced by
The variable $user 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...
162
            throw new InvalidArgumentException("The type of the users variable is not valid.");
163
        }
164
165
        // Set the arguments of the request
166
        $arguments = array();
167
168
        if($user != NULL) {
169
            $arguments["users"] = $users;
170
        }
171
172
        $this->setUrl("dnd.teamInfo", $arguments);
173
174
        // Send the request
175
        try {
176
            $client = new \GuzzleHttp\Client();
177
            $json_response = $client->request('GET', $this->getUrl(), []);
178
            $response = json_decode( $json_response->getBody() );
179
        }
180
        catch (RequestException $e) {
181
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
182
        }
183
184
        if($response->{'ok'} === FALSE) {
185
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
186
        }
187
188
        return $json_response->getBody();
189
    }
190
}
191