Microsoft   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 2
cbo 4
dl 0
loc 104
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getBaseAuthorizationUrl() 0 4 1
A getBaseAccessTokenUrl() 0 4 1
A getDefaultScopes() 0 4 1
A checkResponse() 0 10 3
A createResourceOwner() 0 4 1
A getResourceOwnerDetailsUrl() 0 6 1
1
<?php namespace Stevenmaguire\OAuth2\Client\Provider;
2
3
use GuzzleHttp\Psr7\Uri;
4
use League\OAuth2\Client\Provider\AbstractProvider;
5
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
6
use League\OAuth2\Client\Token\AccessToken;
7
use Psr\Http\Message\ResponseInterface;
8
9
class Microsoft extends AbstractProvider
10
{
11
    /**
12
     * Default scopes
13
     *
14
     * @var array
15
     */
16
    public $defaultScopes = ['wl.basic', 'wl.emails'];
17
18
    /**
19
     * Base url for authorization.
20
     *
21
     * @var string
22
     */
23
    protected $urlAuthorize = 'https://login.live.com/oauth20_authorize.srf';
24
25
    /**
26
     * Base url for access token.
27
     *
28
     * @var string
29
     */
30
    protected $urlAccessToken = 'https://login.live.com/oauth20_token.srf';
31
32
    /**
33
     * Base url for resource owner.
34
     *
35
     * @var string
36
     */
37
    protected $urlResourceOwnerDetails = 'https://apis.live.net/v5.0/me';
38
39
    /**
40
     * Get authorization url to begin OAuth flow
41
     *
42
     * @return string
43
     */
44 12
    public function getBaseAuthorizationUrl()
45
    {
46 12
        return $this->urlAuthorize;
47
    }
48
49
    /**
50
     * Get access token url to retrieve token
51
     *
52
     * @return string
53
     */
54 18
    public function getBaseAccessTokenUrl(array $params)
55
    {
56 18
        return $this->urlAccessToken;
57
    }
58
59
    /**
60
     * Get default scopes
61
     *
62
     * @return array
63
     */
64 9
    protected function getDefaultScopes()
65
    {
66 9
        return $this->defaultScopes;
67
    }
68
69
    /**
70
     * Check a provider response for errors.
71
     *
72
     * @throws IdentityProviderException
73
     * @param  ResponseInterface $response
74
     * @return void
75
     */
76 12
    protected function checkResponse(ResponseInterface $response, $data)
77
    {
78 12
        if (isset($data['error'])) {
79 3
            throw new IdentityProviderException(
80 3
                (isset($data['error']['message']) ? $data['error']['message'] : $response->getReasonPhrase()),
81 3
                $response->getStatusCode(),
82 2
                $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...
83 1
            );
84
        }
85 9
    }
86
87
    /**
88
     * Generate a user object from a successful user details request.
89
     *
90
     * @param array $response
91
     * @param AccessToken $token
92
     * @return MicrosoftResourceOwner
93
     */
94 6
    protected function createResourceOwner(array $response, AccessToken $token)
95
    {
96 6
        return new MicrosoftResourceOwner($response);
97
    }
98 6
99
    /**
100 6
     * Get provider url to fetch user details
101
     *
102
     * @param  AccessToken $token
103
     *
104
     * @return string
105
     */
106
    public function getResourceOwnerDetailsUrl(AccessToken $token)
107
    {
108
        $uri = new Uri($this->urlResourceOwnerDetails);
109
110 9
        return (string) Uri::withQueryValue($uri, 'access_token', (string) $token);
111
    }
112
}
113