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.
Completed
Push — master ( 30655b...a8e9a1 )
by Romain
04:44
created

Reminders::list_reminders()   A

Complexity

Conditions 3
Paths 5

Size

Total Lines 20
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 20
rs 9.4285
cc 3
eloc 11
nc 5
nop 0
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 Reminders extends AbstractApi
19
{
20
    /**
21
     * {@inheritdoc}
22
     *
23
     * @param  string $text
24
     * @param  integer $time
25
     * @param  string $user
26
     * @return Reminders
27
     */
28 View Code Duplication
    public function add($text, $time, $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...
29
30
        // Check if the type of the variables is valid.
31
        if (!is_string($text)) {
32
            throw new InvalidArgumentException("The type of the text variable is not valid.");
33
        }
34
        if (!is_integer($time)) {
35
            throw new InvalidArgumentException("The type of the time variable is not valid.");
36
        }
37
        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...
38
            throw new InvalidArgumentException("The type of the user variable is not valid.");
39
        }
40
41
        // Set the arguments of the request
42
        $arguments = array(
43
            "text" => $text,
44
            "time" => (string)$time
45
        );
46
47
        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...
48
            $arguments["user"] = $user;
49
        }
50
51
        $this->setUrl("reminders.add", $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 $reminder
77
     * @return Reminders
78
     */
79
    public function complete($reminder) {
80
81
        // Check if the type of the variables is valid.
82
        if (!is_string($reminder)) {
83
            throw new InvalidArgumentException("The type of the reminder variable is not valid.");
84
        }
85
86
        // Set the arguments of the request
87
        $arguments = array(
88
            "reminder" => $reminder
89
        );
90
91
        $this->setUrl("reminders.complete", $arguments);
92
93
        // Send the request
94
        try {
95
            $client = new \GuzzleHttp\Client();
96
            $json_response = $client->request('GET', $this->getUrl(), []);
97
            $response = json_decode( $json_response->getBody() );
98
        }
99
        catch (RequestException $e) {
100
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
101
        }
102
103
        if($response->{'ok'} === FALSE) {
104
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
105
        }
106
107
        return $this;
108
    }
109
110
111
112
113
    /**
114
     * {@inheritdoc}
115
     *
116
     * @param  string $reminder
117
     * @return Reminders
118
     */
119
    public function delete($reminder) {
120
121
        // Check if the type of the variables is valid.
122
        if (!is_string($reminder)) {
123
            throw new InvalidArgumentException("The type of the reminder variable is not valid.");
124
        }
125
126
        // Set the arguments of the request
127
        $arguments = array(
128
            "reminder" => $reminder
129
        );
130
131
        $this->setUrl("reminders.delete", $arguments);
132
133
        // Send the request
134
        try {
135
            $client = new \GuzzleHttp\Client();
136
            $json_response = $client->request('GET', $this->getUrl(), []);
137
            $response = json_decode( $json_response->getBody() );
138
        }
139
        catch (RequestException $e) {
140
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
141
        }
142
143
        if($response->{'ok'} === FALSE) {
144
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
145
        }
146
147
        return $this;
148
    }
149
150
151
152
153
    /**
154
     * {@inheritdoc}
155
     *
156
     * @param  string $reminder
157
     * @return string
158
     */
159
    public function info($reminder) {
160
161
        // Check if the type of the variables is valid.
162
        if (!is_string($reminder)) {
163
            throw new InvalidArgumentException("The type of the reminder variable is not valid.");
164
        }
165
166
        // Set the arguments of the request
167
        $arguments = array(
168
            "reminder" => $reminder
169
        );
170
171
        $this->setUrl("reminders.info", $arguments);
172
173
        // Send the request
174
        try {
175
            $client = new \GuzzleHttp\Client();
176
            $json_response = $client->request('GET', $this->getUrl(), []);
177
            $response = json_decode( $json_response->getBody() );
178
        }
179
        catch (RequestException $e) {
180
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
181
        }
182
183
        if($response->{'ok'} === FALSE) {
184
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
185
        }
186
187
        return $json_response->getBody();
188
    }
189
190
191
192
193
    /**
194
     * {@inheritdoc}
195
     *
196
     * @return string
197
     */
198
    public function list_reminders() {
199
200
        $this->setUrl("reminders.list");
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