1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Stack Exchange Api Client library. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2014-2016 Beñat Espiña <[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 BenatEspina\StackExchangeApiClient\Api; |
13
|
|
|
|
14
|
|
|
use BenatEspina\StackExchangeApiClient\Authentication\Authentication; |
15
|
|
|
use BenatEspina\StackExchangeApiClient\Http\Http; |
16
|
|
|
use BenatEspina\StackExchangeApiClient\Model\Answer; |
17
|
|
|
use BenatEspina\StackExchangeApiClient\Serializer\AnswerSerializer; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* The answer api class. |
21
|
|
|
* |
22
|
|
|
* @author Beñat Espiña <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
final class AnswerApi |
25
|
|
|
{ |
26
|
|
|
const URL = 'answers/'; |
27
|
|
|
const QUERY_PARAMS = [ |
28
|
|
|
'order' => 'desc', |
29
|
|
|
'sort' => 'activity', |
30
|
|
|
'site' => 'stackoverflow', |
31
|
|
|
'filter' => Http::FILTER_ALL, |
32
|
|
|
]; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* The authentication. |
36
|
|
|
* |
37
|
|
|
* @var Authentication|null |
38
|
|
|
*/ |
39
|
|
|
private $authentication; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Constructor. |
43
|
|
|
* |
44
|
|
|
* @param Authentication|null $anAuthentication The authentication |
45
|
|
|
*/ |
46
|
|
|
public function __construct(Authentication $anAuthentication = null) |
47
|
|
|
{ |
48
|
|
|
$this->authentication = $anAuthentication; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Get all answers on the site. |
53
|
|
|
* |
54
|
|
|
* More info: http://api.stackexchange.com/docs/answers |
55
|
|
|
* |
56
|
|
|
* @param array $params QueryString parameter(s) |
57
|
|
|
* @param bool $serialize Checks if the result will be serialize or not, by default is true |
58
|
|
|
* |
59
|
|
|
* @return array |
|
|
|
|
60
|
|
|
*/ |
61
|
|
View Code Duplication |
public function all(array $params = ['site' => 'stackoverflow'], $serialize = true) |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
if ($this->authentication instanceof Authentication) { |
64
|
|
|
if (true === empty($params)) { |
65
|
|
|
$params = array_merge($params, self::QUERY_PARAMS); |
66
|
|
|
} |
67
|
|
|
$params = array_merge($params, $this->authentication->toArray()); |
68
|
|
|
} |
69
|
|
|
$response = Http::instance()->get( |
70
|
|
|
self::URL, $params |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
return $serialize === true ? AnswerSerializer::serialize($response) : $response; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get answers identified by a set of ids. |
78
|
|
|
* |
79
|
|
|
* More info: http://api.stackexchange.com/docs/answers-by-ids |
80
|
|
|
* |
81
|
|
|
* @param string|array $ids Array which contains the ids delimited by semicolon, or a simple id |
82
|
|
|
* @param array $params QueryString parameter(s) |
83
|
|
|
* @param bool $serialize Checks if the result will be serialize or not, by default is true |
84
|
|
|
* |
85
|
|
|
* @return array|Answer |
|
|
|
|
86
|
|
|
*/ |
87
|
|
|
public function getOfIds($ids, array $params = ['site' => 'stackoverflow'], $serialize = true) |
88
|
|
|
{ |
89
|
|
|
if ($this->authentication instanceof Authentication) { |
90
|
|
|
if (true === empty($params)) { |
91
|
|
|
$params = array_merge($params, self::QUERY_PARAMS); |
92
|
|
|
} |
93
|
|
|
$params = array_merge($params, $this->authentication->toArray()); |
94
|
|
|
} |
95
|
|
|
$response = Http::instance()->get( |
96
|
|
|
self::URL . (is_array($ids) ? implode(';', $ids) : $ids), $params |
97
|
|
|
); |
98
|
|
|
|
99
|
|
|
return $serialize === true ? AnswerSerializer::serialize($response) : $response; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Casts an accept vote on the given answer. |
104
|
|
|
* |
105
|
|
|
* More info: https://api.stackexchange.com/docs/accept-answer |
106
|
|
|
* |
107
|
|
|
* @param string $id The id of question |
108
|
|
|
* @param array $params QueryString parameter(s) |
109
|
|
|
* @param bool $serialize Checks if the result will be serialize or not, by default is true |
110
|
|
|
* |
111
|
|
|
* @throws \Exception when the auth is null |
112
|
|
|
* |
113
|
|
|
* @return Answer |
114
|
|
|
*/ |
115
|
|
|
public function accept($id, array $params = self::QUERY_PARAMS, $serialize = true) |
116
|
|
|
{ |
117
|
|
|
if (!$this->authentication instanceof Authentication) { |
118
|
|
|
throw new \Exception('Authentication is required'); |
119
|
|
|
} |
120
|
|
|
$response = Http::instance()->put( |
121
|
|
|
self::URL . $id . '/accept', array_merge($params, $this->authentication->toArray()) |
122
|
|
|
); |
123
|
|
|
|
124
|
|
|
return $serialize === true ? AnswerSerializer::serialize($response) : $response; |
|
|
|
|
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Undoes an accept vote on the given answer. |
129
|
|
|
* |
130
|
|
|
* More info: https://api.stackexchange.com/docs/undo-accept-answer |
131
|
|
|
* |
132
|
|
|
* @param string $id The id of question |
133
|
|
|
* @param array $params QueryString parameter(s) |
134
|
|
|
* @param bool $serialize Checks if the result will be serialize or not, by default is true |
135
|
|
|
* |
136
|
|
|
* @throws \Exception when the auth is null |
137
|
|
|
* |
138
|
|
|
* @return Answer |
139
|
|
|
*/ |
140
|
|
|
public function undoAccept($id, array $params = self::QUERY_PARAMS, $serialize = true) |
141
|
|
|
{ |
142
|
|
|
if (!$this->authentication instanceof Authentication) { |
143
|
|
|
throw new \Exception('Authentication is required'); |
144
|
|
|
} |
145
|
|
|
$response = Http::instance()->put( |
146
|
|
|
self::URL . $id . '/accept/undo', array_merge($params, $this->authentication->toArray()) |
147
|
|
|
); |
148
|
|
|
|
149
|
|
|
return $serialize === true ? AnswerSerializer::serialize($response) : $response; |
|
|
|
|
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Deletes an answer. |
154
|
|
|
* |
155
|
|
|
* More info: https://api.stackexchange.com/docs/delete-answer |
156
|
|
|
* |
157
|
|
|
* @param string $id The id of question |
158
|
|
|
* @param array $params QueryString parameter(s) |
159
|
|
|
* @param bool $serialize Checks if the result will be serialize or not, by default is true |
160
|
|
|
* |
161
|
|
|
* @throws \Exception when the auth is null |
162
|
|
|
* |
163
|
|
|
* @return Answer |
164
|
|
|
*/ |
165
|
|
|
public function delete($id, array $params = self::QUERY_PARAMS, $serialize = true) |
166
|
|
|
{ |
167
|
|
|
if (!$this->authentication instanceof Authentication) { |
168
|
|
|
throw new \Exception('Authentication is required'); |
169
|
|
|
} |
170
|
|
|
$response = Http::instance()->delete( |
171
|
|
|
self::URL . $id . '/delete', array_merge($params, $this->authentication->toArray()) |
172
|
|
|
); |
173
|
|
|
|
174
|
|
|
return $serialize === true ? AnswerSerializer::serialize($response) : $response; |
|
|
|
|
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Downvotes an answer. |
179
|
|
|
* |
180
|
|
|
* More info: https://api.stackexchange.com/docs/downvote-answer |
181
|
|
|
* |
182
|
|
|
* @param string $id The id of question |
183
|
|
|
* @param array $params QueryString parameter(s) |
184
|
|
|
* @param bool $serialize Checks if the result will be serialize or not, by default is true |
185
|
|
|
* |
186
|
|
|
* @throws \Exception when the auth is null |
187
|
|
|
* |
188
|
|
|
* @return Answer |
189
|
|
|
*/ |
190
|
|
|
public function downvote($id, array $params = self::QUERY_PARAMS, $serialize = true) |
191
|
|
|
{ |
192
|
|
|
if (!$this->authentication instanceof Authentication) { |
193
|
|
|
throw new \Exception('Authentication is required'); |
194
|
|
|
} |
195
|
|
|
$response = Http::instance()->put( |
196
|
|
|
self::URL . $id . '/downvote', array_merge($params, $this->authentication->toArray()) |
197
|
|
|
); |
198
|
|
|
|
199
|
|
|
return $serialize === true ? AnswerSerializer::serialize($response) : $response; |
|
|
|
|
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* Undoes an downvote on an answer. |
204
|
|
|
* |
205
|
|
|
* More info: https://api.stackexchange.com/docs/undo-downvote-answer |
206
|
|
|
* |
207
|
|
|
* @param string $id The id of question |
208
|
|
|
* @param array $params QueryString parameter(s) |
209
|
|
|
* @param bool $serialize Checks if the result will be serialize or not, by default is true |
210
|
|
|
* |
211
|
|
|
* @throws \Exception when the auth is null |
212
|
|
|
* |
213
|
|
|
* @return Answer |
214
|
|
|
*/ |
215
|
|
|
public function undoDownvote($id, array $params = self::QUERY_PARAMS, $serialize = true) |
216
|
|
|
{ |
217
|
|
|
if (!$this->authentication instanceof Authentication) { |
218
|
|
|
throw new \Exception('Authentication is required'); |
219
|
|
|
} |
220
|
|
|
$response = Http::instance()->put( |
221
|
|
|
self::URL . $id . '/downvote/undo', array_merge($params, $this->authentication->toArray()) |
222
|
|
|
); |
223
|
|
|
|
224
|
|
|
return $serialize === true ? AnswerSerializer::serialize($response) : $response; |
|
|
|
|
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
/** |
228
|
|
|
* Edit an existing answer. |
229
|
|
|
* |
230
|
|
|
* More info: https://api.stackexchange.com/docs/edit-answer |
231
|
|
|
* |
232
|
|
|
* @param string $id The id of question |
233
|
|
|
* @param string $body The body of the answer |
234
|
|
|
* @param array $params QueryString parameter(s) |
235
|
|
|
* @param bool $serialize Checks if the result will be serialize or not, by default is true |
236
|
|
|
* |
237
|
|
|
* @throws \Exception when the auth is null |
238
|
|
|
* |
239
|
|
|
* @return Answer |
240
|
|
|
*/ |
241
|
|
View Code Duplication |
public function update($id, $body, array $params = self::QUERY_PARAMS, $serialize = true) |
|
|
|
|
242
|
|
|
{ |
243
|
|
|
if (!$this->authentication instanceof Authentication) { |
244
|
|
|
throw new \Exception('Authentication is required'); |
245
|
|
|
} |
246
|
|
|
$response = Http::instance()->put( |
247
|
|
|
self::URL . $id . '/edit', array_merge(['body' => $body], $params, $this->authentication->toArray()) |
248
|
|
|
); |
249
|
|
|
|
250
|
|
|
return $serialize === true ? AnswerSerializer::serialize($response) : $response; |
|
|
|
|
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
/** |
254
|
|
|
* Upvotes an answer. |
255
|
|
|
* |
256
|
|
|
* More info: https://api.stackexchange.com/docs/upvote-answer |
257
|
|
|
* |
258
|
|
|
* @param string $id The id of question |
259
|
|
|
* @param array $params QueryString parameter(s) |
260
|
|
|
* @param bool $serialize Checks if the result will be serialize or not, by default is true |
261
|
|
|
* |
262
|
|
|
* @throws \Exception when the auth is null |
263
|
|
|
* |
264
|
|
|
* @return Answer |
265
|
|
|
*/ |
266
|
|
|
public function upvote($id, array $params = self::QUERY_PARAMS, $serialize = true) |
267
|
|
|
{ |
268
|
|
|
if (!$this->authentication instanceof Authentication) { |
269
|
|
|
throw new \Exception('Authentication is required'); |
270
|
|
|
} |
271
|
|
|
$response = Http::instance()->put( |
272
|
|
|
self::URL . $id . '/upvote', array_merge($params, $this->authentication->toArray()) |
273
|
|
|
); |
274
|
|
|
|
275
|
|
|
return $serialize === true ? AnswerSerializer::serialize($response) : $response; |
|
|
|
|
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* Undoes an upvote on an answer. |
280
|
|
|
* |
281
|
|
|
* More info: https://api.stackexchange.com/docs/undo-upvote-answer |
282
|
|
|
* |
283
|
|
|
* @param string $id The id of question |
284
|
|
|
* @param array $params QueryString parameter(s) |
285
|
|
|
* @param bool $serialize Checks if the result will be serialize or not, by default is true |
286
|
|
|
* |
287
|
|
|
* @throws \Exception when the auth is null |
288
|
|
|
* |
289
|
|
|
* @return Answer |
290
|
|
|
*/ |
291
|
|
|
public function undoUpvote($id, array $params = self::QUERY_PARAMS, $serialize = true) |
292
|
|
|
{ |
293
|
|
|
if (!$this->authentication instanceof Authentication) { |
294
|
|
|
throw new \Exception('Authentication is required'); |
295
|
|
|
} |
296
|
|
|
$response = Http::instance()->put( |
297
|
|
|
self::URL . $id . '/upvote/undo', array_merge($params, $this->authentication->toArray()) |
298
|
|
|
); |
299
|
|
|
|
300
|
|
|
return $serialize === true ? AnswerSerializer::serialize($response) : $response; |
|
|
|
|
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
/** |
304
|
|
|
* Casts a flag against the answer identified by id. |
305
|
|
|
* |
306
|
|
|
* More info: https://api.stackexchange.com/docs/create-answer-flag |
307
|
|
|
* |
308
|
|
|
* @param string $id The id of question |
309
|
|
|
* @param array $params QueryString parameter(s) |
310
|
|
|
* @param bool $serialize Checks if the result will be serialize or not, by default is true |
311
|
|
|
* |
312
|
|
|
* @throws \Exception when the auth is null |
313
|
|
|
* |
314
|
|
|
* @return Answer |
315
|
|
|
*/ |
316
|
|
|
public function addFlag($id, array $params = self::QUERY_PARAMS, $serialize = true) |
317
|
|
|
{ |
318
|
|
|
if (!$this->authentication instanceof Authentication) { |
319
|
|
|
throw new \Exception('Authentication is required'); |
320
|
|
|
} |
321
|
|
|
$response = Http::instance()->put( |
322
|
|
|
self::URL . $id . '/flags/add', array_merge($params, $this->authentication->toArray()) |
323
|
|
|
); |
324
|
|
|
|
325
|
|
|
return $serialize === true ? AnswerSerializer::serialize($response) : $response; |
|
|
|
|
326
|
|
|
} |
327
|
|
|
|
328
|
|
|
/** |
329
|
|
|
* Gets the answers to a set of questions identified in id. |
330
|
|
|
* |
331
|
|
|
* More info: https://api.stackexchange.com/docs/answers-on-questions |
332
|
|
|
* |
333
|
|
|
* @param string|array $ids Array which contains the ids delimited by semicolon, or a simple id |
334
|
|
|
* @param array $params QueryString parameter(s) |
335
|
|
|
* @param bool $serialize Checks if the result will be serialize or not, by default is true |
336
|
|
|
* |
337
|
|
|
* @return array|Answer |
|
|
|
|
338
|
|
|
*/ |
339
|
|
|
public function getOfQuestionIds($ids, array $params = ['site' => 'stackoverflow'], $serialize = true) |
340
|
|
|
{ |
341
|
|
|
if ($this->authentication instanceof Authentication) { |
342
|
|
|
if (true === empty($params)) { |
343
|
|
|
$params = array_merge($params, self::QUERY_PARAMS); |
344
|
|
|
} |
345
|
|
|
$params = array_merge($params, $this->authentication->toArray()); |
346
|
|
|
} |
347
|
|
|
$response = Http::instance()->get( |
348
|
|
|
'questions/' . (is_array($ids) ? implode(';', $ids) : $ids) . self::URL, $params |
349
|
|
|
); |
350
|
|
|
|
351
|
|
|
return $serialize === true ? AnswerSerializer::serialize($response) : $response; |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* Create a new answer on the given question. |
356
|
|
|
* |
357
|
|
|
* More info: https://api.stackexchange.com/docs/create-answer |
358
|
|
|
* |
359
|
|
|
* @param string $id The id of question |
360
|
|
|
* @param string $body The body of the answer |
361
|
|
|
* @param array $params QueryString parameter(s) |
362
|
|
|
* @param bool $serialize Checks if the result will be serialize or not, by default is true |
363
|
|
|
* |
364
|
|
|
* @throws \Exception when the auth is null |
365
|
|
|
* |
366
|
|
|
* @return Answer |
367
|
|
|
*/ |
368
|
|
View Code Duplication |
public function addOfQuestionId($id, $body, array $params = self::QUERY_PARAMS, $serialize = true) |
|
|
|
|
369
|
|
|
{ |
370
|
|
|
if (!$this->authentication instanceof Authentication) { |
371
|
|
|
throw new \Exception('Authentication is required'); |
372
|
|
|
} |
373
|
|
|
$response = Http::instance()->post( |
374
|
|
|
'questions/' . $id . '/' . self::URL . 'add', array_merge( |
375
|
|
|
['body' => $body], $params, $this->authentication->toArray() |
376
|
|
|
) |
377
|
|
|
); |
378
|
|
|
|
379
|
|
|
return $serialize === true ? AnswerSerializer::serialize($response) : $response; |
|
|
|
|
380
|
|
|
} |
381
|
|
|
|
382
|
|
|
/** |
383
|
|
|
* Render an answer given it's body and the question it's on. |
384
|
|
|
* |
385
|
|
|
* More info: https://api.stackexchange.com/docs/render-answer |
386
|
|
|
* |
387
|
|
|
* @param string $id The id of question |
388
|
|
|
* @param string $body The body of the answer |
389
|
|
|
* @param array $params QueryString parameter(s) |
390
|
|
|
* @param bool $serialize Checks if the result will be serialize or not, by default is true |
391
|
|
|
* |
392
|
|
|
* @throws \Exception when the auth is null |
393
|
|
|
* |
394
|
|
|
* @return Answer |
395
|
|
|
*/ |
396
|
|
|
public function render($id, $body, array $params = ['site' => 'stackoverflow'], $serialize = true) |
397
|
|
|
{ |
398
|
|
|
if ($this->authentication instanceof Authentication) { |
399
|
|
|
if (true === empty($params)) { |
400
|
|
|
$params = array_merge($params, self::QUERY_PARAMS); |
401
|
|
|
} |
402
|
|
|
$params = array_merge($params, $this->authentication->toArray()); |
403
|
|
|
} |
404
|
|
|
$response = Http::instance()->post( |
405
|
|
|
'questions/' . $id . '/' . self::URL . 'render', array_merge( |
406
|
|
|
['body' => $body], $params, $this->authentication->toArray() |
407
|
|
|
) |
408
|
|
|
); |
409
|
|
|
|
410
|
|
|
return $serialize === true ? AnswerSerializer::serialize($response) : $response; |
|
|
|
|
411
|
|
|
} |
412
|
|
|
|
413
|
|
|
/** |
414
|
|
|
* Returns the answers the users in {ids} have posted. |
415
|
|
|
* |
416
|
|
|
* More info: https://api.stackexchange.com/docs/answers-on-users |
417
|
|
|
* |
418
|
|
|
* @param string|array $ids Array which contains the ids delimited by semicolon, or a simple id |
419
|
|
|
* @param array $params QueryString parameter(s) |
420
|
|
|
* @param bool $serialize Checks if the result will be serialize or not, by default is true |
421
|
|
|
* |
422
|
|
|
* @return array|Answer |
|
|
|
|
423
|
|
|
*/ |
424
|
|
View Code Duplication |
public function getOfUserIds($ids, array $params = ['site' => 'stackoverflow'], $serialize = true) |
|
|
|
|
425
|
|
|
{ |
426
|
|
|
if ($this->authentication instanceof Authentication) { |
427
|
|
|
if (true === empty($params)) { |
428
|
|
|
$params = array_merge($params, self::QUERY_PARAMS); |
429
|
|
|
} |
430
|
|
|
$params = array_merge($params, $this->authentication->toArray()); |
431
|
|
|
} |
432
|
|
|
$response = Http::instance()->get( |
433
|
|
|
'users/' . (is_array($ids) ? implode(';', $ids) : $ids) . '/' . self::URL, $params |
434
|
|
|
); |
435
|
|
|
|
436
|
|
|
return $serialize === true ? AnswerSerializer::serialize($response) : $response; |
437
|
|
|
} |
438
|
|
|
|
439
|
|
|
/** |
440
|
|
|
* Returns the answers owned by the user associated with the given access_token. |
441
|
|
|
* |
442
|
|
|
* More info: https://api.stackexchange.com/docs/me-answers |
443
|
|
|
* |
444
|
|
|
* @param array $params QueryString parameter(s) |
445
|
|
|
* @param bool $serialize Checks if the result will be serialize or not, by default is true |
446
|
|
|
* |
447
|
|
|
* @throws \Exception when the auth is null |
448
|
|
|
* |
449
|
|
|
* @return array|Answer |
|
|
|
|
450
|
|
|
*/ |
451
|
|
View Code Duplication |
public function myAnswers(array $params = self::QUERY_PARAMS, $serialize = true) |
|
|
|
|
452
|
|
|
{ |
453
|
|
|
if (!$this->authentication instanceof Authentication) { |
454
|
|
|
throw new \Exception('Authentication is required'); |
455
|
|
|
} |
456
|
|
|
$response = Http::instance()->get( |
457
|
|
|
'me/' . self::URL, array_merge($params, $this->authentication->toArray()) |
458
|
|
|
); |
459
|
|
|
|
460
|
|
|
return $serialize === true ? AnswerSerializer::serialize($response) : $response; |
461
|
|
|
} |
462
|
|
|
|
463
|
|
|
/** |
464
|
|
|
* Returns the top 30 answers a user has posted in response to questions with the given tags. |
465
|
|
|
* |
466
|
|
|
* More info: https://api.stackexchange.com/docs/top-user-answers-in-tags |
467
|
|
|
* |
468
|
|
|
* @param string $userId The user id |
469
|
|
|
* @param string|array $tags Array which contains the $tags delimited by semicolon, or a simple tag |
470
|
|
|
* @param array $params QueryString parameter(s) |
471
|
|
|
* @param bool $serialize Checks if the result will be serialize or not, by default is true |
472
|
|
|
* |
473
|
|
|
* @return array|Answer |
|
|
|
|
474
|
|
|
*/ |
475
|
|
View Code Duplication |
public function getTopOfUserAndTags($userId, $tags, array $params = ['site' => 'stackoverflow'], $serialize = true) |
|
|
|
|
476
|
|
|
{ |
477
|
|
|
if ($this->authentication instanceof Authentication) { |
478
|
|
|
if (true === empty($params)) { |
479
|
|
|
$params = array_merge($params, self::QUERY_PARAMS); |
480
|
|
|
} |
481
|
|
|
$params = array_merge($params, $this->authentication->toArray()); |
482
|
|
|
} |
483
|
|
|
$response = Http::instance()->get( |
484
|
|
|
'users/' . $userId . '/tags/' . (is_array($tags) ? implode(';', $tags) : $tags) . '/top-' . self::URL, $params |
|
|
|
|
485
|
|
|
); |
486
|
|
|
|
487
|
|
|
return $serialize === true ? AnswerSerializer::serialize($response) : $response; |
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
/** |
491
|
|
|
* Returns the top 30 answers the user associated with the given |
492
|
|
|
* access_token has posted in response to questions with the given tags. |
493
|
|
|
* |
494
|
|
|
* More info: https://api.stackexchange.com/docs/me-tags-top-answers |
495
|
|
|
* |
496
|
|
|
* @param string|array $tags Array which contains the tags delimited by semicolon, or a simple tag |
497
|
|
|
* @param array $params QueryString parameter(s) |
498
|
|
|
* @param bool $serialize Checks if the result will be serialize or not, by default is true |
499
|
|
|
* |
500
|
|
|
* @throws \Exception when the auth is null |
501
|
|
|
* |
502
|
|
|
* @return array|Answer |
|
|
|
|
503
|
|
|
*/ |
504
|
|
|
public function myTopAnswersOfTags($tags, array $params = self::QUERY_PARAMS, $serialize = true) |
505
|
|
|
{ |
506
|
|
|
if (!$this->authentication instanceof Authentication) { |
507
|
|
|
throw new \Exception('Authentication is required'); |
508
|
|
|
} |
509
|
|
|
$response = Http::instance()->get( |
510
|
|
|
'me/tags/' . (is_array($tags) ? implode(';', $tags) : $tags) . '/top-' . self::URL, |
511
|
|
|
array_merge($params, $this->authentication->toArray()) |
512
|
|
|
); |
513
|
|
|
|
514
|
|
|
return $serialize === true ? AnswerSerializer::serialize($response) : $response; |
515
|
|
|
} |
516
|
|
|
} |
517
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.If the return type contains the type array, this check recommends the use of a more specific type like
String[]
orarray<String>
.