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

ApplicationDeAuthenticate   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 33
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A __invoke() 0 9 1
A url() 0 4 1
A stringifyAccessTokens() 0 4 2
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\AccessToken;
15
16
use BenatEspina\StackExchangeApiClient\Http\HttpClient;
17
use BenatEspina\StackExchangeApiClient\Serializer\Serializer;
18
19
/**
20
 * https://api.stackexchange.com/docs/application-de-authenticate.
21
 *
22
 * @author Beñat Espiña <[email protected]>
23
 */
24
class ApplicationDeAuthenticate
25
{
26
    private const URL = '/apps/{accessTokens}/de-authenticate';
27
28
    private $client;
29
    private $serializer;
30
31
    public function __construct(HttpClient $client, Serializer $serializer)
32
    {
33
        $this->client = $client;
34
        $this->serializer = $serializer;
35
    }
36
37
    public function __invoke($accessTokens, array $parameters = [])
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...
38
    {
39
        return $this->serializer->serialize(
40
            $this->client->get(
41
                $this->url($accessTokens),
42
                $parameters
43
            )
44
        );
45
    }
46
47
    private function url($accessTokens) : string
48
    {
49
        return str_replace('{accessTokens}', $this->stringifyAccessTokens($accessTokens), self::URL);
50
    }
51
52
    private function stringifyAccessTokens($accessTokens) : string
53
    {
54
        return is_array($accessTokens) ? implode(';', $accessTokens) : $accessTokens;
55
    }
56
}
57