Completed
Push — master ( ec993a...1dea25 )
by Michael
02:43
created

TomTomMySports::getApiVersion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
namespace League\OAuth2\Client\Provider;
3
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 TomTomMySports extends AbstractProvider
10
{
11
    use BearerAuthorizationTrait;
12
13
    /**
14
     * @var string
15
     */
16
    const BASE_MYSPORTS_URL = 'https://api.tomtom.com/mysports';
17
18
    /**
19
     * @var string
20
     */
21
    protected $apiVersion = '1';
22
23
    /**
24
     * Constructs an OAuth 2.0 service provider.
25
     *
26
     * @param array $options An array of options to set on this provider.
27
     *     Options include `clientId`, `clientSecret`, `redirectUri`, `state`, `apiVersion`.
28
     *     Individual providers may introduce more options, as needed.
29
     * @param array $collaborators An array of collaborators that may be used to
30
     *     override this provider's default behavior. Collaborators include
31
     *     `grantFactory`, `requestFactory`, `httpClient`, and `randomFactory`.
32
     *     Individual providers may introduce more collaborators, as needed.
33
     */
34 21
    public function __construct(array $options = [], array $collaborators = [])
35
    {
36 21
        parent::__construct($options, $collaborators);
37
38 21
        foreach ($options as $option => $value) {
39 21
            if (property_exists($this, $option)) {
40 21
                $this->{$option} = $value;
41 7
            }
42 7
        }
43 21
    }
44
45
    /**
46
     * Get authorization url to begin OAuth flow
47
     *
48
     * @return string
49
     */
50 12
    public function getBaseAuthorizationUrl()
51
    {
52 12
        return self::BASE_MYSPORTS_URL . '/oauth2/authorize';
53
    }
54
55
    /**
56
     * Get access token url to retrieve token
57
     *
58
     * @param  array $params
59
     *
60
     * @return string
61
     */
62 12
    public function getBaseAccessTokenUrl(array $params)
63
    {
64 12
        return self::BASE_MYSPORTS_URL . '/oauth2/token';
65
    }
66
67
    /**
68
     * Get provider url to fetch user details
69
     *
70
     * @param  AccessToken $token
71
     *
72
     * @return string
73
     */
74
    public function getResourceOwnerDetailsUrl(AccessToken $token)
75
    {
76
        return self::BASE_MYSPORTS_URL . '/' . $this->apiVersion . '/athlete';
77
    }
78
79
    /**
80
     * @link http://developer.tomtom.com/products/sports/mysportscloud/authorization/
81
     *
82
     * Get the default scopes used by this provider.
83
     *
84
     * This should not be a complete list of all scopes, but the minimum
85
     * required for the provider user interface!
86
     *
87
     * @return array
88
     */
89 6
    protected function getDefaultScopes()
90
    {
91 6
        return ['activities'];
92
    }
93
94
    /**
95
     * Check a provider response for errors.
96
     *
97
     * @throws IdentityProviderException
98
     * @param  ResponseInterface $response
99
     * @param  string $data Parsed response data
100
     * @return void
101
     */
102 9
    protected function checkResponse(ResponseInterface $response, $data)
103
    {
104 9
        if ($response->getStatusCode() >= 400) {
105 3
            throw new IdentityProviderException(
106 3
                $data['message'] ?: $response->getReasonPhrase(),
107 3
                $response->getStatusCode(),
108 1
                $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...
109 1
            );
110
        }
111 7
    }
112
113
    /**
114
     * Generate a user object from a successful user details request.
115
     *
116
     * @param array $response
117
     * @param AccessToken $token
118
     * @return null
119
     */
120 1
    protected function createResourceOwner(array $response, AccessToken $token)
121
    {
122
        return null;
123 1
    }
124
125
    /**
126
     * @return string
127
     */
128 3
    public function getBaseMySportsUrl()
129
    {
130 3
        return self::BASE_MYSPORTS_URL;
131
    }
132
133
    /**
134
     * @return string
135
     */
136 3
    public function getApiVersion()
137
    {
138 3
        return $this->apiVersion;
139
    }
140
141
    /**
142
     * Returns the default headers used by this provider.
143
     *
144
     * Typically this is used to set 'Accept' or 'Content-Type' headers.
145
     *
146
     * @return array
147
     */
148 9
    protected function getDefaultHeaders()
149
    {
150
        return [
151 9
            'Accept'          => 'application/json',
152 3
            'Accept-Encoding' => 'gzip',
153 3
        ];
154
    }
155
}
156