Stripe   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 127
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 5
dl 0
loc 127
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getBaseAuthorizationUrl() 0 4 1
A getBaseAccessTokenUrl() 0 4 1
A getResourceOwnerDetailsUrl() 0 4 1
A getBaseDeauthorizationUrl() 0 4 1
A getDefaultScopes() 0 4 1
A checkResponse() 0 10 3
A createResourceOwner() 0 4 1
A createAccessToken() 0 13 3
A deauthorize() 0 17 1
1
<?php
2
3
namespace AdamPaterson\OAuth2\Client\Provider;
4
5
use League\OAuth2\Client\Grant\AbstractGrant;
6
use League\OAuth2\Client\Provider\AbstractProvider;
7
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
8
use League\OAuth2\Client\Token\AccessToken;
9
use League\OAuth2\Client\Tool\BearerAuthorizationTrait;
10
use Psr\Http\Message\ResponseInterface;
11
12
class Stripe extends AbstractProvider
13
{
14
    use BearerAuthorizationTrait;
15
16
    /**
17
     * Get authorization url to begin OAuth flow
18
     *
19
     * @return string
20
     */
21 3
    public function getBaseAuthorizationUrl()
22
    {
23 3
        return 'https://connect.stripe.com/oauth/authorize';
24
    }
25
26
    /**
27
     * Get access token url to retrieve token
28
     *
29
     * @param array $params
30
     *
31
     * @return string
32
     */
33 15
    public function getBaseAccessTokenUrl(array $params)
34
    {
35 15
        return 'https://connect.stripe.com/oauth/token';
36
    }
37
38
    /**
39
     * Get provider url to fetch user details
40
     *
41
     * @param AccessToken $token
42
     *
43
     * @return string
44
     */
45 6
    public function getResourceOwnerDetailsUrl(AccessToken $token)
46
    {
47 6
        return 'https://api.stripe.com/v1/account';
48
    }
49
50
    /**
51
     * Get deauthorization url to end OAuth flow
52
     *
53
     * @return string
54
     */
55 3
    public function getBaseDeauthorizationUrl()
56
    {
57 3
        return 'https://connect.stripe.com/oauth/deauthorize';
58
    }
59
60
    /**
61
     * Get the default scopes used by this provider.
62
     *
63
     * @return array
64
     */
65
    protected function getDefaultScopes()
66
    {
67
        return ['read_only'];
68 12
    }
69
70 12
    /**
71 3
     * Check a provider response for errors.
72 3
     *
73 3
     * @param ResponseInterface $response
74
     * @param array|string $data
75 2
     *
76
     * @throws IdentityProviderException
77 9
     */
78
    protected function checkResponse(ResponseInterface $response, $data)
79
    {
80
        if ($response->getStatusCode() >= 400) {
81
            throw new IdentityProviderException(
82
                $data['error'] ?: $response->getReasonPhrase(),
83
                $response->getStatusCode(),
84
                $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...
85
            );
86
        }
87 3
    }
88
89 3
    /**
90
     * Generate a user object from a successful user details request.
91
     *
92 9
     * @param array $response
93
     * @param AccessToken $token
94 9
     *
95
     * @return StripeResourceOwner
96
     */
97 9
    protected function createResourceOwner(array $response, AccessToken $token)
98 9
    {
99 9
        return new StripeResourceOwner($response);
100 6
    }
101 6
102
    protected function createAccessToken(array $response, AbstractGrant $grant)
103 9
    {
104
        $accessToken = parent::createAccessToken($response, $grant);
105
106
        // create the parent access token and add properties from response
107
        foreach ($response as $k => $v) {
108
            if (!property_exists($accessToken, $k)) {
109
                $accessToken->$k = $v;
110
            }
111
        }
112
113
        return $accessToken;
114
    }
115
116
    /**
117
     * @param string $stripeUserId stripe account ID
118
     *
119
     * @return mixed
120
     */
121
    public function deauthorize($stripeUserId)
122
    {
123
        $request = $this->createRequest(
124
            self::METHOD_POST,
125
            $this->getBaseDeauthorizationUrl(),
126
            null,
127
            [
128
                'body' => $this->buildQueryString([
129
                    'stripe_user_id' => $stripeUserId,
130
                    'client_id' => $this->clientId,
131
                    'client_secret' => $this->clientSecret,
132
                ]),
133
            ]
134
        );
135
136
        return $this->getParsedResponse($request);
137
    }
138
}
139