diff --git a/.gitattributes b/.gitattributes index 96ceb731..b7189ff1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -11,3 +11,4 @@ /.github/CONTRIBUTING.md export-ignore /CHANGELOG.md export-ignore /README.md export-ignore +/pint.json export-ignore diff --git a/pint.json b/pint.json new file mode 100644 index 00000000..b5a32c81 --- /dev/null +++ b/pint.json @@ -0,0 +1,20 @@ +{ + "preset": "laravel", + "rules": { + "binary_operator_spaces": { + "operators": { + "=>": "align" + } + }, + "is_null": true, + "no_superfluous_elseif": true, + "no_superfluous_phpdoc_tags": false, + "no_useless_else": true, + "yoda_style": { + "always_move_variable": true, + "equal": false, + "identical": false, + "less_and_greater": false + } + } +} diff --git a/src/Exception/InvalidArgumentException.php b/src/Exception/InvalidArgumentException.php index ce04812a..116ea9a5 100644 --- a/src/Exception/InvalidArgumentException.php +++ b/src/Exception/InvalidArgumentException.php @@ -4,6 +4,4 @@ use InvalidArgumentException as BaseInvalidArgumentException; -class InvalidArgumentException extends BaseInvalidArgumentException -{ -} +class InvalidArgumentException extends BaseInvalidArgumentException {} diff --git a/src/Exception/MissingConfigException.php b/src/Exception/MissingConfigException.php index 3d8d0b62..68810af4 100644 --- a/src/Exception/MissingConfigException.php +++ b/src/Exception/MissingConfigException.php @@ -4,6 +4,4 @@ use Exception; -class MissingConfigException extends Exception -{ -} +class MissingConfigException extends Exception {} diff --git a/src/Helpers/ConfigRetriever.php b/src/Helpers/ConfigRetriever.php index f3c21471..a3b7560c 100644 --- a/src/Helpers/ConfigRetriever.php +++ b/src/Helpers/ConfigRetriever.php @@ -47,7 +47,7 @@ public function fromServices($providerName, array $additionalConfigKeys = []) $this->getFromServices('client_id'), $this->getFromServices('client_secret'), $this->getFromServices('redirect'), - $this->getConfigItems($additionalConfigKeys, fn($key) => $this->getFromServices(strtolower($key))) + $this->getConfigItems($additionalConfigKeys, fn ($key) => $this->getFromServices(strtolower($key))) ); } @@ -114,9 +114,9 @@ protected function getConfigFromServicesArray($providerName) // If we are running in console we should spoof values to make Socialite happy... if (app()->runningInConsole()) { $configArray = [ - 'client_id' => "{$this->providerIdentifier}_KEY", + 'client_id' => "{$this->providerIdentifier}_KEY", 'client_secret' => "{$this->providerIdentifier}_SECRET", - 'redirect' => "{$this->providerIdentifier}_REDIRECT_URI", + 'redirect' => "{$this->providerIdentifier}_REDIRECT_URI", ]; } else { throw new MissingConfigException("There is no services entry for $providerName"); diff --git a/src/OAuth1/AbstractProvider.php b/src/OAuth1/AbstractProvider.php index 2c44f3fa..712c5c3c 100644 --- a/src/OAuth1/AbstractProvider.php +++ b/src/OAuth1/AbstractProvider.php @@ -72,7 +72,7 @@ public function user() */ public function userFromTokenAndSecret($token, $secret) { - $tokenCredentials = new TokenCredentials(); + $tokenCredentials = new TokenCredentials; $tokenCredentials->setIdentifier($token); $tokenCredentials->setSecret($secret); @@ -172,8 +172,8 @@ protected function getToken() ]); return $this->server->getTokenCredentials( - $temp, $this->request->get('oauth_token'), $this->request->get('oauth_verifier') - ); + $temp, $this->request->get('oauth_token'), $this->request->get('oauth_verifier') + ); } /** diff --git a/src/OAuth2/AbstractProvider.php b/src/OAuth2/AbstractProvider.php index cff100b6..36beb5e0 100644 --- a/src/OAuth2/AbstractProvider.php +++ b/src/OAuth2/AbstractProvider.php @@ -26,13 +26,12 @@ abstract class AbstractProvider extends BaseProvider implements ProviderInterfac protected $user; /** - * @param string $providerName - * + * @param string $providerName * @return string */ public static function serviceContainerKey($providerName) { - return SocialiteWasCalled::SERVICE_CONTAINER_PREFIX . $providerName; + return SocialiteWasCalled::SERVICE_CONTAINER_PREFIX.$providerName; } /** @@ -47,7 +46,7 @@ public function user() } if ($this->hasInvalidState()) { - throw new InvalidStateException(); + throw new InvalidStateException; } $response = $this->getAccessTokenResponse($this->getCode()); @@ -70,8 +69,7 @@ public function user() /** * Get the access token from the token response body. * - * @param array $body - * + * @param array $body * @return string */ protected function parseAccessToken($body) @@ -82,8 +80,7 @@ protected function parseAccessToken($body) /** * Get the refresh token from the token response body. * - * @param array $body - * + * @param array $body * @return string */ protected function parseRefreshToken($body) @@ -94,8 +91,7 @@ protected function parseRefreshToken($body) /** * Get the expires in from the token response body. * - * @param array $body - * + * @param array $body * @return string */ protected function parseExpiresIn($body) @@ -106,15 +102,14 @@ protected function parseExpiresIn($body) /** * Get the approved scopes from the token response body. * - * @param array $body - * + * @param array $body * @return array */ protected function parseApprovedScopes($body) { $scopesRaw = Arr::get($body, 'scope', null); - if (!is_array($scopesRaw) && !is_string($scopesRaw)) { + if (! is_array($scopesRaw) && ! is_string($scopesRaw)) { return []; } diff --git a/src/ServiceProvider.php b/src/ServiceProvider.php index 1d1b1dc3..a3d33f49 100644 --- a/src/ServiceProvider.php +++ b/src/ServiceProvider.php @@ -40,7 +40,7 @@ public function register() } if (! $this->app->bound(ConfigRetrieverInterface::class)) { - $this->app->singleton(ConfigRetrieverInterface::class, fn() => new ConfigRetriever()); + $this->app->singleton(ConfigRetrieverInterface::class, fn () => new ConfigRetriever); } } } diff --git a/tests/ConfigRetrieverTest.php b/tests/ConfigRetrieverTest.php index 99d9187d..f3e54dcb 100644 --- a/tests/ConfigRetrieverTest.php +++ b/tests/ConfigRetrieverTest.php @@ -23,7 +23,7 @@ public function it_throws_if_there_is_a_problem_with_the_services_config(): void ->with("services.{$providerName}") ->once() ->andReturn(null); - $configRetriever = new ConfigRetriever(); + $configRetriever = new ConfigRetriever; $configRetriever->fromServices($providerName)->get(); } @@ -41,7 +41,7 @@ public function it_throws_if_there_are_missing_items_in_the_services_config(): v ->with("services.{$providerName}") ->once() ->andReturn([]); - $configRetriever = new ConfigRetriever(); + $configRetriever = new ConfigRetriever; $configRetriever->fromServices($providerName)->get(); } @@ -57,17 +57,17 @@ public function it_retrieves_a_config_from_the_services(): void $uri = 'uri'; $additionalConfigItem = 'test'; $config = [ - 'client_id' => $key, + 'client_id' => $key, 'client_secret' => $secret, - 'redirect' => $uri, - 'additional' => $additionalConfigItem, + 'redirect' => $uri, + 'additional' => $additionalConfigItem, ]; self::$functions ->shouldReceive('config') ->with("services.{$providerName}") ->once() ->andReturn($config); - $configRetriever = new ConfigRetriever(); + $configRetriever = new ConfigRetriever; $result = $configRetriever->fromServices($providerName, ['additional'])->get(); @@ -88,18 +88,18 @@ public function it_retrieves_a_config_from_the_services_with_guzzle(): void $uri = 'uri'; $additionalConfigItem = 'test'; $config = [ - 'client_id' => $key, + 'client_id' => $key, 'client_secret' => $secret, - 'redirect' => $uri, - 'additional' => $additionalConfigItem, - 'guzzle' => ['verify' => false], + 'redirect' => $uri, + 'additional' => $additionalConfigItem, + 'guzzle' => ['verify' => false], ]; self::$functions ->shouldReceive('config') ->with("services.{$providerName}") ->once() ->andReturn($config); - $configRetriever = new ConfigRetriever(); + $configRetriever = new ConfigRetriever; $result = $configRetriever->fromServices($providerName, ['additional'])->get(); @@ -127,7 +127,7 @@ function config($key) function app() { - return new applicationStub(); + return new applicationStub; } class applicationStub diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index 70e36ef0..9fe55d71 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -15,9 +15,9 @@ public function it_returns_a_config_array(): void $secret = 'secret'; $callbackUri = 'uri'; $result = [ - 'client_id' => $key, + 'client_id' => $key, 'client_secret' => $secret, - 'redirect' => $callbackUri, + 'redirect' => $callbackUri, ]; $config = new Config($key, $secret, $callbackUri); @@ -34,10 +34,10 @@ public function it_allows_additional_config_items(): void $secret = 'secret'; $callbackUri = 'uri'; $result = [ - 'client_id' => $key, + 'client_id' => $key, 'client_secret' => $secret, - 'redirect' => $callbackUri, - 'additional' => true, + 'redirect' => $callbackUri, + 'additional' => true, ]; $additional = ['additional' => true]; @@ -54,12 +54,12 @@ public function it_allows_closure_config_redirect() $key = 'key'; $secret = 'secret'; $callbackUri = 'uri'; - $callbackFunc = fn() => $callbackUri; + $callbackFunc = fn () => $callbackUri; $result = [ - 'client_id' => $key, + 'client_id' => $key, 'client_secret' => $secret, - 'redirect' => $callbackUri, - 'additional' => true, + 'redirect' => $callbackUri, + 'additional' => true, ]; $additional = ['additional' => true]; diff --git a/tests/ManagerTestTrait.php b/tests/ManagerTestTrait.php index 186a31f0..9f51d9e1 100644 --- a/tests/ManagerTestTrait.php +++ b/tests/ManagerTestTrait.php @@ -94,9 +94,9 @@ protected function configRetrieverMockWithDefaultExpectations($providerName, $pr protected function config(): array { return [ - 'client_id' => 'test', + 'client_id' => 'test', 'client_secret' => 'test', - 'redirect' => 'test', + 'redirect' => 'test', ]; } @@ -107,8 +107,8 @@ protected function config(): array protected function oauth1FormattedConfig(array $config): array { return [ - 'identifier' => $config['client_id'], - 'secret' => $config['client_secret'], + 'identifier' => $config['client_id'], + 'secret' => $config['client_secret'], 'callback_uri' => $config['redirect'], ]; } @@ -117,7 +117,7 @@ protected function oauth2ProviderStub(): MockInterface { static $provider = null; - if (is_null($provider)) { + if ($provider === null) { $provider = $this->mockStub('OAuth2ProviderStub')->shouldDeferMissing(); } @@ -128,7 +128,7 @@ protected function oauth1ProviderStub(): MockInterface { static $provider = null; - if (is_null($provider)) { + if ($provider === null) { $provider = $this->mockStub('OAuth1ProviderStub'); } diff --git a/tests/OAuth2ProviderTest.php b/tests/OAuth2ProviderTest.php index 40a2c853..2617e55e 100644 --- a/tests/OAuth2ProviderTest.php +++ b/tests/OAuth2ProviderTest.php @@ -21,7 +21,7 @@ class OAuth2ProviderTest extends TestCase */ public function it_throws_if_there_is_no_config_in_services_or_env(): void { - $this->expectExceptionObject(new MissingConfigException()); + $this->expectExceptionObject(new MissingConfigException); $providerName = 'bar'; $providerClass = $this->oauth2ProviderStubClass(); diff --git a/tests/OAuthTwoTest.php b/tests/OAuthTwoTest.php index 8a3b1763..7e651e8b 100644 --- a/tests/OAuthTwoTest.php +++ b/tests/OAuthTwoTest.php @@ -12,7 +12,6 @@ use SocialiteProviders\Manager\Test\Stubs\OAuthTwoTestProviderStub; use stdClass; use Symfony\Component\HttpFoundation\RedirectResponse; -use Symfony\Component\HttpFoundation\Session\SessionInterface; class OAuthTwoTest extends TestCase { @@ -54,7 +53,7 @@ public function userReturnsAUserInstanceForTheAuthenticatedRequest(): void $session = m::mock(SessionContract::class); $request = Request::create('foo', 'GET', [ 'state' => str_repeat('A', 40), - 'code' => 'code', + 'code' => 'code', ]); $request->setLaravelSession($session); $session @@ -72,11 +71,11 @@ public function userReturnsAUserInstanceForTheAuthenticatedRequest(): void 'Accept' => 'application/json', ], 'form_params' => [ - 'grant_type' => 'authorization_code', - 'client_id' => 'client_id', + 'grant_type' => 'authorization_code', + 'client_id' => 'client_id', 'client_secret' => 'client_secret', - 'code' => 'code', - 'redirect_uri' => 'redirect_uri', + 'code' => 'code', + 'redirect_uri' => 'redirect_uri', ], ]) ->andReturn($response = m::mock(stdClass::class)); @@ -98,7 +97,7 @@ public function access_token_response_body_is_accessible_from_user(): void $accessTokenResponseBody = '{"access_token": "access_token", "test": "test"}'; $request = Request::create('foo', 'GET', [ 'state' => str_repeat('A', 40), - 'code' => 'code', + 'code' => 'code', ]); $request->setLaravelSession($session); $session @@ -116,11 +115,11 @@ public function access_token_response_body_is_accessible_from_user(): void 'Accept' => 'application/json', ], 'form_params' => [ - 'grant_type' => 'authorization_code', - 'client_id' => 'client_id', + 'grant_type' => 'authorization_code', + 'client_id' => 'client_id', 'client_secret' => 'client_secret', - 'code' => 'code', - 'redirect_uri' => 'redirect_uri', + 'code' => 'code', + 'redirect_uri' => 'redirect_uri', ], ]) ->andReturn($response = m::mock(stdClass::class)); @@ -143,7 +142,7 @@ public function regular_laravel_socialite_class_works_as_well(): void $accessTokenResponseBody = '{"access_token": "access_token", "test": "test"}'; $request = Request::create('foo', 'GET', [ 'state' => str_repeat('A', 40), - 'code' => 'code', + 'code' => 'code', ]); $request->setLaravelSession($session); $session @@ -162,11 +161,11 @@ public function regular_laravel_socialite_class_works_as_well(): void 'Accept' => 'application/json', ], 'form_params' => [ - 'grant_type' => 'authorization_code', - 'client_id' => 'client_id', + 'grant_type' => 'authorization_code', + 'client_id' => 'client_id', 'client_secret' => 'client_secret', - 'code' => 'code', - 'redirect_uri' => 'redirect_uri', + 'code' => 'code', + 'redirect_uri' => 'redirect_uri', ], ]) ->andReturn($response = m::mock(stdClass::class)); @@ -184,12 +183,12 @@ public function regular_laravel_socialite_class_works_as_well(): void */ public function exceptionIsThrownIfStateIsInvalid(): void { - $this->expectExceptionObject(new InvalidStateException()); + $this->expectExceptionObject(new InvalidStateException); $session = m::mock(SessionContract::class); $request = Request::create('foo', 'GET', [ 'state' => str_repeat('B', 40), - 'code' => 'code', + 'code' => 'code', ]); $request->setLaravelSession($session); $session @@ -206,12 +205,12 @@ public function exceptionIsThrownIfStateIsInvalid(): void */ public function exceptionIsThrownIfStateIsNotSet(): void { - $this->expectExceptionObject(new InvalidStateException()); + $this->expectExceptionObject(new InvalidStateException); $session = m::mock(SessionContract::class); $request = Request::create('foo', 'GET', [ 'state' => 'state', - 'code' => 'code', + 'code' => 'code', ]); $request->setLaravelSession($session); $session @@ -231,7 +230,7 @@ public function userObjectShouldBeCachedOnFirstCall(): void $accessTokenResponseBody = '{"access_token": "access_token", "test": "test"}'; $request = Request::create('foo', 'GET', [ 'state' => str_repeat('A', 40), - 'code' => 'code', + 'code' => 'code', ]); $request->setLaravelSession($session); $session @@ -250,11 +249,11 @@ public function userObjectShouldBeCachedOnFirstCall(): void 'Accept' => 'application/json', ], 'form_params' => [ - 'grant_type' => 'authorization_code', - 'client_id' => 'client_id', + 'grant_type' => 'authorization_code', + 'client_id' => 'client_id', 'client_secret' => 'client_secret', - 'code' => 'code', - 'redirect_uri' => 'redirect_uri', + 'code' => 'code', + 'redirect_uri' => 'redirect_uri', ], ]) ->andReturn($response = m::mock(stdClass::class)); diff --git a/tests/Stubs/OAuth2ProviderStub.php b/tests/Stubs/OAuth2ProviderStub.php index 1aef9640..f5a0df11 100644 --- a/tests/Stubs/OAuth2ProviderStub.php +++ b/tests/Stubs/OAuth2ProviderStub.php @@ -7,6 +7,7 @@ class OAuth2ProviderStub extends AbstractProvider { protected $test = 'test'; + public const IDENTIFIER = 'TEST'; /** diff --git a/tests/Stubs/OAuthTwoTestProviderStub.php b/tests/Stubs/OAuthTwoTestProviderStub.php index d3d955fc..39658df6 100644 --- a/tests/Stubs/OAuthTwoTestProviderStub.php +++ b/tests/Stubs/OAuthTwoTestProviderStub.php @@ -35,7 +35,7 @@ protected function getUserByToken($token) protected function mapUserToObject(array $user) { - return (new User())->map(['id' => $user['id']]); + return (new User)->map(['id' => $user['id']]); } protected function getHttpClient() diff --git a/tests/UserTest.php b/tests/UserTest.php index 409266d4..ecc2d290 100644 --- a/tests/UserTest.php +++ b/tests/UserTest.php @@ -15,7 +15,7 @@ class UserTest extends TestCase public function we_should_be_able_to_set_the_credentials_body(): void { $credentialsBody = ['test']; - $user = (new User())->setAccessTokenResponseBody($credentialsBody); + $user = (new User)->setAccessTokenResponseBody($credentialsBody); $this->assertSame($user->accessTokenResponseBody, $credentialsBody); }