SinaWeibo   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 81.82%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 8
c 2
b 0
f 0
lcom 0
cbo 3
dl 0
loc 89
ccs 18
cts 22
cp 0.8182
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getBaseAuthorizationUrl() 0 4 1
A getBaseAccessTokenUrl() 0 11 1
A getResourceOwnerDetailsUrl() 0 4 1
A getDefaultScopes() 0 4 1
A checkResponse() 0 8 3
A createResourceOwner() 0 4 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: xiabin
5
 * Date: 16/6/24
6
 * Time: 下午7:12
7
 */
8
9
10
namespace Xiabin\OAuth2\Client\Provider;
11
12
use League\OAuth2\Client\Provider\AbstractProvider;
13
use Psr\Http\Message\ResponseInterface;
14
use GuzzleHttp\Client as HttpClient;
15
use Xiabin\OAuth2\Client\Provider\Exception;
16
use Xiabin\OAuth2\Client\Provider\Exception\SinaWeiboIdentityProviderException;
17
use League\OAuth2\Client\Token\AccessToken;
18
19
/**
20
 * Class SinaWeibo
21
 * @package League\OAuth2\Client\Provider
22
 */
23
class SinaWeibo extends AbstractProvider
24
{
25
26
27
    /**
28
     * Returns the base URL for authorizing a client.
29
     *
30
     * Eg. https://oauth.service.com/authorize
31
     *
32
     * @return string
33
     */
34 6
    public function getBaseAuthorizationUrl()
35
    {
36 6
        return "https://api.weibo.com/oauth2/authorize";
37
    }
38
39
    /**
40
     * Returns the base URL for requesting an access token.
41
     *
42
     * Eg. https://oauth.service.com/token
43
     *
44
     * @param array $params
45
     * @return string
46
     */
47 12
    public function getBaseAccessTokenUrl(array $params)
48
    {
49 12
        return 'https://api.weibo.com/oauth2/access_token?' . http_build_query([
50 12
            'client_id' => $params['client_id'],
51 12
            'client_secret' => $params['client_secret'],
52 12
            'grant_type' => $params['grant_type'],
53 12
            'redirect_uri' => $params['redirect_uri'],
54 12
            'code' => $params['code']
55 8
        ]);
56
57
    }
58
59
    /**
60
     * Returns the URL for requesting the resource owner's details.
61
     *
62
     * @param AccessToken $token
63
     * @return string
64
     */
65
    public function getResourceOwnerDetailsUrl(AccessToken $token)
66
    {
67
        // 暂不使用
68
    }
69
70
71
    /**
72
     * Returns the default scopes used by this provider.
73
     *
74
     * This should only be the scopes that are required to request the details
75
     * of the resource owner, rather than all the available scopes.
76
     *
77
     * @return array
78
     */
79 6
    protected function getDefaultScopes()
80
    {
81
        // 暂不使用
82 6
    }
83
84
    /**
85
     * Checks a provider response for errors.
86
     * @param ResponseInterface $response
87
     * @param array|string $data
88
     * @throws \League\OAuth2\Client\Provider\Exception\IdentityProviderException
89
     */
90 9
    protected function checkResponse(ResponseInterface $response, $data)
91
    {
92 9
        if ($response->getStatusCode() >= 400) {
93 3
            throw SinaWeiboIdentityProviderException::clientException($response, $data);
0 ignored issues
show
Bug introduced by
It seems like $data defined by parameter $data on line 90 can also be of type array; however, Xiabin\OAuth2\Client\Pro...tion::clientException() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
94 6
        } elseif (isset($data['error'])) {
95 3
            throw SinaWeiboIdentityProviderException::oauthException($response, $data);
0 ignored issues
show
Bug introduced by
It seems like $data defined by parameter $data on line 90 can also be of type array; however, Xiabin\OAuth2\Client\Pro...ption::oauthException() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
96
        }
97 3
    }
98
99
    /**
100
     * Generates a resource owner object from a successful resource owner
101
     * details request.
102
     *
103
     * @param  array $response
104
     * @param  AccessToken $token
105
     * @return \League\OAuth2\Client\Provider\ResourceOwnerInterface
106
     */
107
    protected function createResourceOwner(array $response, AccessToken $token)
108
    {
109
        // 暂不使用.
110
    }
111
}
112