Completed
Push — master ( 3f204e...7dc412 )
by Beñat
01:49
created

UndoAcceptAnswer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 35
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A __invoke() 0 9 1
A url() 0 4 1
A mergeAuthenticationIntoParameters() 0 4 1
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
namespace BenatEspina\StackExchangeApiClient\Api\Answer;
15
16
use BenatEspina\StackExchangeApiClient\Api\AnswerApi;
17
use BenatEspina\StackExchangeApiClient\Authentication\Authentication;
18
use BenatEspina\StackExchangeApiClient\Http\HttpClient;
19
use BenatEspina\StackExchangeApiClient\Serializer\Serializer;
20
21
/**
22
 * https://api.stackexchange.com/docs/undo-accept-answer.
23
 *
24
 * @author Beñat Espiña <[email protected]>
25
 */
26
class UndoAcceptAnswer
27
{
28
    private const URL = '/answers/{id}/accept/undo';
29
30
    private $client;
31
    private $serializer;
32
    private $authentication;
33
34
    public function __construct(HttpClient $client, Serializer $serializer, Authentication $authentication)
35
    {
36
        $this->client = $client;
37
        $this->serializer = $serializer;
38
        $this->authentication = $authentication;
39
    }
40
41
    public function __invoke(string $id, array $parameters = AnswerApi::QUERY_PARAMS)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
42
    {
43
        return $this->serializer->serialize(
44
            $this->client->put(
45
                $this->url($id),
46
                $this->mergeAuthenticationIntoParameters($parameters)
47
            )
48
        );
49
    }
50
51
    private function url(string $id) : string
52
    {
53
        return str_replace('{id}', $id, self::URL);
54
    }
55
56
    private function mergeAuthenticationIntoParameters(array $parameters) : array
57
    {
58
        return array_merge($parameters, $this->authentication->toArray());
59
    }
60
}
61