Runkeeper::getResourceOwner()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace League\OAuth2\Client\Provider;
4
5
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
6
use League\OAuth2\Client\Token\AccessToken;
7
use League\OAuth2\Client\Tool\BearerAuthorizationTrait;
8
use Psr\Http\Message\ResponseInterface;
9
10
class Runkeeper extends AbstractProvider
11
{
12
    use BearerAuthorizationTrait;
13
14
    public $domain = 'https://runkeeper.com';
15
16
    public $apiDomain = 'https://api.runkeeper.com';
17
18
    /**
19
     * Get authorization url to begin OAuth flow
20
     *
21
     * @return string
22
     */
23 12
    public function getBaseAuthorizationUrl()
24
    {
25 12
        return $this->domain . '/apps/authorize';
26
    }
27
28
    /**
29
     * Get access token url to retrieve token
30
     *
31
     * @param  array $params
32
     *
33
     * @return string
34
     */
35 15
    public function getBaseAccessTokenUrl(array $params)
36
    {
37 15
        return $this->domain . '/apps/token';
38
    }
39
40
    /**
41
     * Get provider url to fetch user details
42
     *
43
     * @param  AccessToken $token
44
     *
45
     * @return string
46
     */
47 6
    public function getResourceOwnerDetailsUrl(AccessToken $token)
48
    {
49 6
        return $this->apiDomain . '/user?access_token=' . $token;
50
    }
51
52
    /**
53
     * Get provider url to fetch user profile details
54
     *
55
     * @param  AccessToken $token
56
     *
57
     * @return string
58
     */
59 6
    public function getResourceOwnerProfileUrl(AccessToken $token)
60
    {
61 6
        return $this->apiDomain . '/profile?access_token=' . $token;
62
    }
63
64
    /**
65
     * @link https://runkeeper.com/developer/healthgraph/registration-authorization
66
     * Get the default scopes used by this provider.
67
     *
68
     * This should not be a complete list of all scopes, but the minimum
69
     * required for the provider user interface!
70
     *
71
     * @return array
72
     */
73 6
    protected function getDefaultScopes()
74
    {
75 6
        return [];
76
    }
77
78
    /**
79
     * Check a provider response for errors.
80
     *
81
     * @throws IdentityProviderException
82
     * @param  ResponseInterface $response
83
     * @param  string $data Parsed response data
84
     * @return void
85
     */
86 12
    protected function checkResponse(ResponseInterface $response, $data)
87
    {
88 12
        if (isset($data['error'])) {
89 3
            throw new IdentityProviderException(
90 3
                $data['error'] ?: $response->getReasonPhrase(),
91 3
                $response->getStatusCode(),
92
                $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...
93 2
            );
94
        }
95 9
    }
96
97
    /**
98
     * Requests and returns the resource owner of given access token.
99
     *
100
     * @param  AccessToken $token
101
     * @return ResourceOwnerInterface
102
     */
103 3
    public function getResourceOwner(AccessToken $token)
104
    {
105 3
        $response = $this->fetchResourceOwnerDetails($token);
106
107 3
        return $this->createResourceOwner($response, $token);
108
    }
109
110
    /**
111
     * Requests resource owner details.
112
     *
113
     * @param  AccessToken $token
114
     * @return mixed
115
     */
116 3
    protected function fetchResourceOwnerDetails(AccessToken $token)
117
    {
118 3
        $url = $this->getResourceOwnerDetailsUrl($token);
119 3
        $request = $this->getAuthenticatedRequest(self::METHOD_GET, $url, $token);
120
121 3
        $userDetails = $this->getParsedResponse($request);
122
123 3
        $url = $this->getResourceOwnerProfileUrl($token);
124 3
        $request = $this->getAuthenticatedRequest(self::METHOD_GET, $url, $token);
125
126 3
        $userProfile = $this->getParsedResponse($request);
127
128 3
        return array_merge($userDetails, $userProfile);
129
    }
130
131
    /**
132
     * Generate a user object from a successful user details request.
133
     *
134
     * @param array $response
135
     * @param AccessToken $token
136
     * @return \League\OAuth2\Client\Provider\ResourceOwnerInterface
137
     */
138 3
    protected function createResourceOwner(array $response, AccessToken $token)
139
    {
140 3
        return new RunkeeperResourceOwner($response);
141
    }
142
}
143