Completed
Push — v2 ( 6101cd...f8a429 )
by Beñat
02:32
created

AnswerApi::accept()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 11
rs 9.4286
cc 3
eloc 6
nc 3
nop 3
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
0 ignored issues
show
Documentation introduced by
Should the return type not be array|\BenatEspina\Stack...geApiClient\Model\Model? Also, consider making the array more specific, something like array<String>, or String[].

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[] or array<String>.

Loading history...
60
     */
61
    public function all($params = self::QUERY_PARAMS, $serialize = true)
62
    {
63
        $response = Http::instance()->get(
64
            self::URL, $params
65
        );
66
67
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
68
    }
69
70
    /**
71
     * Get answers identified by a set of ids.
72
     *
73
     * More info: http://api.stackexchange.com/docs/answers-by-ids
74
     *
75
     * @param string|array $ids       Array which contains the ids delimited by semicolon, or a simple id
76
     * @param array        $params    QueryString parameter(s)
77
     * @param bool         $serialize Checks if the result will be serialize or not, by default is true
78
     *
79
     * @return array|Answer
0 ignored issues
show
Documentation introduced by
Should the return type not be array|\BenatEspina\Stack...geApiClient\Model\Model? Also, consider making the array more specific, something like array<String>, or String[].

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[] or array<String>.

Loading history...
80
     */
81 View Code Duplication
    public function getOfIds($ids, array $params = self::QUERY_PARAMS, $serialize = true)
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...
82
    {
83
        $response = Http::instance()->get(
84
            self::URL . (is_array($ids) ? implode(';', $ids) : $ids), $params
85
        );
86
87
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
88
    }
89
90
    /**
91
     * Casts an accept vote on the given answer.
92
     *
93
     * More info: https://api.stackexchange.com/docs/accept-answer
94
     *
95
     * @param string $id        The id of question
96
     * @param array  $params    QueryString parameter(s)
97
     * @param bool   $serialize Checks if the result will be serialize or not, by default is true
98
     *
99
     * @throws \Exception when the auth is null
100
     *
101
     * @return Answer
102
     */
103
    public function accept($id, array $params = self::QUERY_PARAMS, $serialize = true)
104
    {
105
        if (!$this->authentication instanceof Authentication) {
106
            throw new \Exception('Authentication is required');
107
        }
108
        $response = Http::instance()->put(
109
            self::URL . $id . '/accept', array_merge($params, $this->authentication->toArray())
110
        );
111
112
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
0 ignored issues
show
Bug Compatibility introduced by
The expression $serialize === true ? \B...$response) : $response; of type array|BenatEspina\StackE...geApiClient\Model\Model adds the type array to the return on line 112 which is incompatible with the return type documented by BenatEspina\StackExchang...t\Api\AnswerApi::accept of type BenatEspina\StackExchangeApiClient\Model\Answer.
Loading history...
113
    }
114
115
    /**
116
     * Undoes an accept vote on the given answer.
117
     *
118
     * More info: https://api.stackexchange.com/docs/undo-accept-answer
119
     *
120
     * @param string $id        The id of question
121
     * @param array  $params    QueryString parameter(s)
122
     * @param bool   $serialize Checks if the result will be serialize or not, by default is true
123
     *
124
     * @throws \Exception when the auth is null
125
     *
126
     * @return Answer
127
     */
128
    public function undoAccept($id, array $params = self::QUERY_PARAMS, $serialize = true)
129
    {
130
        if (!$this->authentication instanceof Authentication) {
131
            throw new \Exception('Authentication is required');
132
        }
133
        $response = Http::instance()->put(
134
            self::URL . $id . '/accept/undo', array_merge($params, $this->authentication->toArray())
135
        );
136
137
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
0 ignored issues
show
Bug Compatibility introduced by
The expression $serialize === true ? \B...$response) : $response; of type array|BenatEspina\StackE...geApiClient\Model\Model adds the type array to the return on line 137 which is incompatible with the return type documented by BenatEspina\StackExchang...i\AnswerApi::undoAccept of type BenatEspina\StackExchangeApiClient\Model\Answer.
Loading history...
138
    }
