Completed
Pull Request — master (#18)
by
unknown
06:04
created

OAuth::getBaseAuthorizationUrl()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
namespace Strava\API;
3
4
use League\OAuth2\Client\Token\AccessToken as AccessToken;
5
use League\OAuth2\Client\Provider\AbstractProvider as AbstractProvider;
6
use Psr\Http\Message\ResponseInterface;
7
8
/**
9
 * Strava OAuth
10
 * The Strava implementation of the OAuth client
11
 * 
12
 * @see: https://github.com/thephpleague/oauth2-client
13
 * @author Bas van Dorst
14
 */
15
class OAuth extends AbstractProvider
16
{
17
18
    public $scopes = array('write');
19
    public $responseType = 'json';
20
    
21
    /**
22
     * @see AbstractProvider::__construct
23
     * @param array $options
24
     */
25 8
    public function __construct($options)
26
    {
27 8
        parent::__construct($options);
28 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...
29
            'Authorization' => 'Bearer'
30 8
        );
31 8
    }
32
    
33
    /**
34
     * @see AbstractProvider::urlAuthorize
35
     */
36 1
    public function urlAuthorize()
37
    {
38 1
        return 'https://www.strava.com/oauth/authorize';
39
    }
40
41
    /**
42
     * @see AbstractProvider::urlAuthorize
43
     */
44 1
    public function urlAccessToken()
45
    {
46 1
        return 'https://www.strava.com/oauth/token';
47
    }
48
49
    /**
50
     * @see AbstractProvider::urlUserDetails
51
     */
52 1
    public function urlUserDetails(AccessToken $token)
53
    {
54 1
        return 'https://www.strava.com/api/v3/athlete/?access_token='.$token;
55
    }
56
57
    /**
58
     * @see AbstractProvider::userDetails
59
     */
60 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...
61
    {
62 1
        $user = new \stdClass;
63
64 1
        $user->uid = $response->id;
65 1
        $user->name = implode(" ", array($response->firstname, $response->lastname));
66 1
        $user->firstName = $response->firstname;
67 1
        $user->lastName = $response->lastname;
68 1
        $user->email = $response->email;
69 1
        $user->location = $response->country;
70 1
        $user->imageUrl = $response->profile;
71 1
        $user->gender = $response->sex;
72 1
73 1
        return $user;
74
    }
75 1
76
    /**
77
     * @see AbstractProvider::userUid
78
     */
79
    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...
80
    {
81 1
        return $response->id;
82
    }
83 1
84
    /**
85
     * @see AbstractProvider::userUid
86
     */
87
    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...
88
    {
89 1
        return isset($response->email) && $response->email ? $response->email : null;
90
    }
91 1
92
    /**
93
     * @see AbstractProvider::userScreenName
94
     */
95
    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...
96
    {
97 1
        return implode(" ", array($response->firstname, $response->lastname));
98
    }
99 1
100
    /**
101
     * @see AbstractProvider::getBaseAuthorizationUrl
102
     */
103
    public function getBaseAuthorizationUrl()
104
    {
105
        return 'https://www.strava.com/oauth/authorize';
106
    }
107
108
    /**
109
     * @see AbstractProvider::getBaseAccessTokenUrl
110
     */
111
    public function getBaseAccessTokenUrl(array $params)
112
    {
113
        return 'https://www.strava.com/oauth/token';
114
    }
115
116
    /**
117
     * @see AbstractProvider::getResourceOwnerDetailsUrl
118
     */
119
    public function getResourceOwnerDetailsUrl(AccessToken $token)
120
    {
121
        return '';
122
    }
123
124
125
    /**
126
     * @see AbstractProvider::getDefaultScopes
127
     */
128
    protected function getDefaultScopes()
129
    {
130
        return array('view_private', 'write');
131
    }
132
133
134
    /**
135
     * @see AbstractProvider::checkResponse
136
     */
137
    protected function checkResponse(ResponseInterface $response, $data)
138
    {
139
140
    }
141
142
    /**
143
     * @see AbstractProvider::createResourceOwner
144
     */
145
    protected function createResourceOwner(array $response, AccessToken $token)
146
    {
147
148
    }
149
}
150