Completed
Pull Request — master (#472)
by
unknown
02:42
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
<?php
2
3
namespace OAuth\OAuth1\Service;
4
5
use OAuth\OAuth1\Signature\SignatureInterface;
6
use OAuth\Common\Http\Uri\Uri;
7
use OAuth\Common\Consumer\CredentialsInterface;
8
use OAuth\Common\Http\Uri\UriInterface;
9
use OAuth\Common\Storage\TokenStorageInterface;
10
use OAuth\Common\Http\Client\ClientInterface;
11
12
class Etsy extends AbstractService
13
{
14
15
    protected $scopes = array();
16
17
    public function __construct(
18
        CredentialsInterface $credentials,
19
        ClientInterface $httpClient,
20
        TokenStorageInterface $storage,
21
        SignatureInterface $signature,
22
        UriInterface $baseApiUri = null
23
    ) {
24
        parent::__construct($credentials, $httpClient, $storage, $signature, $baseApiUri);
25
26
        if (null === $baseApiUri) {
27
            $this->baseApiUri = new Uri('https://openapi.etsy.com/v2/');
28
        }
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function getRequestTokenEndpoint()
35
    {
36
        $uri = new Uri($this->baseApiUri . 'oauth/request_token');
37
        $scopes = $this->getScopes();
38
39
        if (count($scopes)) {
40
            $uri->setQuery('scope=' . implode('%20', $scopes));
41
        }
42
43
        return $uri;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function getAuthorizationEndpoint()
50
    {
51
        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...
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function getAccessTokenEndpoint()
58
    {
59
        return new Uri($this->baseApiUri . 'oauth/access_token');
60
    }
61
    
62
    /**
63
     * Set the scopes for permissions
64
     * @see https://www.etsy.com/developers/documentation/getting_started/oauth#section_permission_scopes
65
     * @param array $scopes
66
     *
67
     * @return $this
68
     */
69
    public function setScopes(array $scopes)
70
    {
71
        if (!is_array($scopes)) {
72
            $scopes = array();
73
        }
74
75
        $this->scopes = $scopes;
76
        return $this;
77
    }
78
79
    /**
80
     * Return the defined scopes
81
     * @return array
82
     */
83
    public function getScopes()
84
    {
85
        return $this->scopes;
86
    }
87
}
88