Completed
Pull Request — master (#20)
by
unknown
03:17
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 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 1
1
§<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 15 and the first side effect is on line 1.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
namespace Strava\API;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Namespace declaration statement has to be the very first statement in the script
Loading history...
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
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(
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)
61
    {
62 1
        $user = new User;
63
64 1
        $user->exchangeArray(array(
65 1
            'uid' => $response->id,
66 1
            'name' => implode(" ", array($response->firstname, $response->lastname)),
67 1
            'firstName' => $response->firstname,
68 1
            'lastName' => $response->lastname,
69 1
            'email' => $response->email,
70 1
            'location' => $response->country,
71 1
            'imageUrl' => $response->profile,
72 1
            'gender' => $response->sex,
73 1
        ));
74
75 1
        return $user;
76
    }
77
78
    /**
79
     * @see AbstractProvider::userUid
80
     */
81 1
    public function userUid($response, AccessToken $token)
82
    {
83 1
        return $response->id;
84
    }
85
86
    /**
87
     * @see AbstractProvider::userUid
88
     */
89 1
    public function userEmail($response, AccessToken $token)
90
    {
91 1
        return isset($response->email) && $response->email ? $response->email : null;
92
    }
93
94
    /**
95
     * @see AbstractProvider::userScreenName
96
     */
97 1
    public function userScreenName($response, AccessToken $token)
98
    {
99 1
        return implode(" ", array($response->firstname, $response->lastname));
100
    }
101
}
102