Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2fe592a

Browse files
committedJun 25, 2024·
refactor: 移除不必要的依赖
1 parent f7e6510 commit 2fe592a

15 files changed

+74
-78
lines changed
 

‎composer.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
"php": ">=8.0.2",
2626
"ext-json": "*",
2727
"ext-openssl": "*",
28-
"guzzlehttp/guzzle": "^7.0",
29-
"symfony/psr-http-message-bridge": "^2.1|^6.0|^7.1"
28+
"guzzlehttp/guzzle": "^7.0"
3029
},
3130
"require-dev": {
3231
"mockery/mockery": "^1.3",

‎src/Config.php

-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ class Config implements ArrayAccess, JsonSerializable
99
{
1010
protected array $config;
1111

12-
/**
13-
* @param array $config
14-
*/
1512
public function __construct(array $config)
1613
{
1714
$this->config = $config;

‎src/Exceptions/BadRequestException.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@
22

33
namespace Overtrue\Socialite\Exceptions;
44

5-
class BadRequestException extends Exception
6-
{
7-
}
5+
class BadRequestException extends Exception {}

‎src/Exceptions/FeiShu/InvalidTicketException.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@
44

55
use Overtrue\Socialite\Exceptions;
66

7-
class InvalidTicketException extends Exceptions\Exception
8-
{
9-
}
7+
class InvalidTicketException extends Exceptions\Exception {}

‎src/Providers/Base.php

+13-13
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,29 @@ abstract class Base implements Contracts\ProviderInterface
1515
{
1616
public const NAME = null;
1717

18-
protected ?string $state = null;
18+
protected ?string $state = null;
1919

20-
protected Config $config;
20+
protected Config $config;
2121

22-
protected ?string $redirectUrl;
22+
protected ?string $redirectUrl;
2323

24-
protected array $parameters = [];
24+
protected array $parameters = [];
2525

26-
protected array $scopes = [];
26+
protected array $scopes = [];
2727

28-
protected string $scopeSeparator = ',';
28+
protected string $scopeSeparator = ',';
2929

3030
protected GuzzleClient $httpClient;
3131

32-
protected array $guzzleOptions = [];
32+
protected array $guzzleOptions = [];
3333

34-
protected int $encodingType = PHP_QUERY_RFC1738;
34+
protected int $encodingType = PHP_QUERY_RFC1738;
3535

36-
protected string $expiresInKey = Contracts\RFC6749_ABNF_EXPIRES_IN;
36+
protected string $expiresInKey = Contracts\RFC6749_ABNF_EXPIRES_IN;
3737

38-
protected string $accessTokenKey = Contracts\RFC6749_ABNF_ACCESS_TOKEN;
38+
protected string $accessTokenKey = Contracts\RFC6749_ABNF_ACCESS_TOKEN;
3939

40-
protected string $refreshTokenKey = Contracts\RFC6749_ABNF_REFRESH_TOKEN;
40+
protected string $refreshTokenKey = Contracts\RFC6749_ABNF_REFRESH_TOKEN;
4141

4242
public function __construct(array $config)
4343
{
@@ -53,15 +53,15 @@ public function __construct(array $config)
5353
// normalize Contracts\RFC6749_ABNF_CLIENT_ID
5454
if (! $this->config->has(Contracts\RFC6749_ABNF_CLIENT_ID)) {
5555
$id = $this->config->get(Contracts\ABNF_APP_ID);
56-
if (null != $id) {
56+
if ($id != null) {
5757
$this->config->set(Contracts\RFC6749_ABNF_CLIENT_ID, $id);
5858
}
5959
}
6060

6161
// normalize Contracts\RFC6749_ABNF_CLIENT_SECRET
6262
if (! $this->config->has(Contracts\RFC6749_ABNF_CLIENT_SECRET)) {
6363
$secret = $this->config->get(Contracts\ABNF_APP_SECRET);
64-
if (null != $secret) {
64+
if ($secret != null) {
6565
$this->config->set(Contracts\RFC6749_ABNF_CLIENT_SECRET, $secret);
6666
}
6767
}

‎src/Providers/Coding.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class Coding extends Base
1313
{
14-
public const NAME = 'coding';
14+
public const NAME = 'coding';
1515

1616
// example: https://{your-team}.coding.net
1717
protected string $teamUrl;

‎src/Providers/Douban.php

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ protected function getTokenUrl(): string
2525
}
2626

2727
/**
28-
* @param string $token
2928
* @param ?array $query
3029
*/
3130
protected function getUserByToken(string $token, ?array $query = []): array

‎src/Providers/Facebook.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Facebook extends Base
1717

1818
protected string $version = 'v3.3';
1919

20-
protected array $fields = ['first_name', 'last_name', 'email', 'gender', 'verified','picture'];
20+
protected array $fields = ['first_name', 'last_name', 'email', 'gender', 'verified', 'picture'];
2121

2222
protected array $scopes = [];
2323

‎src/Providers/FeiShu.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class FeiShu extends Base
2121

2222
protected string $expiresInKey = 'refresh_expires_in';
2323

24-
protected bool $isInternalApp = false;
24+
protected bool $isInternalApp = false;
2525

2626
public function __construct(array $config)
2727
{

‎src/Providers/GitHub.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
class GitHub extends Base
1111
{
12-
public const NAME = 'github';
12+
public const NAME = 'github';
1313

14-
protected array $scopes = ['read:user'];
14+
protected array $scopes = ['read:user'];
1515

1616
protected string $scopeSeparator = ' ';
1717

‎src/Providers/Linkedin.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected function getBasicProfile(string $token): array
5151

5252
$response = $this->getHttpClient()->get($url, [
5353
'headers' => [
54-
'Authorization' => 'Bearer ' . $token,
54+
'Authorization' => 'Bearer '.$token,
5555
'X-RestLi-Protocol-Version' => '2.0.0',
5656
],
5757
]);
@@ -65,7 +65,7 @@ protected function getEmailAddress(string $token): array
6565

6666
$response = $this->getHttpClient()->get($url, [
6767
'headers' => [
68-
'Authorization' => 'Bearer ' . $token,
68+
'Authorization' => 'Bearer '.$token,
6969
'X-RestLi-Protocol-Version' => '2.0.0',
7070
],
7171
]);
@@ -75,11 +75,11 @@ protected function getEmailAddress(string $token): array
7575

7676
protected function mapUserToObject(array $user): Contracts\UserInterface
7777
{
78-
$preferredLocale = ($user['firstName']['preferredLocale']['language'] ?? null) . '_' .
78+
$preferredLocale = ($user['firstName']['preferredLocale']['language'] ?? null).'_'.
7979
($user['firstName']['preferredLocale']['country'] ?? null);
8080
$firstName = $user['firstName']['localized'][$preferredLocale] ?? null;
8181
$lastName = $user['lastName']['localized'][$preferredLocale] ?? null;
82-
$name = $firstName . ' ' . $lastName;
82+
$name = $firstName.' '.$lastName;
8383

8484
$images = $user['profilePicture']['displayImage~']['elements'] ?? [];
8585
$avatars = \array_filter($images, static fn ($image) => ($image['data']['com.linkedin.digitalmedia.mediaartifact.StillImage']['storageSize']['width'] ?? 0) === 100);

‎src/Providers/PayPal.php

+46-39
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,57 @@
88

99
/**
1010
* Class PayPal
11+
*
1112
* @author zhiqiang
12-
* @package Overtrue\Socialite\Providers
13+
*
1314
* @see https://developer.paypal.com/docs/log-in-with-paypal/
1415
*/
1516
class PayPal extends Base
1617
{
1718
public const NAME = 'paypal';
1819

1920
protected string $scopeSeparator = ' ';
21+
2022
/**
2123
* @var string|null
22-
* code or id_token
24+
* code or id_token
2325
*/
2426
protected ?string $responseType = Contracts\RFC6749_ABNF_CODE;
25-
protected string $flowEntry = 'static';
2627

27-
protected string $authUrl = 'https://www.paypal.com/signin/authorize';
28-
protected string $tokenURL = "https://api.sandbox.paypal.com/v1/oauth2/token";
29-
protected string $userinfoURL = "https://api.paypal.com/v1/identity/openidconnect/userinfo";
28+
protected string $flowEntry = 'static';
29+
30+
protected string $authUrl = 'https://www.paypal.com/signin/authorize';
31+
32+
protected string $tokenURL = 'https://api.sandbox.paypal.com/v1/oauth2/token';
33+
34+
protected string $userinfoURL = 'https://api.paypal.com/v1/identity/openidconnect/userinfo';
3035

3136
protected array $scopes = [
32-
'openid', 'profile', 'email', 'address'
37+
'openid', 'profile', 'email', 'address',
3338
];
3439

3540
protected bool $sandbox = true;
3641

3742
public function __construct(array $config)
3843
{
3944
parent::__construct($config);
40-
$this->sandbox = (bool)$this->config->get('sandbox', false);
45+
$this->sandbox = (bool) $this->config->get('sandbox', false);
4146
if ($this->sandbox) {
42-
$this->authUrl = 'https://www.sandbox.paypal.com/signin/authorize';
43-
$this->tokenURL = 'https://api-m.sandbox.paypal.com/v1/oauth2/token';
47+
$this->authUrl = 'https://www.sandbox.paypal.com/signin/authorize';
48+
$this->tokenURL = 'https://api-m.sandbox.paypal.com/v1/oauth2/token';
4449
$this->userinfoURL = 'https://api-m.sandbox.paypal.com/v1/identity/openidconnect/userinfo';
4550
}
4651
}
4752

4853
/**
49-
* @param string|null $responseType
5054
* @return $this
55+
*
5156
* @see https://developer.paypal.com/docs/log-in-with-paypal/integrate/generate-button/
5257
*/
5358
public function withResponseType(?string $responseType)
5459
{
5560
$this->responseType = $responseType;
61+
5662
return $this;
5763
}
5864

@@ -65,32 +71,31 @@ protected function getCodeFields(): array
6571
{
6672
$fields = \array_merge(
6773
[
68-
'flowEntry' => $this->flowEntry,
69-
Contracts\RFC6749_ABNF_CLIENT_ID => $this->getClientId(),
74+
'flowEntry' => $this->flowEntry,
75+
Contracts\RFC6749_ABNF_CLIENT_ID => $this->getClientId(),
7076
Contracts\RFC6749_ABNF_RESPONSE_TYPE => $this->responseType,
71-
Contracts\RFC6749_ABNF_SCOPE => $this->formatScopes($this->scopes, $this->scopeSeparator),
72-
Contracts\RFC6749_ABNF_REDIRECT_URI => $this->redirectUrl,
77+
Contracts\RFC6749_ABNF_SCOPE => $this->formatScopes($this->scopes, $this->scopeSeparator),
78+
Contracts\RFC6749_ABNF_REDIRECT_URI => $this->redirectUrl,
7379
],
7480
$this->parameters
7581
);
7682

7783
if ($this->state) {
7884
$fields[Contracts\RFC6749_ABNF_STATE] = $this->state;
7985
}
86+
8087
return $fields;
8188
}
8289

83-
8490
protected function getTokenUrl(): string
8591
{
8692
return $this->tokenURL;
8793
}
8894

8995
/**
90-
* @param string $code
91-
* @return array
9296
* @throws \GuzzleHttp\Exception\GuzzleException
9397
* @throws \Overtrue\Socialite\Exceptions\AuthorizeFailedException
98+
*
9499
* @see https://developer.paypal.com/docs/log-in-with-paypal/integrate/#link-getaccesstoken
95100
*/
96101
public function tokenFromCode(string $code): array
@@ -100,46 +105,46 @@ public function tokenFromCode(string $code): array
100105
[
101106
'form_params' => [
102107
Contracts\RFC6749_ABNF_GRANT_TYPE => Contracts\RFC6749_ABNF_AUTHORATION_CODE,
103-
Contracts\RFC6749_ABNF_CODE => $code,
108+
Contracts\RFC6749_ABNF_CODE => $code,
104109
],
105-
'headers' => [
106-
'Accept' => 'application/json',
107-
'Authorization' => 'Basic ' . \base64_encode(\sprintf('%s:%s', $this->getClientId(), $this->getClientSecret())),
110+
'headers' => [
111+
'Accept' => 'application/json',
112+
'Authorization' => 'Basic '.\base64_encode(\sprintf('%s:%s', $this->getClientId(), $this->getClientSecret())),
108113
],
109114
]
110115
);
111-
return $this->normalizeAccessTokenResponse((string)$response->getBody());
116+
117+
return $this->normalizeAccessTokenResponse((string) $response->getBody());
112118
}
113119

114120
/**
115-
* @param string $refreshToken
116-
* @return mixed
117121
* @throws \GuzzleHttp\Exception\GuzzleException
118122
* @throws \Overtrue\Socialite\Exceptions\AuthorizeFailedException
123+
*
119124
* @see https://developer.paypal.com/docs/log-in-with-paypal/integrate/#link-exchangerefreshtokenforaccesstoken
120125
*/
121126
public function refreshToken(string $refreshToken): mixed
122127
{
123-
$response = $this->getHttpClient()->post(
128+
$response = $this->getHttpClient()->post(
124129
$this->getTokenUrl(),
125130
[
126131
'form_params' => [
127-
Contracts\RFC6749_ABNF_GRANT_TYPE => Contracts\RFC6749_ABNF_REFRESH_TOKEN,
132+
Contracts\RFC6749_ABNF_GRANT_TYPE => Contracts\RFC6749_ABNF_REFRESH_TOKEN,
128133
Contracts\RFC6749_ABNF_REFRESH_TOKEN => $refreshToken,
129134
],
130-
'headers' => [
131-
'Accept' => 'application/json',
132-
'Authorization' => 'Basic ' . \base64_encode(\sprintf('%s:%s', $this->getClientId(), $this->getClientSecret())),
135+
'headers' => [
136+
'Accept' => 'application/json',
137+
'Authorization' => 'Basic '.\base64_encode(\sprintf('%s:%s', $this->getClientId(), $this->getClientSecret())),
133138
],
134139
]
135140
);
136-
return $this->normalizeAccessTokenResponse((string)$response->getBody());
141+
142+
return $this->normalizeAccessTokenResponse((string) $response->getBody());
137143
}
138144

139145
/**
140-
* @param string $token
141-
* @return array
142146
* @throws \GuzzleHttp\Exception\GuzzleException
147+
*
143148
* @see https://developer.paypal.com/docs/api/identity/v1/#userinfo_get
144149
*/
145150
protected function getUserByToken(string $token): array
@@ -148,22 +153,24 @@ protected function getUserByToken(string $token): array
148153
$this->userinfoURL,
149154
[
150155
'headers' => [
151-
'Content-Type' => 'application/x-www-form-urlencoded',
152-
'Authorization' => 'Bearer ' . $token,
156+
'Content-Type' => 'application/x-www-form-urlencoded',
157+
'Authorization' => 'Bearer '.$token,
153158
],
154159
]
155160
);
161+
156162
return $this->fromJsonBody($response);
157163
}
158164

159165
#[Pure]
160166
protected function mapUserToObject(array $user): Contracts\UserInterface
161167
{
162-
$user[Contracts\ABNF_ID] = $user['user_id'] ?? null;
168+
$user[Contracts\ABNF_ID] = $user['user_id'] ?? null;
163169
$user[Contracts\ABNF_NICKNAME] = $user['given_name'] ?? $user['family_name'] ?? $user['middle_name'] ?? null;
164-
$user[Contracts\ABNF_NAME] = $user['name'] ?? '';
165-
$user[Contracts\ABNF_EMAIL] = $user[Contracts\ABNF_EMAIL] ?? null;
166-
$user[Contracts\ABNF_AVATAR] = $user['picture'] ?? null;
170+
$user[Contracts\ABNF_NAME] = $user['name'] ?? '';
171+
$user[Contracts\ABNF_EMAIL] = $user[Contracts\ABNF_EMAIL] ?? null;
172+
$user[Contracts\ABNF_AVATAR] = $user['picture'] ?? null;
173+
167174
return new User($user);
168175
}
169176
}

‎src/Providers/WeChat.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,11 @@ protected function prepareForComponent(array $component): void
205205
}
206206
}
207207

208-
if (2 !== \count($config)) {
208+
if (\count($config) !== 2) {
209209
throw new Exceptions\InvalidArgumentException('Please check your config arguments were available.');
210210
}
211211

212-
if (1 === \count($this->scopes) && \in_array('snsapi_login', $this->scopes)) {
212+
if (\count($this->scopes) === 1 && \in_array('snsapi_login', $this->scopes)) {
213213
$this->scopes = ['snsapi_base'];
214214
}
215215

‎src/Traits/HasAttributes.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function toJSON(): string
6868
{
6969
$result = \json_encode($this->getAttributes(), JSON_UNESCAPED_UNICODE);
7070

71-
false === $result && throw new Exceptions\Exception('Cannot Processing this instance as JSON stringify.');
71+
$result === false && throw new Exceptions\Exception('Cannot Processing this instance as JSON stringify.');
7272

7373
return $result;
7474
}

0 commit comments

Comments
 (0)
Please sign in to comment.