Completed
Pull Request — master (#1)
by
unknown
04:07
created

Heroku::getDefaultHeaders()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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 Heroku extends AbstractProvider
10
{
11
    use BearerAuthorizationTrait;
12
13
    /**
14
     * @var string Key used in a token response to identify the resource owner.
15
     */
16
    const ACCESS_TOKEN_RESOURCE_OWNER_ID = 'user_id';
17
18
    /**
19
     * Get authorization url to begin OAuth flow
20
     *
21
     * @return string
22
     */
23 6
    public function getBaseAuthorizationUrl()
24
    {
25 6
        return 'https://id.heroku.com/oauth/authorize';
26
    }
27
28
    /**
29
     * Get access token url to retrieve token
30
     *
31
     * @return string
32
     */
33 8
    public function getBaseAccessTokenUrl(array $params)
34
    {
35 8
        return 'https://id.heroku.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 2
    public function getResourceOwnerDetailsUrl(AccessToken $token)
46
    {
47 2
        return 'https://api.heroku.com/account';
48
    }
49
50
    /**
51
     * Get the default scopes used by this provider.
52
     *
53
     * This should not be a complete list of all scopes, but the minimum
54
     * required for the provider user interface!
55
     *
56
     * @return array
57
     */
58 4
    protected function getDefaultScopes()
59
    {
60 4
        return [];
61
    }
62
63
    /**
64
     * Returns the string that should be used to separate scopes when building
65
     * the URL for requesting an access token.
66
     *
67
     * @return string Scope separator, defaults to ','
68
     */
69 6
    protected function getScopeSeparator()
70
    {
71 6
        return ' ';
72
    }
73
74
    /**
75
     * Returns the default headers used by this provider.
76
     *
77
     * Typically this is used to set 'Accept' or 'Content-Type' headers.
78
     *
79
     * @return array
80
     */
81
    protected function getDefaultHeaders()
82 6
    {
83
        return [
84 6
            'Accept' => 'application/vnd.heroku+json; version=3'
85 6
        ];
86 2
    }
87 2
88 2
    /**
89
     * Check a provider response for errors.
90 2
     *
91
     * @throws IdentityProviderException
92 4
     * @param  ResponseInterface $response
93
     * @param  string $data Parsed response data
94
     * @return void
95
     */
96
    protected function checkResponse(ResponseInterface $response, $data)
97
    {
98
        $statusCode = $response->getStatusCode();
99
        if ($statusCode >= 400) {
100
            throw new IdentityProviderException(
101 2
                isset($data['message']) ? $data['message'] : $response->getReasonPhrase(),
102
                $statusCode,
103 2
                $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...
104
            );
105
        }
106
    }
107
108
    /**
109
     * Generate a user object from a successful user details request.
110
     *
111
     * @param object $response
112
     * @param AccessToken $token
113
     * @return HerokuResourceOwner
114
     */
115
    protected function createResourceOwner(array $response, AccessToken $token)
116
    {
117
        return new HerokuResourceOwner($response);
118
    }
119
}
120