139
140
    /**
141
     * Deletes an answer.
142
     *
143
     * More info: https://api.stackexchange.com/docs/delete-answer
144
     *
145
     * @param string $id        The id of question
146
     * @param array  $params    QueryString parameter(s)
147
     * @param bool   $serialize Checks if the result will be serialize or not, by default is true
148
     *
149
     * @throws \Exception when the auth is null
150
     *
151
     * @return Answer
152
     */
153
    public function delete($id, array $params = self::QUERY_PARAMS, $serialize = true)
154
    {
155
        if (!$this->authentication instanceof Authentication) {
156
            throw new \Exception('Authentication is required');
157
        }
158
        $response = Http::instance()->delete(
159
            self::URL . $id . '/delete', array_merge($params, $this->authentication->toArray())
160
        );
161
162
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
0 ignored issues
show
Bug Compatibility introduced by
The expression $serialize === true ? \B...$response) : $response; of type array|BenatEspina\StackE...geApiClient\Model\Model adds the type array to the return on line 162 which is incompatible with the return type documented by BenatEspina\StackExchang...t\Api\AnswerApi::delete of type BenatEspina\StackExchangeApiClient\Model\Answer.
Loading history...
163
    }
164
165
    /**
166
     * Downvotes an answer.
167
     *
168
     * More info: https://api.stackexchange.com/docs/downvote-answer
169
     *
170
     * @param string $id        The id of question
171
     * @param array  $params    QueryString parameter(s)
172
     * @param bool   $serialize Checks if the result will be serialize or not, by default is true
173
     *
174
     * @throws \Exception when the auth is null
175
     *
176
     * @return Answer
177
     */
178
    public function downvote($id, array $params = self::QUERY_PARAMS, $serialize = true)
179
    {
180
        if (!$this->authentication instanceof Authentication) {
181
            throw new \Exception('Authentication is required');
182
        }
183
        $response = Http::instance()->put(
184
            self::URL . $id . '/downvote', array_merge($params, $this->authentication->toArray())
185
        );
186
187
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
0 ignored issues
show
Bug Compatibility introduced by
The expression $serialize === true ? \B...$response) : $response; of type array|BenatEspina\StackE...geApiClient\Model\Model adds the type array to the return on line 187 which is incompatible with the return type documented by BenatEspina\StackExchang...Api\AnswerApi::downvote of type BenatEspina\StackExchangeApiClient\Model\Answer.
Loading history...
188
    }
189
190
    /**
191
     * Undoes an downvote on an answer.
192
     *
193
     * More info: https://api.stackexchange.com/docs/undo-downvote-answer
194
     *
195
     * @param string $id        The id of question
196
     * @param array  $params    QueryString parameter(s)
197
     * @param bool   $serialize Checks if the result will be serialize or not, by default is true
198
     *
199
     * @throws \Exception when the auth is null
200
     *
201
     * @return Answer
202
     */
203
    public function undoDownvote($id, array $params = self::QUERY_PARAMS, $serialize = true)
204
    {
205
        if (!$this->authentication instanceof Authentication) {
206
            throw new \Exception('Authentication is required');
207
        }
208
        $response = Http::instance()->put(
209
            self::URL . $id . '/downvote/undo', array_merge($params, $this->authentication->toArray())
210
        );
211
212
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
0 ignored issues
show
Bug Compatibility introduced by
The expression $serialize === true ? \B...$response) : $response; of type array|BenatEspina\StackE...geApiClient\Model\Model adds the type array to the return on line 212 which is incompatible with the return type documented by BenatEspina\StackExchang...AnswerApi::undoDownvote of type BenatEspina\StackExchangeApiClient\Model\Answer.
Loading history...
213
    }
214
215
    /**
216
     * Edit an existing answer.
217
     *
218
     * More info: https://api.stackexchange.com/docs/edit-answer
219
     *
220
     * @param string $id        The id of question
221
     * @param string $body      The body of the answer
222
     * @param array  $params    QueryString parameter(s)
223
     * @param bool   $serialize Checks if the result will be serialize or not, by default is true
224
     *
225
     * @throws \Exception when the auth is null
226
     *
227
     * @return Answer
228
     */
