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.

Team::integrationLogs()   F
last analyzed

Complexity

Conditions 19
Paths 326

Size

Total Lines 62

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 62
rs 2.1083
c 0
b 0
f 0
cc 19
nc 326
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 Team extends AbstractApi
19
{
20
    /**
21
     * {@inheritdoc}
22
     *
23
     * @param  string $count
24
     * @param  string $page
25
     * @param  string $before
26
     * @return string
27
     */
28 View Code Duplication
    public function accessLogs($count = 100, $page = 1, $before = 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 (!is_int($count)) {
32
            throw new InvalidArgumentException("The type of the count variable is not valid.");
33
        }
34
        if (!is_int($page)) {
35
            throw new InvalidArgumentException("The type of the page variable is not valid.");
36
        }
37
        if (!is_int($before) && ($before != NULL)) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $before of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
38
            throw new InvalidArgumentException("The type of the before variable is not valid.");
39
        }
40
41
        // Set the arguments of the request
42
        $arguments = array(
43
            "count" => $count,
44
            "page" => $page
45
        );
46
47
        if ($before != NULL) {
48
            $arguments["before"] = $before;
49
        }
50
51
        $this->setUrl("team.accessLogs", $arguments);
52
53
        // Send the request
54
        try {
55
            $client = new \GuzzleHttp\Client();
56
            $json_response = $client->request('GET', $this->getUrl(), []);
57
            $response = json_decode( $json_response->getBody() );
58
        }
59
        catch (RequestException $e) {
60
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
61
        }
62
63
        if($response->{'ok'} === FALSE) {
64
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
65
        }
66
67
        return $json_response->getBody();
68
    }
69
70
71
72
73
    /**
74
     * {@inheritdoc}
75
     *
76
     * @param  string $user
77
     * @return string
78
     */
79 View Code Duplication
    public function billableInfo($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...
80
81
        // Check if the type of the variables is valid.
82
        if (!is_string($user) && ($user != NULL)) {
83
            throw new InvalidArgumentException("The type of the user variable is not valid.");
84
        }
85
86
        // Set the arguments of the request
87
        $arguments = array();
88
89
        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...
90
            $arguments["user"] = $user;
91
        }
92
93
        $this->setUrl("team.billableInfo", $arguments);
94
95
        // Send the request
96
        try {
97
            $client = new \GuzzleHttp\Client();
98
            $json_response = $client->request('GET', $this->getUrl(), []);
99
            $response = json_decode( $json_response->getBody() );
100
        }
101
        catch (RequestException $e) {
102
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
103
        }
104
105
        if($response->{'ok'} === FALSE) {
106
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
107
        }
108
109
        return $json_response->getBody();
110
    }
111
112
113
114
115
    /**
116
     * {@inheritdoc}
117
     *
118
     * @return string
119
     */
120
    public function info() {
121
122
        $this->setUrl("team.info");
123
124
        // Send the request
125
        try {
126
            $client = new \GuzzleHttp\Client();
127
            $json_response = $client->request('GET', $this->getUrl(), []);
128
            $response = json_decode( $json_response->getBody() );
129
        }
130
        catch (RequestException $e) {
131
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
132
        }
133
134
        if($response->{'ok'} === FALSE) {
135
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
136
        }
137
138
        return $json_response->getBody();
139
    }
140
141
142
143
144
145
    /**
146
     * {@inheritdoc}
147
     *
148
     * @param  string $service_id
149
     * @param  string $app_id
150
     * @param  string $user
151
     * @param  string $change_type
152
     * @param  int $count
153
     * @param  int $page
154
     * @return string
155
     */
156
    public function integrationLogs($service_id = NULL, $app_id = NULL, $user = NULL, $change_type = NULL, $count = 100, $page = 1) {
157
158
        // Check if the type of the variables is valid.
159
        if (!is_string($service_id) && ($service_id != NULL)) {
160
            throw new InvalidArgumentException("The type of the service_id variable is not valid.");
161
        }
162
        if (!is_string($app_id) && ($app_id != NULL)) {
163
            throw new InvalidArgumentException("The type of the app_id variable is not valid.");
164
        }
165
        if (!is_string($user) && ($user != NULL)) {
166
            throw new InvalidArgumentException("The type of the user variable is not valid.");
167
        }
168
        if (!is_string($change_type) && ($change_type != NULL)) {
169
            throw new InvalidArgumentException("The type of the change_type variable is not valid.");
170
        }
171
        if (!is_int($count)) {
172
            throw new InvalidArgumentException("The type of the count variable is not valid.");
173
        }
174
        if (!is_string($page)) {
175
            throw new InvalidArgumentException("The type of the page variable is not valid.");
176
        }
177
178
        // Set the arguments of the request
179
        $arguments = array();
180
181
        if($service_id != NULL) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $service_id of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
182
            $arguments["service_id"] = $service_id;
183
        }
184
        if($app_id != NULL) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $app_id of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
185
            $arguments["app_id"] = $app_id;
186
        }
187
        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...
188
            $arguments["user"] = $user;
189
        }
190
        if($change_type != NULL) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $change_type of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
191
            $arguments["change_type"] = $change_type;
192
        }
193
        if($count != NULL) {
194
            $arguments["count"] = $count;
195
        }
196
        if($page != NULL) {
197
            $arguments["page"] = $page;
198
        }
199
200
        $this->setUrl("team.integrationLogs", $arguments);
201
202
        // Send the request
203
        try {
204
            $client = new \GuzzleHttp\Client();
205
            $json_response = $client->request('GET', $this->getUrl(), []);
206
            $response = json_decode( $json_response->getBody() );
207
        }
208
        catch (RequestException $e) {
209
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
210
        }
211
212
        if($response->{'ok'} === FALSE) {
213
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
214
        }
215
216
        return $json_response->getBody();
217
    }
218
219
220
221
222
    /**
223
     * {@inheritdoc}
224
     *
225
     * @param  string $visibility
226
     * @return string
227
     */
228
    public function profileGet($visibility = NULL) {
229
230
        // Set the allowed values for the visibility parameter.
231
        $allowed_visibilities = array("all", "visible", "hidden");
232
233
        // Check if the type of the variables is valid.
234
        if (!is_string($visibility) && ($visibility != NULL) && !in_array($allowed_visibilities, $visibility)) {
235
            throw new InvalidArgumentException("The type of the visibility variable is not valid.");
236
        }
237
238
        // Set the arguments of the request
239
        $arguments = array();
240
241
        if ($visibility != NULL) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $visibility of type string|null against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== instead.
Loading history...
242
            $arguments["visibility"] = $visibility;
243
        }
244
245
        $this->setUrl("team.profile.get", $arguments);
246
247
        // Send the request
248
        try {
249
            $client = new \GuzzleHttp\Client();
250
            $json_response = $client->request('GET', $this->getUrl(), []);
251
            $response = json_decode( $json_response->getBody() );
252
        }
253
        catch (RequestException $e) {
254
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
255
        }
256
257
        if($response->{'ok'} === FALSE) {
258
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
259
        }
260
261
        return $json_response->getBody();
262
    }
263
}
264