Skip to content

Commit

Permalink
refactor: add laravel pint to lint php files (#448)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored Sep 8, 2023
1 parent 7ea4c1d commit 701b992
Show file tree
Hide file tree
Showing 19 changed files with 84 additions and 23 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/lint_php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: PHP linting (Pint)

on:
pull_request:
types: [opened, synchronize, reopened]

concurrency:
group: Lint php ${{ github.ref }}
cancel-in-progress: true


jobs:
phplint:
runs-on: ubuntu-latest
name: PHP linting (Pint)

strategy:
fail-fast: false

steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Get pint version
id: pint
run: |
echo "version=$(composer show laravel/pint --locked --format=json | jq -r '.versions[0]' | sed 's/v//')" >> $GITHUB_OUTPUT
- name: laravel-pint
uses: aglipanci/laravel-pint-action@2.3.0
with:
configPath: pint.json
pintVersion: ${{ steps.pint.outputs.version }}

- name: Check if there is any file update needed
run: |
status=$(git status --porcelain)
if [ -n "$status" ]; then
echo -e "Waiting modifications:\n$status"
echo "::error::Laravel pint found fixes. Please run 'vendor/bin/pint' prior to your next commit."
exit -1
fi
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
.phpunit.result.cache
.phpunit.cache
composer.lock
cghooks.lock

19 changes: 18 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@
"ext-sqlite3": "*",
"guzzlehttp/psr7": "^2.1",
"laravel/legacy-factories": "^1.0",
"laravel/pint": "^1.13",
"nunomaduro/larastan": "^2.0",
"ocramius/package-versions": "^2.0",
"orchestra/testbench": "^7.0 || ^8.0",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan-strict-rules": "^1.0",
"phpunit/phpunit": "^9.5 || ^10.0"
"phpunit/phpunit": "^9.5 || ^10.0",
"xheaven/composer-git-hooks": "^3.1"
},
"suggest": {
"guzzlehttp/psr7": "To provide a psr/http-factory-implementation implementation",
Expand All @@ -67,8 +69,23 @@
"providers": [
"LaravelWebauthn\\WebauthnServiceProvider"
]
},
"hooks": {
"config": {
"stop-on-failure": [
"pre-commit"
]
},
"pre-commit": [
"files=$(git diff --staged --name-only);\"$(dirname \"$0\")/../../vendor/bin/pint\" $files; git add $files"
]
}
},
"scripts": {
"cghooks": "vendor/bin/cghooks",
"post-install-cmd": "cghooks add --ignore-lock",
"post-update-cmd": "cghooks update"
},
"config": {
"sort-packages": true,
"allow-plugins": {
Expand Down
8 changes: 8 additions & 0 deletions pint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"preset": "laravel",
"rules": {
"single_import_per_statement": {
"group_to_single_imports": false
}
}
}
2 changes: 1 addition & 1 deletion src/Actions/AttemptToAuthenticate.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected function throwFailedAuthenticationException(Request $request): void
/**
* Fire the failed authentication attempt event with the given arguments.
*/
protected function fireFailedEvent(Request $request, ?User $user = null): void
protected function fireFailedEvent(Request $request, User $user = null): void
{
event(new Failed(config('webauthn.guard'), $user, [
Webauthn::username() => $user !== null
Expand Down
2 changes: 1 addition & 1 deletion src/Actions/PrepareCreationData.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __invoke(User $user): PublicKeyCredentialCreationOptions
*
* @throws \Illuminate\Validation\ValidationException
*/
protected function throwFailedRegisterException(User $user, ?Exception $e = null): void
protected function throwFailedRegisterException(User $user, Exception $e = null): void
{
WebauthnRegisterFailed::dispatch($user, $e);

Expand Down
2 changes: 1 addition & 1 deletion src/Actions/ValidateKeyCreation.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected function validateAttestation(User $user, array $data, string $keyName)
*
* @throws \Illuminate\Validation\ValidationException
*/
protected function throwFailedRegisterException(User $user, ?Exception $e = null): void
protected function throwFailedRegisterException(User $user, Exception $e = null): void
{
WebauthnRegisterFailed::dispatch($user, $e);

Expand Down
2 changes: 1 addition & 1 deletion src/Events/WebauthnLogin.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class WebauthnLogin
{
use SerializesModels, Dispatchable;
use Dispatchable, SerializesModels;

/**
* Create a new event instance.
Expand Down
2 changes: 1 addition & 1 deletion src/Events/WebauthnLoginData.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class WebauthnLoginData
{
use SerializesModels, Dispatchable;
use Dispatchable, SerializesModels;

/**
* Create a new event instance.
Expand Down
2 changes: 1 addition & 1 deletion src/Events/WebauthnRegister.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class WebauthnRegister
{
use SerializesModels, Dispatchable;
use Dispatchable, SerializesModels;

/**
* Create a new event instance.
Expand Down
2 changes: 1 addition & 1 deletion src/Events/WebauthnRegisterData.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class WebauthnRegisterData
{
use SerializesModels, Dispatchable;
use Dispatchable, SerializesModels;

/**
* Create a new event instance.
Expand Down
2 changes: 1 addition & 1 deletion src/Events/WebauthnRegisterFailed.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class WebauthnRegisterFailed
{
use SerializesModels, Dispatchable;
use Dispatchable, SerializesModels;

/**
* Create a new event instance.
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Middleware/WebauthnMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function __construct(
/**
* Handle an incoming request.
*/
public function handle(Request $request, Closure $next, ?string $guard = null): mixed
public function handle(Request $request, Closure $next, string $guard = null): mixed
{
if (Webauthn::webauthnEnabled() && ! Webauthn::check()) {
abort_if($this->auth->guard($guard)->guest(), 401, /** @var string $m */ $m = trans('webauthn::errors.user_unauthenticated'));
Expand Down
3 changes: 0 additions & 3 deletions src/Http/Responses/LoginSuccessResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ public function toResponse($request)

/**
* Create an HTTP response that represents the object.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
protected function jsonResponse(Request $request): \Symfony\Component\HttpFoundation\Response
{
Expand Down
2 changes: 1 addition & 1 deletion src/Models/WebauthnKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function publicKeyCredentialSource(): Attribute
(string) $this->user_id,
$this->counter
),
set: function (PublicKeyCredentialSource $value, ?array $attributes = null): array {
set: function (PublicKeyCredentialSource $value, array $attributes = null): array {
if (((string) Arr::get($attributes, 'user_id')) !== $value->getUserHandle()) {
throw new WrongUserHandleException();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Services/Webauthn/CredentialAssertionValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected function getCredentialSource(User $user, PublicKeyCredential $publicKe

return (Webauthn::model())::where('user_id', $user->getAuthIdentifier())
->where(fn ($query) => $query->where('credentialId', Base64UrlSafe::encode($credentialId))
->orWhere('credentialId', Base64UrlSafe::encodeUnpadded($credentialId))
->orWhere('credentialId', Base64UrlSafe::encodeUnpadded($credentialId))
)
->firstOrFail()
->publicKeyCredentialSource;
Expand Down
4 changes: 0 additions & 4 deletions src/Services/Webauthn/RequestOptionsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ final class RequestOptionsFactory extends OptionsFactory
{
/**
* User verification preference.
*
* @var string|null
*/
protected ?string $userVerification;

Expand Down Expand Up @@ -68,8 +66,6 @@ private function getAllowedCredentials(User $user): array

/**
* Get the rpEntity Id.
*
* @return string|null
*/
private function getRpId(): ?string
{
Expand Down
2 changes: 1 addition & 1 deletion src/WebauthnServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ protected function bindPsrInterfaces(): void
$this->app->bind(ServerRequestInterface::class, function ($app) {
if (class_exists(PsrHttpFactory::class)) {
return $app[PsrHttpFactory::class]
->createRequest($app->make('request'));
->createRequest($app->make('request'));
}

if (class_exists(\GuzzleHttp\Psr7\ServerRequest::class)) {
Expand Down
5 changes: 2 additions & 3 deletions tests/FeatureTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ protected function getEnvironmentSetUp($app)
// Setup default database to use sqlite :memory:
$app['config']->set('database.default', 'testbench');
$app['config']->set('database.connections.testbench', [
'driver' => 'sqlite',
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
'prefix' => '',
]);
}

Expand Down Expand Up @@ -79,7 +79,6 @@ protected function resolveApplicationHttpKernel($app)
* Create a user and sign in as that user. If a user
* object is passed, then sign in as that user.
*
* @param null $user
* @return User
*/
public function signIn($user = null)
Expand Down

0 comments on commit 701b992

Please sign in to comment.