229 View Code Duplication
    public function update($id, $body, array $params = self::QUERY_PARAMS, $serialize = true)
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...
230
    {
231
        if (!$this->authentication instanceof Authentication) {
232
            throw new \Exception('Authentication is required');
233
        }
234
        $response = Http::instance()->put(
235
            self::URL . $id . '/edit', array_merge(['body' => $body], $params, $this->authentication->toArray())
236
        );
237
238
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
0 ignored issues
show
Bug Compatibility introduced by
The expression $serialize === true ? \B...$response) : $response; of type array|BenatEspina\StackE...geApiClient\Model\Model adds the type array to the return on line 238 which is incompatible with the return type documented by BenatEspina\StackExchang...t\Api\AnswerApi::update of type BenatEspina\StackExchangeApiClient\Model\Answer.
Loading history...
239
    }
240
241
    /**
242
     * Upvotes an answer.
243
     *
244
     * More info: https://api.stackexchange.com/docs/upvote-answer
245
     *
246
     * @param string $id        The id of question
247
     * @param array  $params    QueryString parameter(s)
248
     * @param bool   $serialize Checks if the result will be serialize or not, by default is true
249
     *
250
     * @throws \Exception when the auth is null
251
     *
252
     * @return Answer
253
     */
254
    public function upvote($id, array $params = self::QUERY_PARAMS, $serialize = true)
255
    {
256
        if (!$this->authentication instanceof Authentication) {
257
            throw new \Exception('Authentication is required');
258
        }
259
        $response = Http::instance()->put(
260
            self::URL . $id . '/upvote', array_merge($params, $this->authentication->toArray())
261
        );
262
263
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
0 ignored issues
show
Bug Compatibility introduced by
The expression $serialize === true ? \B...$response) : $response; of type array|BenatEspina\StackE...geApiClient\Model\Model adds the type array to the return on line 263 which is incompatible with the return type documented by BenatEspina\StackExchang...t\Api\AnswerApi::upvote of type BenatEspina\StackExchangeApiClient\Model\Answer.
Loading history...
264
    }
265
266
    /**
267
     * Undoes an upvote on an answer.
268
     *
269
     * More info: https://api.stackexchange.com/docs/undo-upvote-answer
270
     *
271
     * @param string $id        The id of question
272
     * @param array  $params    QueryString parameter(s)
273
     * @param bool   $serialize Checks if the result will be serialize or not, by default is true
274
     *
275
     * @throws \Exception when the auth is null
276
     *
277
     * @return Answer
278
     */
279
    public function undoUpvote($id, array $params = self::QUERY_PARAMS, $serialize = true)
280
    {
281
        if (!$this->authentication instanceof Authentication) {
282
            throw new \Exception('Authentication is required');
283
        }
284
        $response = Http::instance()->put(
285
            self::URL . $id . '/upvote/undo', array_merge($params, $this->authentication->toArray())
286
        );
287
288
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
0 ignored issues
show
Bug Compatibility introduced by
The expression $serialize === true ? \B...$response) : $response; of type array|BenatEspina\StackE...geApiClient\Model\Model adds the type array to the return on line 288 which is incompatible with the return type documented by BenatEspina\StackExchang...i\AnswerApi::undoUpvote of type BenatEspina\StackExchangeApiClient\Model\Answer.
Loading history...
289
    }
290
291
    /**
292
     * Casts a flag against the answer identified by id.
293
     *
294
     * More info: https://api.stackexchange.com/docs/create-answer-flag
295
     *
296
     * @param string $id        The id of question
297
     * @param array  $params    QueryString parameter(s)
298
     * @param bool   $serialize Checks if the result will be serialize or not, by default is true
299
     *
300
     * @throws \Exception when the auth is null
301
     *
302
     * @return Answer
303
     */
304
    public function addFlag($id, array $params = self::QUERY_PARAMS, $serialize = true)
305
    {
306
        if (!$this->authentication instanceof Authentication) {
307
            throw new \Exception('Authentication is required');
308
        }
309
        $response = Http::instance()->put(
310
            self::URL . $id . '/flags/add', array_merge($params, $this->authentication->toArray())
311
        );
312
313
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
0 ignored issues
show
Bug Compatibility introduced by
The expression $serialize === true ? \B...$response) : $response; of type array|BenatEspina\StackE...geApiClient\Model\Model adds the type array to the return on line 313 which is incompatible with the return type documented by BenatEspina\StackExchang...\Api\AnswerApi::addFlag of type BenatEspina\StackExchangeApiClient\Model\Answer.
Loading history...
314
    }
