Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a coding standards GA to fix code with Laravel Pint. #221

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
# Ignore all test and documentation with "export-ignore".
/.gitattributes export-ignore
/.gitignore export-ignore
/.styleci.yml export-ignore
/phpunit.xml.dist export-ignore
/.scrutinizer.yml export-ignore
/tests export-ignore
Expand Down
31 changes: 31 additions & 0 deletions .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Fix code styling

on: [ push ]

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout the code
uses: actions/checkout@v3
with:
token: ${{ secrets.PAT }}

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ inputs.php }}
extensions: json, dom, curl, libxml, mbstring
coverage: none

- name: Install Pint
run: composer global require laravel/pint

- name: Run Pint
run: pint

- name: Commit linted files
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "Apply code styling fixes"
1 change: 0 additions & 1 deletion .styleci.yml

This file was deleted.

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
}
}
}
6 changes: 3 additions & 3 deletions src/Helpers/ConfigRetriever.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
$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 @@ -112,9 +112,9 @@
// 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",

Check warning on line 115 in src/Helpers/ConfigRetriever.php

View check run for this annotation

Codecov / codecov/patch

src/Helpers/ConfigRetriever.php#L115

Added line #L115 was not covered by tests
'client_secret' => "{$this->providerIdentifier}_SECRET",
'redirect' => "{$this->providerIdentifier}_REDIRECT_URI",
'redirect' => "{$this->providerIdentifier}_REDIRECT_URI",

Check warning on line 117 in src/Helpers/ConfigRetriever.php

View check run for this annotation

Codecov / codecov/patch

src/Helpers/ConfigRetriever.php#L117

Added line #L117 was not covered by tests
];
} else {
throw new MissingConfigException("There is no services entry for $providerName");
Expand Down
4 changes: 2 additions & 2 deletions src/OAuth1/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@
]);

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')
);

Check warning on line 176 in src/OAuth1/AbstractProvider.php

View check run for this annotation

Codecov / codecov/patch

src/OAuth1/AbstractProvider.php#L175-L176

Added lines #L175 - L176 were not covered by tests
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/OAuth2/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ public function user()
}

return $this->user->setToken($token)
->setRefreshToken($this->parseRefreshToken($response))
->setExpiresIn($this->parseExpiresIn($response));
->setRefreshToken($this->parseRefreshToken($response))
->setExpiresIn($this->parseExpiresIn($response));
}

/**
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 @@
}

if (! $this->app->bound(ConfigRetrieverInterface::class)) {
$this->app->singleton(ConfigRetrieverInterface::class, fn() => new ConfigRetriever());
$this->app->singleton(ConfigRetrieverInterface::class, fn () => new ConfigRetriever());

Check warning on line 43 in src/ServiceProvider.php

View check run for this annotation

Codecov / codecov/patch

src/ServiceProvider.php#L43

Added line #L43 was not covered by tests
}
}
}
6 changes: 3 additions & 3 deletions tests/ConfigRetrieverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ 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')
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
44 changes: 22 additions & 22 deletions tests/OAuthTwoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function userReturnsAUserInstanceForTheAuthenticatedRequest(): void
$session = m::mock(SessionInterface::class);
$request = Request::create('foo', 'GET', [
'state' => str_repeat('A', 40),
'code' => 'code',
'code' => 'code',
]);
$request->setSession($session);
$session
Expand All @@ -72,11 +72,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));
Expand All @@ -98,7 +98,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->setSession($session);
$session
Expand All @@ -116,11 +116,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));
Expand All @@ -143,7 +143,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->setSession($session);
$session
Expand All @@ -162,11 +162,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));
Expand All @@ -189,7 +189,7 @@ public function exceptionIsThrownIfStateIsInvalid(): void
$session = m::mock(SessionInterface::class);
$request = Request::create('foo', 'GET', [
'state' => str_repeat('B', 40),
'code' => 'code',
'code' => 'code',
]);
$request->setSession($session);
$session
Expand All @@ -211,7 +211,7 @@ public function exceptionIsThrownIfStateIsNotSet(): void
$session = m::mock(SessionInterface::class);
$request = Request::create('foo', 'GET', [
'state' => 'state',
'code' => 'code',
'code' => 'code',
]);
$request->setSession($session);
$session
Expand All @@ -231,7 +231,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->setSession($session);
$session
Expand All @@ -250,11 +250,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));
Expand Down
1 change: 1 addition & 0 deletions tests/Stubs/OAuth2ProviderStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class OAuth2ProviderStub extends AbstractProvider
{
protected $test = 'test';

public const IDENTIFIER = 'TEST';

/**
Expand Down