Completed
Push — master ( f5580e...4e6c29 )
by Beñat
01:39
created

UndoUpvoteAnswer   C

Complexity

Total Complexity 66

Size/Duplication

Total Lines 493
Duplicated Lines 13.39 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 66
lcom 1
cbo 1
dl 66
loc 493
rs 5.7474
c 0
b 0
f 0

19 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A all() 14 14 4
B getOfIds() 0 14 5
A update() 11 11 3
B getOfQuestionIds() 0 14 5
A addOfQuestionId() 13 13 3
A render() 0 16 4
B getOfUserIds() 14 14 5
B getTopOfUserAndTags() 14 14 5
A myTopAnswersOfTags() 0 12 4
A accept() 0 11 3
A undoAccept() 0 11 3
A delete() 0 11 3
A downvote() 0 11 3
A undoDownvote() 0 11 3
A upvote() 0 11 3
A undoUpvote() 0 11 3
A addFlag() 0 11 3
A myAnswers() 0 11 3

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like UndoUpvoteAnswer often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use UndoUpvoteAnswer, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/*
4
 * This file is part of the Stack Exchange Api Client library.
5
 *
6
 * (c) 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
declare(strict_types=1);
13
/*
14
 * This file is part of the Stack Exchange Api Client library.
15
 *
16
 * (c) Beñat Espiña <[email protected]>
17
 *
18
 * For the full copyright and license information, please view the LICENSE
19
 * file that was distributed with this source code.
20
 */
21
22
namespace BenatEspina\StackExchangeApiClient\Api;
23
24
use BenatEspina\StackExchangeApiClient\Authentication\Authentication;
25
use BenatEspina\StackExchangeApiClient\Http\HttpClient;
26
use BenatEspina\StackExchangeApiClient\Model\Answer;
27
use BenatEspina\StackExchangeApiClient\Serializer\AnswerSerializer;
28
29
/**
30
 * The answer api class.
31
 *
32
 * @author Beñat Espiña <[email protected]>
33
 */
