Skip to content

Commit

Permalink
Fix types on level 8
Browse files Browse the repository at this point in the history
  • Loading branch information
Baspa committed Aug 23, 2024
1 parent 462854d commit 7dc3aab
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ includes:
- phpstan-baseline.neon

parameters:
level: 7
level: 8
paths:
- src
- config
Expand Down
2 changes: 1 addition & 1 deletion src/Enums/TwoFactorType.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ enum TwoFactorType: string implements HasLabel
/**
* Get the values of the enum.
*
* @return array<string>
* @return array<int, string|null>
*/
public static function values(): array
{
Expand Down
8 changes: 7 additions & 1 deletion src/Http/Livewire/Auth/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected function getFormSchema(): array

public function loginWithFortify(): LoginResponse|Redirector|null
{
session()->put('panel', Filament::getCurrentPanel()->getId());
session()->put('panel', Filament::getCurrentPanel()?->getId() ?? null);

try {
$this->rateLimit(5);
Expand Down Expand Up @@ -110,6 +110,12 @@ public function loginWithFortify(): LoginResponse|Redirector|null

$user = Filament::auth()->user();

if (! Filament::getCurrentPanel()) {
Filament::auth()->logout();

throw new \Exception('Current panel is not set.');
}

if (
($user instanceof FilamentUser) &&
(! $user->canAccessPanel(Filament::getCurrentPanel()))
Expand Down
8 changes: 4 additions & 4 deletions src/Http/Livewire/Auth/PasswordReset.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class PasswordReset extends Page implements HasForms
public function mount(): void
{
if (Filament::auth()->check()) {
redirect()->intended(Filament::getCurrentPanel()->getUrl());
redirect()->intended(Filament::getCurrentPanel()?->getUrl() ?? config('fortify.home'));
}

if (session('status')) {
Expand Down Expand Up @@ -66,10 +66,10 @@ protected function getFormSchema(): array
->required(),
Hidden::make('email')
->extraAttributes(['name' => 'email'])
->afterStateHydrated(fn ($component) => $component->state(request()->get('email'))),
->afterStateHydrated(fn($component) => $component->state(request()->get('email'))),
Hidden::make('token')
->extraAttributes(['name' => 'token'])
->afterStateHydrated(fn ($component) => $component->state(request()->route('token'))),
->afterStateHydrated(fn($component) => $component->state(request()->route('token'))),
];
}

Expand All @@ -82,4 +82,4 @@ public function render(): View
...$this->getLayoutData(),
]);
}
}
}
4 changes: 2 additions & 2 deletions src/Http/Livewire/Auth/RequestPasswordReset.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class RequestPasswordReset extends Page implements HasForms
public function mount(): void
{
if (Filament::auth()->check()) {
redirect()->intended(Filament::getCurrentPanel()->getUrl());
redirect()->intended(Filament::getCurrentPanel()?->getUrl() ?? config('fortify.home'));
}

if (session('status')) {
Expand Down Expand Up @@ -60,4 +60,4 @@ public function render(): View
...$this->getLayoutData(),
]);
}
}
}
4 changes: 2 additions & 2 deletions src/Http/Responses/LoginResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public function toResponse($request)
{
return $request->wantsJson()
? response()->json(['two_factor' => false])
: redirect()->intended(Filament::getCurrentPanel()->getUrl());
: redirect()->intended(Filament::getCurrentPanel()?->getUrl() ?? config('fortify.home'));
}
}
}
4 changes: 2 additions & 2 deletions src/Http/Responses/TwoFactorChallengeViewResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ class TwoFactorChallengeViewResponse implements LoginResponseContract
*/
public function toResponse($request)
{
return redirect()->intended(Filament::getCurrentPanel()->getUrl());
return redirect()->intended(Filament::getCurrentPanel()?->getUrl() ?? config('fortify.home'));
}
}
}
6 changes: 5 additions & 1 deletion src/Traits/EnumArraySerializableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ trait EnumArraySerializableTrait
*/
public static function array(): array
{
return array_combine(static::names(), static::values());
$names = static::names();

$values = array_filter(static::values(), fn($value) => $value !== null);

return array_combine($names, $values);
}
}
6 changes: 3 additions & 3 deletions src/TwoFactorAuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function packageBooted(): void
* This route name is used multiple places in filament.
*/
Route::prefix(config('filament.path'))->group(function () {
Route::get('/filament-login', fn () => Redirect::route('login'))
Route::get('/filament-login', fn() => Redirect::route('login'))
->name('auth.login');
});
});
Expand Down Expand Up @@ -214,7 +214,7 @@ protected function registerContractsAndComponents(): void
$this->app->singleton(TwoFactorChallengeViewResponse::class, TwoFactorChallengeViewResponse::class);
}

protected function getAssetPackageName(): ?string
protected function getAssetPackageName(): string
{
return 'vormkracht10/filament-two-factor-auth';
}
Expand Down Expand Up @@ -274,4 +274,4 @@ protected function getMigrations(): array
'add_two_factor_type_column_to_users_table',
];
}
}
}

0 comments on commit 7dc3aab

Please sign in to comment.