Test Failed
Push — master ( 583253...ef047e )
by Shaharia
05:16
created

Provider::getScopeSeparator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * Official OAuth2 Client Provider for Preview Technologies
4
 *
5
 * @author Shaharia Azam <[email protected]>
6
 * @url https://www.previewtechs.com
7
 */
8
9
namespace Previewtechs\Oauth2\Client;
10
11
use League\OAuth2\Client\Provider\AbstractProvider;
12
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
13
use League\OAuth2\Client\Token\AccessToken;
14
use League\OAuth2\Client\Tool\BearerAuthorizationTrait;
15
use Psr\Http\Message\ResponseInterface;
16
17
/**
18
 * Class Provider
19
 * @package Previewtechs\Oauth2\Client
20
 */
21
class Provider extends AbstractProvider
22
{
23
24
    use BearerAuthorizationTrait;
25
26
    /**
27
     * @var bool
28
     */
29
    public $testMode = false;
30
    /**
31
     * @var array
32
     */
33
    public $scopes = ['basic', 'email'];
34
35
    /**
36
     * @var
37
     */
38
    public $authorizeEndpoint;
39
    /**
40
     * @var
41
     */
42
    public $accessTokenEndpoint;
43
    /**
44
     * @var
45
     */
46
    public $resourceOwnerEndpoint;
47
48
    /**
49
     * @var array
50
     */
51
    public $defaultScopes = ['basic', 'email'];
52
53
    /**
54
     * @var string
55
     */
56
    public $oauthHost = "https://myaccount.previewtechs.com";
57
58
    /**
59
     * @return string
60
     */
61
    public function getBaseAuthorizationUrl()
62
    {
63
        return $this->authorizeEndpoint = $this->oauthHost . "/oauth/authorize";
64
    }
65
66
    /**
67
     * @param array $params
68
     * @return string
69
     */
70
    public function getBaseAccessTokenUrl(array $params)
71
    {
72
        return $this->accessTokenEndpoint = $this->oauthHost . "/oauth/access_token";
73
    }
74
75
    /**
76
     * @param AccessToken $token
77
     * @return string
78
     */
79
    public function getResourceOwnerDetailsUrl(AccessToken $token)
80
    {
81
        return $this->resourceOwnerEndpoint = $this->oauthHost . "/api/v1/userinfo";
82
    }
83
84
    /**
85
     * @return array
86
     */
87
    protected function getDefaultScopes()
88
    {
89
        return $this->defaultScopes;
90
    }
91
92
    /**
93
     * @return string
94
     */
95
    protected function getScopeSeparator()
96
    {
97
        return " ";
98
    }
99
100
    /**
101
     * @param ResponseInterface $response
102
     * @param array|string $data
103
     * @throws IdentityProviderException
104
     */
105
    protected function checkResponse(ResponseInterface $response, $data)
106
    {
107
        $statusCode = $response->getStatusCode();
108
        if ($statusCode > 400) {
109
            throw new IdentityProviderException(
110
                $data['message'] ?: $response->getReasonPhrase(),
111
                $statusCode,
112
                $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...
113
            );
114
        }
115
    }
116
117
    /**
118
     * @param array $response
119
     * @param AccessToken $token
120
     * @return ResourceOwner
121
     */
122
    protected function createResourceOwner(array $response, AccessToken $token)
123
    {
124
        return new ResourceOwner($response);
125
    }
126
}
127