34
final class UndoUpvoteAnswer
35
{
36
    const URL = 'answers/';
37
    const QUERY_PARAMS = [
38
        'order'  => 'desc',
39
        'sort'   => 'activity',
40
        'site'   => 'stackoverflow',
41
        'filter' => HttpClient::FILTER_ALL,
42
    ];
43
44
    /**
45
     * The authentication.
46
     *
47
     * @var Authentication|null
48
     */
49
    private $authentication;
50
51
    /**
52
     * Constructor.
53
     *
54
     * @param Authentication|null $anAuthentication The authentication
55
     */
56
    public function __construct(Authentication $anAuthentication = null)
57
    {
58
        $this->authentication = $anAuthentication;
59
    }
60
61
    /**
62
     * Get all answers on the site.
63
     *
64
     * More info: http://api.stackexchange.com/docs/answers
65
     *
66
     * @param array $params    QueryString parameter(s)
67
     * @param bool  $serialize Checks if the result will be serialize or not, by default is true
68
     *
69
     * @return array
70
     */
71 View Code Duplication
    public function all(array $params = ['site' => 'stackoverflow'], $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...
72
    {
73
        if ($this->authentication instanceof Authentication) {
74
            if (true === empty($params)) {
75
                $params = array_merge($params, self::QUERY_PARAMS);
76
            }
77
            $params = array_merge($params, $this->authentication->toArray());
78
        }
79
        $response = HttpClient::instance()->get(
0 ignored issues
show
Bug introduced by
The method instance() does not seem to exist on object<BenatEspina\Stack...Client\Http\HttpClient>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
80
            self::URL, $params
81
        );
82
83
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
84
    }
85
86
    /**
87
     * Get answers identified by a set of ids.
88
     *
89
     * More info: http://api.stackexchange.com/docs/answers-by-ids
90
     *
91
     * @param string|array $ids       Array which contains the ids delimited by semicolon, or a simple id
92
     * @param array        $params    QueryString parameter(s)
93
     * @param bool         $serialize Checks if the result will be serialize or not, by default is true
94
     *
95
     * @return array|Answer
96
     */
97
    public function getOfIds($ids, array $params = ['site' => 'stackoverflow'], $serialize = true)
98
    {
99
        if ($this->authentication instanceof Authentication) {
100
            if (true === empty($params)) {
101
                $params = array_merge($params, self::QUERY_PARAMS);
102
            }
103
            $params = array_merge($params, $this->authentication->toArray());
104
        }
105
        $response = HttpClient::instance()->get(
0 ignored issues
show
Bug introduced by
The method instance() does not seem to exist on object<BenatEspina\Stack...Client\Http\HttpClient>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
106
            self::URL . (is_array($ids) ? implode(';', $ids) : $ids), $params
107
        );
108
109
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
110
    }
111
112
    /**
113
     * Casts an accept vote on the given answer.
114
     *
115
     * More info: https://api.stackexchange.com/docs/accept-answer
116
     *
117
     * @param string $id        The id of question
118
     * @param array  $params    QueryString parameter(s)
119
     * @param bool   $serialize Checks if the result will be serialize or not, by default is true
120
     *
121
     * @throws \Exception when the auth is null
122
     *
123
     * @return Answer
124
     */
125
    public function accept($id, array $params = self::QUERY_PARAMS, $serialize = true)
126
    {
127
        if (!$this->authentication instanceof Authentication) {
128
            throw new \Exception('Authentication is required');
129
        }
130
        $response = HttpClient::instance()->put(
0 ignored issues
show
Bug introduced by
The method instance() does not seem to exist on object<BenatEspina\Stack...Client\Http\HttpClient>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
131
            self::URL . $id . '/accept', array_merge($params, $this->authentication->toArray())
132
        );
133
134
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
135
    }
136
137
    /**
138
     * Undoes an accept vote on the given answer.
139
     *
140
     * More info: https://api.stackexchange.com/docs/undo-accept-answer
141
     *
142
     * @param string $id        The id of question
143
     * @param array  $params    QueryString parameter(s)
144
     * @param bool   $serialize Checks if the result will be serialize or not, by default is true
145
     *
146
     * @throws \Exception when the auth is null
147
     *
148
     * @return Answer
149
     */
150
    public function undoAccept($id, array $params = self::QUERY_PARAMS, $serialize = true)
151
    {
152
        if (!$this->authentication instanceof Authentication) {
153
            throw new \Exception('Authentication is required');
154
        }
155
        $response = HttpClient::instance()->put(
0 ignored issues
show
Bug introduced by
The method instance() does not seem to exist on object<BenatEspina\Stack...Client\Http\HttpClient>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
156
            self::URL . $id . '/accept/undo', array_merge($params, $this->authentication->toArray())
157
        );
158
159
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
160
    }
161
162
    /**
163
     * Deletes an answer.
164
     *
165
     * More info: https://api.stackexchange.com/docs/delete-answer
166
     *
167
     * @param string $id        The id of question
168
     * @param array  $params    QueryString parameter(s)
169
     * @param bool   $serialize Checks if the result will be serialize or not, by default is true
170
     *
171
     * @throws \Exception when the auth is null
172
     *
173
     * @return Answer
174
     */
175
    public function delete($id, array $params = self::QUERY_PARAMS, $serialize = true)
176
    {
177
        if (!$this->authentication instanceof Authentication) {
178
            throw new \Exception('Authentication is required');
179
        }
180
        $response = HttpClient::instance()->delete(
0 ignored issues
show
Bug introduced by
The method instance() does not seem to exist on object<BenatEspina\Stack...Client\Http\HttpClient>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
181
            self::URL . $id . '/delete', array_merge($params, $this->authentication->toArray())
182
        );
183
184
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
185
    }
186
187
    /**
188
     * Downvotes an answer.
189
     *
190
     * More info: https://api.stackexchange.com/docs/downvote-answer
191
     *
192
     * @param string $id        The id of question
193
     * @param array  $params    QueryString parameter(s)
194
     * @param bool   $serialize Checks if the result will be serialize or not, by default is true
195
     *
196
     * @throws \Exception when the auth is null
197
     *
198
     * @return Answer
199
     */
200
    public function downvote($id, array $params = self::QUERY_PARAMS, $serialize = true)
201
    {
202
        if (!$this->authentication instanceof Authentication) {
203
            throw new \Exception('Authentication is required');
204
        }
205
        $response = HttpClient::instance()->put(
0 ignored issues
show
Bug introduced by
The method instance() does not seem to exist on object<BenatEspina\Stack...Client\Http\HttpClient>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
206
            self::URL . $id . '/downvote', array_merge($params, $this->authentication->toArray())
207
        );
208
209
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
210
    }
211
212
    /**
213
     * Undoes an downvote on an answer.
214
     *
215
     * More info: https://api.stackexchange.com/docs/undo-downvote-answer
216
     *
217
     * @param string $id        The id of question
218
     * @param array  $params    QueryString parameter(s)
219
     * @param bool   $serialize Checks if the result will be serialize or not, by default is true
220
     *
221
     * @throws \Exception when the auth is null
222
     *
223
     * @return Answer
224
     */
225
    public function undoDownvote($id, array $params = self::QUERY_PARAMS, $serialize = true)
226
    {
227
        if (!$this->authentication instanceof Authentication) {
228
            throw new \Exception('Authentication is required');
229
        }
230
        $response = HttpClient::instance()->put(
0 ignored issues
show
Bug introduced by
The method instance() does not seem to exist on object<BenatEspina\Stack...Client\Http\HttpClient>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
231
            self::URL . $id . '/downvote/undo', array_merge($params, $this->authentication->toArray())
232
        );
233
234
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
235
    }
236
237
    /**
238
     * Edit an existing answer.
239
     *
240
     * More info: https://api.stackexchange.com/docs/edit-answer
241
     *
242
     * @param string $id        The id of question
243
     * @param string $body      The body of the answer
244
     * @param array  $params    QueryString parameter(s)
245
     * @param bool   $serialize Checks if the result will be serialize or not, by default is true
246
     *
247
     * @throws \Exception when the auth is null
248
     *
249
     * @return Answer
250
     */
251 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...
252
    {
253
        if (!$this->authentication instanceof Authentication) {
254
            throw new \Exception('Authentication is required');
255
        }
256
        $response = HttpClient::instance()->put(
0 ignored issues
show
Bug introduced by
The method instance() does not seem to exist on object<BenatEspina\Stack...Client\Http\HttpClient>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
257
            self::URL . $id . '/edit', array_merge(['body' => $body], $params, $this->authentication->toArray())
258
        );
259
260
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
261
    }
262
263
    /**
264
     * Upvotes an answer.
265
     *
266
     * More info: https://api.stackexchange.com/docs/upvote-answer
267
     *
268
     * @param string $id        The id of question
269
     * @param array  $params    QueryString parameter(s)
270
     * @param bool   $serialize Checks if the result will be serialize or not, by default is true
271
     *
272
     * @throws \Exception when the auth is null
273
     *
274
     * @return Answer
275
     */
276
    public function upvote($id, array $params = self::QUERY_PARAMS, $serialize = true)
277
    {
278
        if (!$this->authentication instanceof Authentication) {
279
            throw new \Exception('Authentication is required');
280
        }
281
        $response = HttpClient::instance()->put(
0 ignored issues
show
Bug introduced by
The method instance() does not seem to exist on object<BenatEspina\Stack...Client\Http\HttpClient>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
282
            self::URL . $id . '/upvote', array_merge($params, $this->authentication->toArray())
283
        );
284
285
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
286
    }
287
288
    /**
289
     * Undoes an upvote on an answer.
290
     *
291
     * More info: https://api.stackexchange.com/docs/undo-upvote-answer
292
     *
293
     * @param string $id        The id of question
294
     * @param array  $params    QueryString parameter(s)
295
     * @param bool   $serialize Checks if the result will be serialize or not, by default is true
296
     *
297
     * @throws \Exception when the auth is null
298
     *
299
     * @return Answer
300
     */
301
    public function undoUpvote($id, array $params = self::QUERY_PARAMS, $serialize = true)
302
    {
303
        if (!$this->authentication instanceof Authentication) {
304
            throw new \Exception('Authentication is required');
305
        }
306
        $response = HttpClient::instance()->put(
0 ignored issues
show
Bug introduced by
The method instance() does not seem to exist on object<BenatEspina\Stack...Client\Http\HttpClient>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
307
            self::URL . $id . '/upvote/undo', array_merge($params, $this->authentication->toArray())
308
        );
309
310
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
311
    }
312
313
    /**
314
     * Casts a flag against the answer identified by id.
315
     *
316
     * More info: https://api.stackexchange.com/docs/create-answer-flag
317
     *
318
     * @param string $id        The id of question
319
     * @param array  $params    QueryString parameter(s)
320
     * @param bool   $serialize Checks if the result will be serialize or not, by default is true
321
     *
322
     * @throws \Exception when the auth is null
323
     *
324
     * @return Answer
325
     */
326
    public function addFlag($id, array $params = self::QUERY_PARAMS, $serialize = true)
327
    {
328
        if (!$this->authentication instanceof Authentication) {
329
            throw new \Exception('Authentication is required');
330
        }
331
        $response = HttpClient::instance()->put(
0 ignored issues
show
Bug introduced by
The method instance() does not seem to exist on object<BenatEspina\Stack...Client\Http\HttpClient>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
332
            self::URL . $id . '/flags/add', array_merge($params, $this->authentication->toArray())
333
        );
334
335
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
336
    }
337
338
    /**
339
     * Gets the answers to a set of questions identified in id.
340
     *
341
     * More info: https://api.stackexchange.com/docs/answers-on-questions
342
     *
343
     * @param string|array $ids       Array which contains the ids delimited by semicolon, or a simple id
344
     * @param array        $params    QueryString parameter(s)
345
     * @param bool         $serialize Checks if the result will be serialize or not, by default is true
346
     *
347
     * @return array|Answer
348
     */
349
    public function getOfQuestionIds($ids, array $params = ['site' => 'stackoverflow'], $serialize = true)
350
    {
351
        if ($this->authentication instanceof Authentication) {
352
            if (true === empty($params)) {
353
                $params = array_merge($params, self::QUERY_PARAMS);
354
            }
355
            $params = array_merge($params, $this->authentication->toArray());
356
        }
357
        $response = HttpClient::instance()->get(
0 ignored issues
show
Bug introduced by
The method instance() does not seem to exist on object<BenatEspina\Stack...Client\Http\HttpClient>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
358
            'questions/' . (is_array($ids) ? implode(';', $ids) : $ids) . self::URL, $params
359
        );
360
361
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
362
    }
363
364
    /**
365
     * Create a new answer on the given question.
366
     *
367
     * More info: https://api.stackexchange.com/docs/create-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 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...
379
    {
380
        if (!$this->authentication instanceof Authentication) {
381
            throw new \Exception('Authentication is required');
382
        }
383
        $response = HttpClient::instance()->post(
0 ignored issues
show
Bug introduced by
The method instance() does not seem to exist on object<BenatEspina\Stack...Client\Http\HttpClient>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
384
            'questions/' . $id . '/' . self::URL . 'add', array_merge(
385
                ['body' => $body], $params, $this->authentication->toArray()
386
            )
387
        );
388
389
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
390
    }
391
392
    /**
393
     * Render an answer given it's body and the question it's on.
394
     *
395
     * More info: https://api.stackexchange.com/docs/render-answer
396
     *
397
     * @param string $id        The id of question
398
     * @param string $body      The body of the answer
399
     * @param array  $params    QueryString parameter(s)
400
     * @param bool   $serialize Checks if the result will be serialize or not, by default is true
401
     *
402
     * @throws \Exception when the auth is null
403
     *
404
     * @return Answer
405
     */
406
    public function render($id, $body, array $params = ['site' => 'stackoverflow'], $serialize = true)
407
    {
408
        if ($this->authentication instanceof Authentication) {
409
            if (true === empty($params)) {
410
                $params = array_merge($params, self::QUERY_PARAMS);
411
            }
412
            $params = array_merge($params, $this->authentication->toArray());
413
        }
414
        $response = HttpClient::instance()->post(
0 ignored issues
show
Bug introduced by
The method instance() does not seem to exist on object<BenatEspina\Stack...Client\Http\HttpClient>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
415
            'questions/' . $id . '/' . self::URL . 'render', array_merge(
416
                ['body' => $body], $params, $this->authentication->toArray()
417
            )
418
        );
419
420
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
421
    }
422
423
    /**
424
     * Returns the answers the users in {ids} have posted.
425
     *
426
     * More info: https://api.stackexchange.com/docs/answers-on-users
427
     *
428
     * @param string|array $ids       Array which contains the ids delimited by semicolon, or a simple id
429
     * @param array        $params    QueryString parameter(s)
430
     * @param bool         $serialize Checks if the result will be serialize or not, by default is true
431
     *
432
     * @return array|Answer
433
     */
434 View Code Duplication
    public function getOfUserIds($ids, array $params = ['site' => 'stackoverflow'], $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...
435
    {
436
        if ($this->authentication instanceof Authentication) {
437
            if (true === empty($params)) {
438
                $params = array_merge($params, self::QUERY_PARAMS);
439
            }
440
            $params = array_merge($params, $this->authentication->toArray());
441
        }
442
        $response = HttpClient::instance()->get(
0 ignored issues
show
Bug introduced by
The method instance() does not seem to exist on object<BenatEspina\Stack...Client\Http\HttpClient>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
443
            'users/' . (is_array($ids) ? implode(';', $ids) : $ids) . '/' . self::URL, $params
444
        );
445
446
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
447
    }
448
449
    /**
450
     * Returns the answers owned by the user associated with the given access_token.
451
     *
452
     * More info: https://api.stackexchange.com/docs/me-answers
453
     *
454
     * @param array $params    QueryString parameter(s)
455
     * @param bool  $serialize Checks if the result will be serialize or not, by default is true
456
     *
457
     * @throws \Exception when the auth is null
458
     *
459
     * @return array|Answer
460
     */
461
    public function myAnswers(array $params = self::QUERY_PARAMS, $serialize = true)
462
    {
463
        if (!$this->authentication instanceof Authentication) {
464
            throw new \Exception('Authentication is required');
465
        }
466
        $response = HttpClient::instance()->get(
0 ignored issues
show
Bug introduced by
The method instance() does not seem to exist on object<BenatEspina\Stack...Client\Http\HttpClient>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
467
            'me/' . self::URL, array_merge($params, $this->authentication->toArray())
468
        );
469
470
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
471
    }
472
473
    /**
474
     * Returns the top 30 answers a user has posted in response to questions with the given tags.
475
     *
476
     * More info: https://api.stackexchange.com/docs/top-user-answers-in-tags
477
     *
478
     * @param string       $userId    The user id
479
     * @param string|array $tags      Array which contains the $tags delimited by semicolon, or a simple tag
480
     * @param array        $params    QueryString parameter(s)
481
     * @param bool         $serialize Checks if the result will be serialize or not, by default is true
482
     *
483
     * @return array|Answer
484
     */
485 View Code Duplication
    public function getTopOfUserAndTags($userId, $tags, array $params = ['site' => 'stackoverflow'], $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...
486
    {
487
        if ($this->authentication instanceof Authentication) {
488
            if (true === empty($params)) {
489
                $params = array_merge($params, self::QUERY_PARAMS);
490
            }
491
            $params = array_merge($params, $this->authentication->toArray());
492
        }
493
        $response = HttpClient::instance()->get(
0 ignored issues
show
Bug introduced by
The method instance() does not seem to exist on object<BenatEspina\Stack...Client\Http\HttpClient>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
494
            '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...
495
        );
496
497
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
498
    }
499
500
    /**
501
     * Returns the top 30 answers the user associated with the given
502
     * access_token has posted in response to questions with the given tags.
503
     *
504
     * More info: https://api.stackexchange.com/docs/me-tags-top-answers
505
     *
506
     * @param string|array $tags      Array which contains the tags delimited by semicolon, or a simple tag
507
     * @param array        $params    QueryString parameter(s)
508
     * @param bool         $serialize Checks if the result will be serialize or not, by default is true
509
     *
510
     * @throws \Exception when the auth is null
511
     *
512
     * @return array|Answer
513
     */
514
    public function myTopAnswersOfTags($tags, array $params = self::QUERY_PARAMS, $serialize = true)
515
    {
516
        if (!$this->authentication instanceof Authentication) {
517
            throw new \Exception('Authentication is required');
518
        }
519
        $response = HttpClient::instance()->get(
0 ignored issues
show
Bug introduced by
The method instance() does not seem to exist on object<BenatEspina\Stack...Client\Http\HttpClient>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
520
            'me/tags/' . (is_array($tags) ? implode(';', $tags) : $tags) . '/top-' . self::URL,
521
            array_merge($params, $this->authentication->toArray())
522
        );
523
524
        return $serialize === true ? AnswerSerializer::serialize($response) : $response;
525
    }
526
}
527