315
316
    /**
317
     * Gets the answers to a set of questions identified in id.
318
     *
319
     * More info: https://api.stackexchange.com/docs/answers-on-questions
320
     *
321
     * @param string|array $ids       Array which contains the ids delimited by semicolon, or a simple id
322
     * @param array        $params    QueryString parameter(s)
323
     * @param bool         $serialize Checks if the result will be serialize or not, by default is true
324
     *
325
     * @return array|Answer
0 ignored issues
show
Documentation introduced by
Should the return type not be array|\BenatEspina\Stack...geApiClient\Model\Model? Also, consider making the array more specific, something like array<String>, or String[].

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[] or array<String>.

Loading history...
326
     */
327 View Code Duplication
    public function getOfQuestionIds($ids, array $params = self::QUERY_PARAMS, $serialize = true)
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...
328
    {
329
        $response = Http::instance()->get(
330
            'questions/' . (is_array($ids) ? implode(';', $ids) : $ids) . self::URL, $params
331
        );
332
333
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
334
    }
335
336
    /**
337
     * Create a new answer on the given question.
338
     *
339
     * More info: https://api.stackexchange.com/docs/create-answer
340
     *
341
     * @param string $id        The id of question
342
     * @param string $body      The body of the answer
343
     * @param array  $params    QueryString parameter(s)
344
     * @param bool   $serialize Checks if the result will be serialize or not, by default is true
345
     *
346
     * @throws \Exception when the auth is null
347
     *
348
     * @return Answer
349
     */
350 View Code Duplication
    public function addOfQuestionId($id, $body, array $params = self::QUERY_PARAMS, $serialize = true)
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...
351
    {
352
        if (!$this->authentication instanceof Authentication) {
353
            throw new \Exception('Authentication is required');
354
        }
355
        $response = Http::instance()->post(
356
            'questions/' . $id . '/' . self::URL . 'add', array_merge(
357
                ['body' => $body], $params, $this->authentication->toArray()
358
            )
359
        );
360
361
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
0 ignored issues
show
Bug Compatibility introduced by
The expression $serialize === true ? \B...$response) : $response; of type array|BenatEspina\StackE...geApiClient\Model\Model adds the type array to the return on line 361 which is incompatible with the return type documented by BenatEspina\StackExchang...werApi::addOfQuestionId of type BenatEspina\StackExchangeApiClient\Model\Answer.
Loading history...
362
    }
363
364
    /**
365
     * Render an answer given it's body and the question it's on.
366
     *
367
     * More info: https://api.stackexchange.com/docs/render-answer
368
     *
369
     * @param string $id        The id of question
370
     * @param string $body      The body of the answer
371
     * @param array  $params    QueryString parameter(s)
372
     * @param bool   $serialize Checks if the result will be serialize or not, by default is true
373
     *
374
     * @throws \Exception when the auth is null
375
     *
376
     * @return Answer
377
     */
378
    public function render($id, $body, array $params = self::QUERY_PARAMS, $serialize = true)
379
    {
380
        $response = Http::instance()->post(
381
            'questions/' . $id . '/' . self::URL . 'render', array_merge(
382
                ['body' => $body], $params, $this->authentication->toArray()
383
            )
384
        );
385
386
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
0 ignored issues
show
Bug Compatibility introduced by
The expression $serialize === true ? \B...$response) : $response; of type array|BenatEspina\StackE...geApiClient\Model\Model adds the type array to the return on line 386 which is incompatible with the return type documented by BenatEspina\StackExchang...t\Api\AnswerApi::render of type BenatEspina\StackExchangeApiClient\Model\Answer.
Loading history...
387
    }
388
389
    /**
390
     * Returns the answers the users in {ids} have posted.
391
     *
392
     * More info: https://api.stackexchange.com/docs/answers-on-users
393
     *
394
     * @param string|array $ids       Array which contains the ids delimited by semicolon, or a simple id
395
     * @param array        $params    QueryString parameter(s)
396
     * @param bool         $serialize Checks if the result will be serialize or not, by default is true
397
     *
398
     * @return array|Answer
0 ignored issues
show
Documentation introduced by
Should the return type not be array|\BenatEspina\Stack...geApiClient\Model\Model? Also, consider making the array more specific, something like array<String>, or String[].

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[] or array<String>.

Loading history...
399
     */
