Skip to content

Commit

Permalink
Fix style with pint (#232)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmichot authored Nov 7, 2024
1 parent ab8588a commit 8ce66f5
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 81 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
/.github/CONTRIBUTING.md export-ignore
/CHANGELOG.md export-ignore
/README.md export-ignore
/pint.json export-ignore
20 changes: 20 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -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
}
}
}
4 changes: 1 addition & 3 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

use InvalidArgumentException as BaseInvalidArgumentException;

class InvalidArgumentException extends BaseInvalidArgumentException
{
}
class InvalidArgumentException extends BaseInvalidArgumentException {}
4 changes: 1 addition & 3 deletions src/Exception/MissingConfigException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@

use Exception;

class MissingConfigException extends Exception
{
}
class MissingConfigException extends Exception {}
6 changes: 3 additions & 3 deletions src/Helpers/ConfigRetriever.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
);
}

Expand Down Expand Up @@ -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");
Expand Down
6 changes: 3 additions & 3 deletions src/OAuth1/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function user()
*/
public function userFromTokenAndSecret($token, $secret)
{
$tokenCredentials = new TokenCredentials();
$tokenCredentials = new TokenCredentials;

$tokenCredentials->setIdentifier($token);
$tokenCredentials->setSecret($secret);
Expand Down Expand Up @@ -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')
);
}

/**
Expand Down
21 changes: 8 additions & 13 deletions src/OAuth2/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -47,7 +46,7 @@ public function user()
}

if ($this->hasInvalidState()) {
throw new InvalidStateException();
throw new InvalidStateException;
}

$response = $this->getAccessTokenResponse($this->getCode());
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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 [];
}

Expand Down
2 changes: 1 addition & 1 deletion src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
24 changes: 12 additions & 12 deletions tests/ConfigRetrieverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand All @@ -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();

Expand All @@ -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();

Expand Down Expand Up @@ -127,7 +127,7 @@ function config($key)

function app()
{
return new applicationStub();
return new applicationStub;
}

class applicationStub
Expand Down
18 changes: 9 additions & 9 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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];

Expand All @@ -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];

Expand Down
12 changes: 6 additions & 6 deletions tests/ManagerTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
];
}

Expand All @@ -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'],
];
}
Expand All @@ -117,7 +117,7 @@ protected function oauth2ProviderStub(): MockInterface
{
static $provider = null;

if (is_null($provider)) {
if ($provider === null) {
$provider = $this->mockStub('OAuth2ProviderStub')->shouldDeferMissing();
}

Expand All @@ -128,7 +128,7 @@ protected function oauth1ProviderStub(): MockInterface
{
static $provider = null;

if (is_null($provider)) {
if ($provider === null) {
$provider = $this->mockStub('OAuth1ProviderStub');
}

Expand Down
2 changes: 1 addition & 1 deletion tests/OAuth2ProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading

0 comments on commit 8ce66f5

Please sign in to comment.