Completed
Push — master ( 16d99f...56cafb )
by Steven
8s
created

Dropbox::getBaseAuthorizationUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Stevenmaguire\OAuth2\Client\Provider;
4
5
use League\OAuth2\Client\Provider\AbstractProvider;
6
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
7
use League\OAuth2\Client\Token\AccessToken;
8
use League\OAuth2\Client\Tool\BearerAuthorizationTrait;
9
use Psr\Http\Message\ResponseInterface;
10
11
class Dropbox extends AbstractProvider
12
{
13
    use BearerAuthorizationTrait;
14
15
    /**
16
     * @var string Key used in the access token response to identify the resource owner.
17
     */
18
    const ACCESS_TOKEN_RESOURCE_OWNER_ID = 'account_id';
19
20
    /**
21
     * Get authorization url to begin OAuth flow
22
     *
23
     * @return string
24
     */
25 6
    public function getBaseAuthorizationUrl()
26
    {
27 6
        return 'https://api.dropbox.com/oauth2/authorize';
28
    }
29
30
    /**
31
     * Get access token url to retrieve token
32
     *
33
     * @return string
34
     */
35 8
    public function getBaseAccessTokenUrl(array $params)
36
    {
37 8
        return 'https://api.dropbox.com/oauth2/token';
38
    }
39
40
    /**
41
     * Get provider url to fetch user details
42
     *
43
     * @param  AccessToken $token
44
     *
45
     * @return string
46
     */
47 2
    public function getResourceOwnerDetailsUrl(AccessToken $token)
48
    {
49 2
        return 'https://api.dropbox.com/2/users/get_current_account';
50
    }
51
52
    /**
53
     * Get the default scopes used by this provider.
54
     *
55
     * This should not be a complete list of all scopes, but the minimum
56
     * required for the provider user interface!
57
     *
58
     * @return array
59
     */
60 4
    protected function getDefaultScopes()
61
    {
62 4
        return [];
63
    }
64
65
    /**
66
     * Check a provider response for errors.
67
     *
68
     * @link   https://www.dropbox.com/developers/core/docs
69
     * @throws IdentityProviderException
70
     * @param  ResponseInterface $response
71
     * @param  string $data Parsed response data
72
     * @return void
73
     */
74 6
    protected function checkResponse(ResponseInterface $response, $data)
75
    {
76 6
        if (isset($data['error'])) {
77 2
            throw new IdentityProviderException(
78 2
                $data['error'] ?: $response->getReasonPhrase(),
79 2
                $response->getStatusCode(),
80 1
                $response
0 ignored issues
show
Documentation introduced by
$response is of type object<Psr\Http\Message\ResponseInterface>, but the function expects a array|string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
81 1
            );
82
        }
83 4
    }
84
85
    /**
86
     * Generate a user object from a successful user details request.
87
     *
88
     * @param object $response
89
     * @param AccessToken $token
90
     * @return DropboxResourceOwner
91
     */
92 2
    protected function createResourceOwner(array $response, AccessToken $token)
93
    {
94 2
        return new DropboxResourceOwner($response);
95
    }
96
97
    /**
98
     * Requests resource owner details.
99
     *
100
     * @param  AccessToken $token
101
     * @return mixed
102
     */
103 6
    protected function fetchResourceOwnerDetails(AccessToken $token)
104
    {
105 6
        $url = $this->getResourceOwnerDetailsUrl($token);
106 6
107 6
        $request = $this->getAuthenticatedRequest(self::METHOD_POST, $url, $token);
108
109
        return $this->getParsedResponse($request);
110
    }
111
112
    /**
113
     * Builds the authorization URL.
114
     *
115
     * @param  array $options
116
     * @return string Authorization URL
117
     */
118
    public function getAuthorizationUrl(array $options = [])
119
    {
120
        return parent::getAuthorizationUrl(array_merge([
121
            'approval_prompt' => []
122
        ], $options));
123
    }
124
}
125