These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace League\OAuth2\Client\Provider; |
||
4 | |||
5 | use League\OAuth2\Client\Provider\Exception\IdentityProviderException; |
||
6 | use League\OAuth2\Client\Token\AccessToken; |
||
7 | use League\OAuth2\Client\Tool\BearerAuthorizationTrait; |
||
8 | use Psr\Http\Message\ResponseInterface; |
||
9 | |||
10 | class Github extends AbstractProvider |
||
11 | { |
||
12 | use BearerAuthorizationTrait; |
||
13 | |||
14 | /** |
||
15 | * Domain |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | public $domain = 'https://github.com'; |
||
20 | |||
21 | /** |
||
22 | * Api domain |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | public $apiDomain = 'https://api.github.com'; |
||
27 | |||
28 | /** |
||
29 | * Get authorization url to begin OAuth flow |
||
30 | * |
||
31 | * @return string |
||
32 | */ |
||
33 | 12 | public function getBaseAuthorizationUrl() |
|
34 | { |
||
35 | 12 | return $this->domain.'/login/oauth/authorize'; |
|
36 | } |
||
37 | |||
38 | /** |
||
39 | * Get access token url to retrieve token |
||
40 | * |
||
41 | * @param array $params |
||
42 | * |
||
43 | * @return string |
||
44 | */ |
||
45 | 18 | public function getBaseAccessTokenUrl(array $params) |
|
46 | { |
||
47 | 18 | return $this->domain.'/login/oauth/access_token'; |
|
48 | } |
||
49 | |||
50 | /** |
||
51 | * Get provider url to fetch user details |
||
52 | * |
||
53 | * @param AccessToken $token |
||
54 | * |
||
55 | * @return string |
||
56 | */ |
||
57 | 6 | public function getResourceOwnerDetailsUrl(AccessToken $token) |
|
58 | { |
||
59 | 6 | if ($this->domain === 'https://github.com') { |
|
60 | 3 | return $this->apiDomain.'/user'; |
|
61 | } |
||
62 | 3 | return $this->domain.'/api/v3/user'; |
|
63 | } |
||
64 | |||
65 | /** |
||
66 | * Get the default scopes used by this provider. |
||
67 | * |
||
68 | * This should not be a complete list of all scopes, but the minimum |
||
69 | * required for the provider user interface! |
||
70 | * |
||
71 | * @return array |
||
72 | */ |
||
73 | 6 | protected function getDefaultScopes() |
|
74 | { |
||
75 | 6 | return []; |
|
76 | } |
||
77 | |||
78 | /** |
||
79 | * Check a provider response for errors. |
||
80 | * |
||
81 | * @link https://developer.github.com/v3/#client-errors |
||
82 | * @throws IdentityProviderException |
||
83 | * @param ResponseInterface $response |
||
84 | * @param string $data Parsed response data |
||
85 | * @return void |
||
86 | */ |
||
87 | 15 | protected function checkResponse(ResponseInterface $response, $data) |
|
88 | { |
||
89 | 15 | if ($response->getStatusCode() >= 400) { |
|
90 | 3 | $errorMessage = isset($data['message']) ? $data['message'] : $response->getReasonPhrase(); |
|
91 | 3 | throw new IdentityProviderException($errorMessage, $response->getStatusCode(), $response); |
|
0 ignored issues
–
show
|
|||
92 | 12 | } elseif (isset($data['error'], $data['error_description'])) { |
|
93 | 3 | $errorMessage = $data['error'] . ': ' . $data['error_description']; |
|
94 | 3 | throw new IdentityProviderException($errorMessage, $response->getStatusCode(), $response); |
|
0 ignored issues
–
show
$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...
|
|||
95 | } |
||
96 | 9 | } |
|
97 | |||
98 | /** |
||
99 | * Generate a user object from a successful user details request. |
||
100 | * |
||
101 | * @param array $response |
||
102 | * @param AccessToken $token |
||
103 | * @return League\OAuth2\Client\Provider\ResourceOwnerInterface |
||
104 | */ |
||
105 | 3 | protected function createResourceOwner(array $response, AccessToken $token) |
|
106 | { |
||
107 | 3 | $user = new GithubResourceOwner($response); |
|
108 | |||
109 | 3 | return $user->setDomain($this->domain); |
|
110 | } |
||
111 | } |
||
112 |
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: