Completed
Pull Request — master (#471)
by
unknown
02:44
created

Etsy::parseAccessTokenResponse()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 23
rs 8.7972
c 1
b 1
f 0
cc 4
eloc 15
nc 3
nop 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A Etsy::getScopes() 0 4 1
1
<?php
2
3
namespace OAuth\OAuth1\Service;
4
5
use OAuth\OAuth1\Signature\SignatureInterface;
6
use OAuth\OAuth1\Token\StdOAuth1Token;
7
use OAuth\Common\Http\Exception\TokenResponseException;
8
use OAuth\Common\Http\Uri\Uri;
9
use OAuth\Common\Consumer\CredentialsInterface;
10
use OAuth\Common\Http\Uri\UriInterface;
11
use OAuth\Common\Storage\TokenStorageInterface;
12
use OAuth\Common\Http\Client\ClientInterface;
13
14
class Etsy extends AbstractService
15
{
16
17
    protected $scopes = array();
18
19
    public function __construct(
20
        CredentialsInterface $credentials,
21
        ClientInterface $httpClient,
22
        TokenStorageInterface $storage,
23
        SignatureInterface $signature,
24
        UriInterface $baseApiUri = null
25
    ) {
26
        parent::__construct($credentials, $httpClient, $storage, $signature, $baseApiUri);
27
28
        if (null === $baseApiUri) {
29
            $this->baseApiUri = new Uri('https://openapi.etsy.com/v2/');
30
        }
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function getRequestTokenEndpoint()
37
    {
38
        $uri = new Uri($this->baseApiUri . 'oauth/request_token');
39
        $scopes = $this->getScopes();
40
41
        if (count($scopes)) {
42
            $uri->setQuery('scope=' . implode('%20', $scopes));
43
        }
44
45
        return $uri;
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function getAuthorizationEndpoint()
52
    {
53
        return new Uri($this->baseApiUri);
0 ignored issues
show
Bug introduced by
It seems like $this->baseApiUri can also be of type object<OAuth\Common\Http\Uri\UriInterface>; however, OAuth\Common\Http\Uri\Uri::__construct() does only seem to accept string|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59
    public function getAccessTokenEndpoint()
60
    {
61
        return new Uri($this->baseApiUri . 'oauth/access_token');
62
    }
63
    
64
    /**
65
     * Set the scopes for permissions
66
     * @see https://www.etsy.com/developers/documentation/getting_started/oauth#section_permission_scopes
67
     * @param array $scopes
68
     *
69
     * @return $this
70
     */
71
    public function setScopes(array $scopes)
72
    {
73
        if (!is_array($scopes)) {
74
            $scopes = array();
75
        }
76
77
        $this->scopes = $scopes;
78
        return $this;
79
    }
80
81
    /**
82
     * Return the defined scopes
83
     * @return array
84
     */
85
    public function getScopes()
86
    {
87
        return $this->scopes;
88
    }
89
}
90