Paypal::getWebAppUrl()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 0
crap 2
1
<?php namespace Stevenmaguire\OAuth2\Client\Provider;
2
3
use League\OAuth2\Client\Provider\AbstractProvider;
4
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
5
use League\OAuth2\Client\Token\AccessToken;
6
use League\OAuth2\Client\Tool\BearerAuthorizationTrait;
7
use Psr\Http\Message\ResponseInterface;
8
9
class Paypal extends AbstractProvider
10
{
11
    use BearerAuthorizationTrait;
12
13
    /**
14
     * Client is in sandbox mode
15
     *
16
     * @var string
17
     */
18
    protected $isSandbox = false;
19
20
    /**
21
     * Creates and returns api base url base on client configuration.
22
     *
23
     * @return string
24
     */
25 10
    protected function getApiUrl()
26
    {
27 10
        return (bool) $this->isSandbox ? 'https://api.sandbox.paypal.com' : 'https://api.paypal.com';
28
    }
29
30
    /**
31
     * Creates and returns web app base url base on client configuration.
32
     *
33
     * @return string
34
     */
35 10
    protected function getWebAppUrl()
36
    {
37 10
        return (bool) $this->isSandbox ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com';
38
    }
39
40
    /**
41
     * Get authorization url to begin OAuth flow
42
     *
43
     * @return string
44
     */
45 10
    public function getBaseAuthorizationUrl()
46
    {
47 10
        return $this->getWebAppUrl().'/webapps/auth/protocol/openidconnect/v1/authorize';
48
    }
49
50
    /**
51
     * Get access token url to retrieve token
52
     *
53
     * @return string
54
     */
55 10
    public function getBaseAccessTokenUrl(array $params)
56
    {
57 10
        return $this->getApiUrl().'/v1/identity/openidconnect/tokenservice';
58
    }
59
60
    /**
61
     * Get provider url to fetch user details
62
     *
63
     * @param  AccessToken $token
64
     *
65
     * @return string
66
     */
67 2
    public function getResourceOwnerDetailsUrl(AccessToken $token)
68
    {
69 2
        return $this->getApiUrl().'/v1/identity/openidconnect/userinfo?schema=openid';
70
    }
71
72
    /**
73
     * Get the default scopes used by this provider.
74
     *
75
     * This should not be a complete list of all scopes, but the minimum
76
     * required for the provider user interface!
77
     *
78
     * @return string[]
79
     */
80 8
    protected function getDefaultScopes()
81
    {
82 8
        return ['openid'];
83
    }
84
85
    /**
86
     * Returns the string that should be used to separate scopes when building
87
     * the URL for requesting an access token.
88
     *
89
     * @return string Scope separator, defaults to ','
90
     */
91 10
    protected function getScopeSeparator()
92
    {
93 10
        return ' ';
94
    }
95
96
    /**
97
     * Check a provider response for errors.
98
     *
99
     * @throws IdentityProviderException
100
     * @param  ResponseInterface $response
101
     * @param  string $data Parsed response data
102
     * @return void
103
     */
104 6
    protected function checkResponse(ResponseInterface $response, $data)
105
    {
106 6
        $statusCode = $response->getStatusCode();
107 6
        if ($statusCode > 400) {
108 2
            throw new IdentityProviderException(
109 2
                $data['message'] ?: $response->getReasonPhrase(),
110 1
                $statusCode,
111
                $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...
112 1
            );
113
        }
114 4
    }
115
116
    /**
117
     * Generate a user object from a successful user details request.
118
     *
119
     * @param object $response
120
     * @param AccessToken $token
121
     * @return PaypalResourceOwner
122
     */
123 2
    protected function createResourceOwner(array $response, AccessToken $token)
124
    {
125 2
        return new PaypalResourceOwner($response);
126
    }
127
}
128