400 View Code Duplication
    public function getOfUserIds($ids, array $params = self::QUERY_PARAMS, $serialize = true)
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...
401
    {
402
        $response = Http::instance()->get(
403
            'users/' . (is_array($ids) ? implode(';', $ids) : $ids) . '/' . self::URL, $params
404
        );
405
406
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
407
    }
408
409
    /**
410
     * Returns the answers owned by the user associated with the given access_token.
411
     *
412
     * More info: https://api.stackexchange.com/docs/me-answers
413
     *
414
     * @param array $params    QueryString parameter(s)
415
     * @param bool  $serialize Checks if the result will be serialize or not, by default is true
416
     *
417
     * @throws \Exception when the auth is null
418
     *
419
     * @return array|Answer
0 ignored issues
show
Documentation introduced by
Should the return type not be array|\BenatEspina\Stack...geApiClient\Model\Model? Also, consider making the array more specific, something like array<String>, or String[].

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[] or array<String>.

Loading history...
420
     */
421 View Code Duplication
    public function myAnswers(array $params = self::QUERY_PARAMS, $serialize = true)
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...
422
    {
423
        if (!$this->authentication instanceof Authentication) {
424
            throw new \Exception('Authentication is required');
425
        }
426
        $response = Http::instance()->get(
427
            'me/' . self::URL, array_merge($params, ['access_token' => $this->authentication->accessToken()])
428
        );
429
430
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
431
    }
432
433
    /**
434
     * Returns the top 30 answers a user has posted in response to questions with the given tags.
435
     *
436
     * More info: https://api.stackexchange.com/docs/top-user-answers-in-tags
437
     *
438
     * @param string       $userId    The user id
439
     * @param string|array $tags      Array which contains the $tags delimited by semicolon, or a simple tag
440
     * @param array        $params    QueryString parameter(s)
441
     * @param bool         $serialize Checks if the result will be serialize or not, by default is true
442
     *
443
     * @return array|Answer
0 ignored issues
show
Documentation introduced by
Should the return type not be array|\BenatEspina\Stack...geApiClient\Model\Model? Also, consider making the array more specific, something like array<String>, or String[].

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[] or array<String>.

Loading history...
444
     */
445 View Code Duplication
    public function getTopOfUserAndTags($userId, $tags, array $params = self::QUERY_PARAMS, $serialize = true)
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...
446
    {
447
        $response = Http::instance()->get(
448
            'users/' . $userId . '/tags/' . (is_array($tags) ? implode(';', $tags) : $tags) . '/top-' . self::URL, $params
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 122 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
449
        );
450
451
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
452
    }
453
454
    /**
455
     * Returns the top 30 answers the user associated with the given
456
     * access_token has posted in response to questions with the given tags.
457
     *
458
     * More info: https://api.stackexchange.com/docs/me-tags-top-answers
459
     *
460
     * @param string|array $tags      Array which contains the tags delimited by semicolon, or a simple tag
461
     * @param array        $params    QueryString parameter(s)
462
     * @param bool         $serialize Checks if the result will be serialize or not, by default is true
463
     *
464
     * @throws \Exception when the auth is null
465
     *
466
     * @return array|Answer
0 ignored issues
show
Documentation introduced by
Should the return type not be array|\BenatEspina\Stack...geApiClient\Model\Model? Also, consider making the array more specific, something like array<String>, or String[].

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[] or array<String>.

Loading history...
467
     */
468
    public function myTopAnswersOfTags($tags, array $params = self::QUERY_PARAMS, $serialize = true)
469
    {
470
        if (!$this->authentication instanceof Authentication) {
471
            throw new \Exception('Authentication is required');
472
        }
473
        $response = Http::instance()->get(
474
            'me/tags/' . (is_array($tags) ? implode(';', $tags) : $tags) . '/top-' . self::URL,
475
            array_merge($params, ['access_token' => $this->authentication->accessToken()])
476
        );
477
478
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
479
    }
480
}
481