Completed
Push — v2 ( 12e20b...6101cd )
by Beñat
03:40
created

AccessTokenApi::getOfToken()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4286
cc 3
eloc 4
nc 2
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\Http\Http;
15
use BenatEspina\StackExchangeApiClient\Serializer\AccessTokenSerializer;
16
17
/**
18
 * The access token api class.
19
 *
20
 * @author Beñat Espiña <[email protected]>
21
 */
22
final class AccessTokenApi
23
{
24
    const URL = 'access-tokens/';
25
26
    /**
27
     * Immediately expires the access tokens passed.
28
     *
29
     * More info: https://api.stackexchange.com/docs/invalidate-access-tokens
30
     *
31
     * @param string|array $accessTokens Array which contains the tokens delimited by semicolon, or a simple token
32
     * @param array        $params       QueryString parameter(s), it admits page and pagesize; by default is null
33
     * @param bool         $serialize    Checks if the result will be serialize or not, by default is true
34
     *
35
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be array|\BenatEspina\Stack...lient\Model\AccessToken? 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...
36
     */
37 View Code Duplication
    public function invalidate($accessTokens, array $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...
38
    {
39
        $response = Http::instance()->get(
40
            self::URL . (is_array($accessTokens) ? implode(';', $accessTokens) : $accessTokens) . '/invalidate', $params
41
        );
42
43
        return $serialize === true ? AccessTokenSerializer::instance()->serialize($response) : $response;
44
    }
45
46
    /**
47
     * Reads the properties for a set of access tokens.
48
     *
49
     * More info: https://api.stackexchange.com/docs/read-access-tokens
50
     *
51
     * @param string|array $accessTokens Array which contains the tokens delimited by semicolon, or a simple token
52
     * @param array        $params       QueryString parameter(s), it admits page and pagesize; by default is null
53
     * @param bool         $serialize    Checks if the result will be serialize or not, by default is true
54
     *
55
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be array|\BenatEspina\Stack...lient\Model\AccessToken? 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...
56
     */
57
    public function getOfToken($accessTokens, array $params = [], $serialize = true)
58
    {
59
        $response = Http::instance()->get(
60
            self::URL . (is_array($accessTokens) ? implode(';', $accessTokens) : $accessTokens), $params
61
        );
62
63
        return $serialize === true ? AccessTokenSerializer::instance()->serialize($response) : $response;
64
    }
65
66
    /**
67
     * Allows an application to de-authorize itself for a set of users.
68
     *
69
     * More info: https://api.stackexchange.com/docs/application-de-authenticate
70
     *
71
     * @param string|array $accessTokens Array which contains the tokens delimited by semicolon, or a simple token
72
     * @param array        $params       QueryString parameter(s), it admits page and pagesize; by default is null
73
     * @param bool         $serialize    Checks if the result will be serialize or not, by default is true
74
     *
75
     * @return array
0 ignored issues
show
Documentation introduced by
Should the return type not be array|\BenatEspina\Stack...lient\Model\AccessToken? 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...
76
     */
77
    public function deAuthenticate($accessTokens, array $params = [], $serialize = true)
78
    {
79
        $response = Http::instance()->get(
80
            self::URL . (is_array($accessTokens) ? implode(';', $accessTokens) : $accessTokens) . '/de-authenticate', $params
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 125 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...
81
        );
82
83
        return $serialize === true ? AccessTokenSerializer::instance()->serialize($response) : $response;
84
    }
85
}
86