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.

Search   A
last analyzed

Complexity

Total Complexity 27

Size/Duplication

Total Lines 194
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 27
c 0
b 0
f 0
lcom 1
cbo 5
dl 0
loc 194
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B all() 0 50 9
B files() 0 50 9
B messages() 0 50 9
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 Search extends AbstractApi
19
{
20
    /**
21
     * {@inheritdoc}
22
     *
23
     * @param  string $query
24
     * @param  string $sort
25
     * @param  string $sort_dir
26
     * @param  int $hightlight
27
     * @param  int $count
28
     * @param  int $page
29
     * @return string
30
     */
31
    public function all($query, $sort = "score", $sort_dir = "desc", $hightlight = 1, $count = 20, $page = 1) {
32
33
        // Check if the type of the variables is valid.
34
        if (!is_string($query)) {
35
            throw new InvalidArgumentException("The type of the query variable is not valid.");
36
        }
37
        if (!is_string($sort)) {
38
            throw new InvalidArgumentException("The type of the sort variable is not valid.");
39
        }
40
        if (!is_string($sort_dir)) {
41
            throw new InvalidArgumentException("The type of the sort_dir variable is not valid.");
42
        }
43
        if (!is_integer($hightlight)) {
44
            throw new InvalidArgumentException("The type of the hightlight variable is not valid.");
45
        }
46
        if (!is_integer($count)) {
47
            throw new InvalidArgumentException("The type of the count variable is not valid.");
48
        }
49
        if (!is_integer($page)) {
50
            throw new InvalidArgumentException("The type of the page variable is not valid.");
51
        }
52
53
        // Set the arguments of the request
54
        $arguments = array(
55
            "query" => $query,
56
            "sort" => $sort,
57
            "sort_dir" => $sort_dir,
58
            "hightlight" => $hightlight,
59
            "count" => $count,
60
            "page" => $page
61
        );
62
63
        $this->setUrl("search.all", $arguments);
64
65
        // Send the request
66
        try {
67
            $client = new \GuzzleHttp\Client();
68
            $json_response = $client->request('GET', $this->getUrl(), []);
69
            $response = json_decode( $json_response->getBody() );
70
        }
71
        catch (RequestException $e) {
72
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
73
        }
74
75
        if($response->{'ok'} === FALSE) {
76
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
77
        }
78
79
        return $json_response->getBody();
80
    }
81
82
83
84
85
    /**
86
     * {@inheritdoc}
87
     *
88
     * @param  string $query
89
     * @param  string $sort
90
     * @param  string $sort_dir
91
     * @param  int $hightlight
92
     * @param  int $count
93
     * @param  int $page
94
     * @return string
95
     */
96
    public function files($query, $sort = "score", $sort_dir = "desc", $hightlight = 1, $count = 20, $page = 1) {
97
98
        // Check if the type of the variables is valid.
99
        if (!is_string($query)) {
100
            throw new InvalidArgumentException("The type of the query variable is not valid.");
101
        }
102
        if (!is_string($sort)) {
103
            throw new InvalidArgumentException("The type of the sort variable is not valid.");
104
        }
105
        if (!is_string($sort_dir)) {
106
            throw new InvalidArgumentException("The type of the sort_dir variable is not valid.");
107
        }
108
        if (!is_integer($hightlight)) {
109
            throw new InvalidArgumentException("The type of the hightlight variable is not valid.");
110
        }
111
        if (!is_integer($count)) {
112
            throw new InvalidArgumentException("The type of the count variable is not valid.");
113
        }
114
        if (!is_integer($page)) {
115
            throw new InvalidArgumentException("The type of the page variable is not valid.");
116
        }
117
118
        // Set the arguments of the request
119
        $arguments = array(
120
            "query" => $query,
121
            "sort" => $sort,
122
            "sort_dir" => $sort_dir,
123
            "hightlight" => $hightlight,
124
            "count" => $count,
125
            "page" => $page
126
        );
127
128
        $this->setUrl("search.files", $arguments);
129
130
        // Send the request
131
        try {
132
            $client = new \GuzzleHttp\Client();
133
            $json_response = $client->request('GET', $this->getUrl(), []);
134
            $response = json_decode( $json_response->getBody() );
135
        }
136
        catch (RequestException $e) {
137
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
138
        }
139
140
        if($response->{'ok'} === FALSE) {
141
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
142
        }
143
144
        return $json_response->getBody();
145
    }
146
147
148
149
150
    /**
151
     * {@inheritdoc}
152
     *
153
     * @param  string $query
154
     * @param  string $sort
155
     * @param  string $sort_dir
156
     * @param  int $hightlight
157
     * @param  int $count
158
     * @param  int $page
159
     * @return string
160
     */
161
    public function messages($query, $sort = "score", $sort_dir = "desc", $hightlight = 1, $count = 20, $page = 1) {
162
163
        // Check if the type of the variables is valid.
164
        if (!is_string($query)) {
165
            throw new InvalidArgumentException("The type of the query variable is not valid.");
166
        }
167
        if (!is_string($sort)) {
168
            throw new InvalidArgumentException("The type of the sort variable is not valid.");
169
        }
170
        if (!is_string($sort_dir)) {
171
            throw new InvalidArgumentException("The type of the sort_dir variable is not valid.");
172
        }
173
        if (!is_integer($hightlight)) {
174
            throw new InvalidArgumentException("The type of the hightlight variable is not valid.");
175
        }
176
        if (!is_integer($count)) {
177
            throw new InvalidArgumentException("The type of the count variable is not valid.");
178
        }
179
        if (!is_integer($page)) {
180
            throw new InvalidArgumentException("The type of the page variable is not valid.");
181
        }
182
183
        // Set the arguments of the request
184
        $arguments = array(
185
            "query" => $query,
186
            "sort" => $sort,
187
            "sort_dir" => $sort_dir,
188
            "hightlight" => $hightlight,
189
            "count" => $count,
190
            "page" => $page
191
        );
192
193
        $this->setUrl("search.messages", $arguments);
194
195
        // Send the request
196
        try {
197
            $client = new \GuzzleHttp\Client();
198
            $json_response = $client->request('GET', $this->getUrl(), []);
199
            $response = json_decode( $json_response->getBody() );
200
        }
201
        catch (RequestException $e) {
202
            throw new RuntimeException('The request to the API failed: '.$e->getMessage(), $e->getCode(), $e);
203
        }
204
205
        if($response->{'ok'} === FALSE) {
206
            throw new RuntimeException('The request to the API failed: '.$response->{'error'}.".");
207
        }
208
209
        return $json_response->getBody();
210
    }
211
}
212