Completed
Push — master ( 5c7825...ce6374 )
by Bas van
04:42 queued 02:26
created

OAuth::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
namespace Strava\API;
3
4
use League\OAuth2\Client\Entity\User;
5
use League\OAuth2\Client\Token\AccessToken as AccessToken;
6
use League\OAuth2\Client\Provider\AbstractProvider as AbstractProvider;
7
use Psr\Http\Message\ResponseInterface;
8
9
/**
10
 * Strava OAuth
11
 * The Strava implementation of the OAuth client
12
 * 
13
 * @see: https://github.com/thephpleague/oauth2-client
14
 * @author Bas van Dorst
15
 */
16
class OAuth extends AbstractProvider
17
{
18
19
    public $scopes = array('write');
20
    public $responseType = 'json';
21
    
22
    /**
23
     * @see AbstractProvider::__construct
24
     * @param array $options
25
     */
26 8
    public function __construct($options)
27
    {
28 8
        parent::__construct($options);
29 8
        $this->headers = array(
0 ignored issues
show
Bug introduced by
The property headers does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
30
            'Authorization' => 'Bearer'
31 8
        );
32 8
    }
33
    
34
    /**
35
     * @see AbstractProvider::urlAuthorize
36
     */
37 1
    public function urlAuthorize()
38
    {
39 1
        return 'https://www.strava.com/oauth/authorize';
40
    }
41
42
    /**
43
     * @see AbstractProvider::urlAuthorize
44
     */
45 1
    public function urlAccessToken()
46
    {
47 1
        return 'https://www.strava.com/oauth/token';
48
    }
49
50
    /**
51
     * @see AbstractProvider::urlUserDetails
52
     */
53 1
    public function urlUserDetails(AccessToken $token)
54
    {
55 1
        return 'https://www.strava.com/api/v3/athlete/?access_token='.$token;
56
    }
57
58
    /**
59
     * @see AbstractProvider::userDetails
60
     */
61 1
    public function userDetails($response, AccessToken $token)
0 ignored issues
show
Unused Code introduced by
The parameter $token is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
62
    {
63 1
        $user = new \stdClass;
64
65 1
        $user->uid = $response->id;
66 1
        $user->name = implode(" ", array($response->firstname, $response->lastname));
67 1
        $user->firstName = $response->firstname;
68 1
        $user->lastName = $response->lastname;
69 1
        $user->email = $response->email;
70 1
        $user->location = $response->country;
71 1
        $user->imageUrl = $response->profile;
72 1
        $user->gender = $response->sex;
73
74 1
        return $user;
75
    }
76
77
    /**
78
     * @see AbstractProvider::userUid
79
     */
80 1
    public function userUid($response, AccessToken $token)
0 ignored issues
show
Unused Code introduced by
The parameter $token is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
81
    {
82 1
        return $response->id;
83
    }
84
85
    /**
86
     * @see AbstractProvider::userUid
87
     */
88 1
    public function userEmail($response, AccessToken $token)
0 ignored issues
show
Unused Code introduced by
The parameter $token is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
89
    {
90 1
        return isset($response->email) && $response->email ? $response->email : null;
91
    }
92
93
    /**
94
     * @see AbstractProvider::userScreenName
95
     */
96 1
    public function userScreenName($response, AccessToken $token)
0 ignored issues
show
Unused Code introduced by
The parameter $token is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
97
    {
98 1
        return implode(" ", array($response->firstname, $response->lastname));
99
    }
100
101
    /**
102
     * @see AbstractProvider::getBaseAuthorizationUrl
103
     */
104
    public function getBaseAuthorizationUrl()
105
    {
106
        return 'https://www.strava.com/oauth/authorize';
107
    }
108
109
    /**
110
     * @see AbstractProvider::getBaseAccessTokenUrl
111
     */
112
    public function getBaseAccessTokenUrl(array $params)
113
    {
114
        return 'https://www.strava.com/oauth/token';
115
    }
116
117
    /**
118
     * @see AbstractProvider::getResourceOwnerDetailsUrl
119
     */
120 1
    public function getResourceOwnerDetailsUrl(AccessToken $token)
121
    {
122
        return '';
123 1
    }
124
125
126
    /**
127
     * @see AbstractProvider::getDefaultScopes
128
     */
129 1
    protected function getDefaultScopes()
130 1
    {
131
        return array('view_private', 'write');
132
    }
133
134
135
    /**
136
     * @see AbstractProvider::checkResponse
137
     */
138
    protected function checkResponse(ResponseInterface $response, $data)
139
    {
140
141
    }
142
143
    /**
144
     * @see AbstractProvider::createResourceOwner
145
     */
146
    protected function createResourceOwner(array $response, AccessToken $token)
147
    {
148
149
    }
150
}