refactor: auto refactor via rector

This commit is contained in:
idevakk
2025-09-29 01:08:34 +05:30
parent 744e0bb9bb
commit 21664b1a3e
26 changed files with 55 additions and 68 deletions

View File

@@ -10,7 +10,7 @@ class Logout
/** /**
* Log the current user out of the application. * Log the current user out of the application.
*/ */
public function __invoke() public function __invoke(): \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse
{ {
Auth::guard('web')->logout(); Auth::guard('web')->logout();

View File

@@ -50,7 +50,7 @@ class ResetPassword extends Component
// database. Otherwise we will parse the error and return the response. // database. Otherwise we will parse the error and return the response.
$status = Password::reset( $status = Password::reset(
$this->only('email', 'password', 'password_confirmation', 'token'), $this->only('email', 'password', 'password_confirmation', 'token'),
function ($user) { function ($user): void {
$user->forceFill([ $user->forceFill([
'password' => Hash::make($this->password), 'password' => Hash::make($this->password),
'remember_token' => Str::random(60), 'remember_token' => Str::random(60),

View File

@@ -39,7 +39,7 @@ class RecoveryCodes extends Component
if ($user->hasEnabledTwoFactorAuthentication() && $user->two_factor_recovery_codes) { if ($user->hasEnabledTwoFactorAuthentication() && $user->two_factor_recovery_codes) {
try { try {
$this->recoveryCodes = json_decode(decrypt($user->two_factor_recovery_codes), true); $this->recoveryCodes = json_decode((string) decrypt($user->two_factor_recovery_codes), true);
} catch (Exception) { } catch (Exception) {
$this->addError('recoveryCodes', 'Failed to load recovery codes'); $this->addError('recoveryCodes', 'Failed to load recovery codes');

View File

@@ -60,21 +60,16 @@ class DashPanelProvider extends PanelProvider
->plugins([ ->plugins([
FilamentLoggerPlugin::make(), FilamentLoggerPlugin::make(),
FilamentLogViewerPlugin::make(), FilamentLogViewerPlugin::make(),
FilamentMailsPlugin::make()->canManageMails(function () { FilamentMailsPlugin::make()->canManageMails(function (): bool {
$user = Auth::user(); $user = Auth::user();
// Allow access for users with specific roles // Allow access for users with specific roles
if ($user->hasRole('admin')) { if ($user->hasRole('admin')) {
return true; return true;
} }
// Allow access for users with specific permissions // Allow access for users with specific permissions
if ($user->hasPermissionTo('manage mails')) {
return true;
}
// Restrict access for all other users // Restrict access for all other users
return false; return (bool) $user->hasPermissionTo('manage mails');
}), }),
]) ])
->routes(fn () => FilamentMails::routes()); ->routes(fn () => FilamentMails::routes());

View File

@@ -23,11 +23,9 @@ class FortifyServiceProvider extends ServiceProvider
*/ */
public function boot(): void public function boot(): void
{ {
Fortify::twoFactorChallengeView(fn () => view('livewire.auth.two-factor-challenge')); Fortify::twoFactorChallengeView(fn (): \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory => view('livewire.auth.two-factor-challenge'));
Fortify::confirmPasswordView(fn () => view('livewire.auth.confirm-password')); Fortify::confirmPasswordView(fn (): \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory => view('livewire.auth.confirm-password'));
RateLimiter::for('two-factor', function (Request $request) { RateLimiter::for('two-factor', fn(Request $request) => Limit::perMinute(5)->by($request->session()->get('login.id')));
return Limit::perMinute(5)->by($request->session()->get('login.id'));
});
} }
} }

View File

@@ -101,7 +101,7 @@ return [
'previous_keys' => [ 'previous_keys' => [
...array_filter( ...array_filter(
explode(',', env('APP_PREVIOUS_KEYS', '')) explode(',', (string) env('APP_PREVIOUS_KEYS', ''))
), ),
], ],

View File

@@ -44,7 +44,7 @@ return [
'pattern' => [ 'pattern' => [
'prefix' => 'laravel-', 'prefix' => 'laravel-',
'date' => '[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]', 'date' => 'dddd-dd-dd',
'extension' => '.log' 'extension' => '.log'
], ],

View File

@@ -54,7 +54,7 @@ return [
'stack' => [ 'stack' => [
'driver' => 'stack', 'driver' => 'stack',
'channels' => explode(',', env('LOG_STACK', 'single')), 'channels' => explode(',', (string) env('LOG_STACK', 'single')),
'ignore_exceptions' => false, 'ignore_exceptions' => false,
], ],

View File

@@ -46,7 +46,7 @@ return [
'username' => env('MAIL_USERNAME'), 'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'), 'password' => env('MAIL_PASSWORD'),
'timeout' => null, 'timeout' => null,
'local_domain' => env('MAIL_EHLO_DOMAIN', parse_url(env('APP_URL', 'http://localhost'), PHP_URL_HOST)), 'local_domain' => env('MAIL_EHLO_DOMAIN', parse_url((string) env('APP_URL', 'http://localhost'), PHP_URL_HOST)),
], ],
'ses' => [ 'ses' => [

View File

@@ -8,8 +8,6 @@ use Rector\Php83\Rector\ClassMethod\AddOverrideAttributeToOverriddenMethodsRecto
return RectorConfig::configure() return RectorConfig::configure()
->withPaths([ ->withPaths([
__DIR__ . '/app', __DIR__ . '/app',
__DIR__ . '/bootstrap',
__DIR__ . '/resources',
__DIR__ . '/routes', __DIR__ . '/routes',
__DIR__ . '/config', __DIR__ . '/config',
__DIR__ . '/tests', __DIR__ . '/tests',

View File

@@ -9,14 +9,14 @@ use App\Livewire\Auth\ResetPassword;
use App\Livewire\Auth\VerifyEmail; use App\Livewire\Auth\VerifyEmail;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
Route::middleware('guest')->group(function () { Route::middleware('guest')->group(function (): void {
Route::get('login', Login::class)->name('login'); Route::get('login', Login::class)->name('login');
Route::get('register', Register::class)->name('register'); Route::get('register', Register::class)->name('register');
Route::get('forgot-password', ForgotPassword::class)->name('password.request'); Route::get('forgot-password', ForgotPassword::class)->name('password.request');
Route::get('reset-password/{token}', ResetPassword::class)->name('password.reset'); Route::get('reset-password/{token}', ResetPassword::class)->name('password.reset');
}); });
Route::middleware('auth')->group(function () { Route::middleware('auth')->group(function (): void {
Route::get('verify-email', VerifyEmail::class) Route::get('verify-email', VerifyEmail::class)
->name('verification.notice'); ->name('verification.notice');

View File

@@ -3,6 +3,6 @@
use Illuminate\Foundation\Inspiring; use Illuminate\Foundation\Inspiring;
use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Facades\Artisan;
Artisan::command('inspire', function () { Artisan::command('inspire', function (): void {
$this->comment(Inspiring::quote()); $this->comment(Inspiring::quote());
})->purpose('Display an inspiring quote'); })->purpose('Display an inspiring quote');

View File

@@ -7,15 +7,13 @@ use App\Livewire\Settings\TwoFactor;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
use Laravel\Fortify\Features; use Laravel\Fortify\Features;
Route::get('/', function () { Route::get('/', fn(): \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory => view('welcome'))->name('home');
return view('welcome');
})->name('home');
Route::view('dashboard', 'dashboard') Route::view('dashboard', 'dashboard')
->middleware(['auth', 'verified']) ->middleware(['auth', 'verified'])
->name('dashboard'); ->name('dashboard');
Route::middleware(['auth'])->group(function () { Route::middleware(['auth'])->group(function (): void {
Route::redirect('settings', 'settings/profile'); Route::redirect('settings', 'settings/profile');
Route::get('settings/profile', Profile::class)->name('settings.profile'); Route::get('settings/profile', Profile::class)->name('settings.profile');

View File

@@ -5,13 +5,13 @@ use App\Models\User;
use Laravel\Fortify\Features; use Laravel\Fortify\Features;
use Livewire\Livewire; use Livewire\Livewire;
test('login screen can be rendered', function () { test('login screen can be rendered', function (): void {
$response = $this->get('/login'); $response = $this->get('/login');
$response->assertStatus(200); $response->assertStatus(200);
}); });
test('users can authenticate using the login screen', function () { test('users can authenticate using the login screen', function (): void {
$user = User::factory()->create(); $user = User::factory()->create();
$response = Livewire::test(Login::class) $response = Livewire::test(Login::class)
@@ -26,7 +26,7 @@ test('users can authenticate using the login screen', function () {
$this->assertAuthenticated(); $this->assertAuthenticated();
}); });
test('users can not authenticate with invalid password', function () { test('users can not authenticate with invalid password', function (): void {
$user = User::factory()->create(); $user = User::factory()->create();
$response = Livewire::test(Login::class) $response = Livewire::test(Login::class)
@@ -39,7 +39,7 @@ test('users can not authenticate with invalid password', function () {
$this->assertGuest(); $this->assertGuest();
}); });
test('users with two factor enabled are redirected to two factor challenge', function () { test('users with two factor enabled are redirected to two factor challenge', function (): void {
if (! Features::canManageTwoFactorAuthentication()) { if (! Features::canManageTwoFactorAuthentication()) {
$this->markTestSkipped('Two-factor authentication is not enabled.'); $this->markTestSkipped('Two-factor authentication is not enabled.');
} }
@@ -67,7 +67,7 @@ test('users with two factor enabled are redirected to two factor challenge', fun
$this->assertGuest(); $this->assertGuest();
}); });
test('users can logout', function () { test('users can logout', function (): void {
$user = User::factory()->create(); $user = User::factory()->create();
$response = $this->actingAs($user)->post('/logout'); $response = $this->actingAs($user)->post('/logout');

View File

@@ -5,7 +5,7 @@ use Illuminate\Auth\Events\Verified;
use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\URL; use Illuminate\Support\Facades\URL;
test('email verification screen can be rendered', function () { test('email verification screen can be rendered', function (): void {
$user = User::factory()->unverified()->create(); $user = User::factory()->unverified()->create();
$response = $this->actingAs($user)->get('/verify-email'); $response = $this->actingAs($user)->get('/verify-email');
@@ -13,7 +13,7 @@ test('email verification screen can be rendered', function () {
$response->assertStatus(200); $response->assertStatus(200);
}); });
test('email can be verified', function () { test('email can be verified', function (): void {
$user = User::factory()->unverified()->create(); $user = User::factory()->unverified()->create();
Event::fake(); Event::fake();
@@ -21,7 +21,7 @@ test('email can be verified', function () {
$verificationUrl = URL::temporarySignedRoute( $verificationUrl = URL::temporarySignedRoute(
'verification.verify', 'verification.verify',
now()->addMinutes(60), now()->addMinutes(60),
['id' => $user->id, 'hash' => sha1($user->email)] ['id' => $user->id, 'hash' => sha1((string) $user->email)]
); );
$response = $this->actingAs($user)->get($verificationUrl); $response = $this->actingAs($user)->get($verificationUrl);
@@ -32,7 +32,7 @@ test('email can be verified', function () {
$response->assertRedirect(route('dashboard', absolute: false).'?verified=1'); $response->assertRedirect(route('dashboard', absolute: false).'?verified=1');
}); });
test('email is not verified with invalid hash', function () { test('email is not verified with invalid hash', function (): void {
$user = User::factory()->unverified()->create(); $user = User::factory()->unverified()->create();
$verificationUrl = URL::temporarySignedRoute( $verificationUrl = URL::temporarySignedRoute(

View File

@@ -2,7 +2,7 @@
use App\Models\User; use App\Models\User;
test('confirm password screen can be rendered', function () { test('confirm password screen can be rendered', function (): void {
$user = User::factory()->create(); $user = User::factory()->create();
$response = $this->actingAs($user)->get(route('password.confirm')); $response = $this->actingAs($user)->get(route('password.confirm'));

View File

@@ -7,13 +7,13 @@ use Illuminate\Auth\Notifications\ResetPassword as ResetPasswordNotification;
use Illuminate\Support\Facades\Notification; use Illuminate\Support\Facades\Notification;
use Livewire\Livewire; use Livewire\Livewire;
test('reset password link screen can be rendered', function () { test('reset password link screen can be rendered', function (): void {
$response = $this->get('/forgot-password'); $response = $this->get('/forgot-password');
$response->assertStatus(200); $response->assertStatus(200);
}); });
test('reset password link can be requested', function () { test('reset password link can be requested', function (): void {
Notification::fake(); Notification::fake();
$user = User::factory()->create(); $user = User::factory()->create();
@@ -25,7 +25,7 @@ test('reset password link can be requested', function () {
Notification::assertSentTo($user, ResetPasswordNotification::class); Notification::assertSentTo($user, ResetPasswordNotification::class);
}); });
test('reset password screen can be rendered', function () { test('reset password screen can be rendered', function (): void {
Notification::fake(); Notification::fake();
$user = User::factory()->create(); $user = User::factory()->create();
@@ -34,7 +34,7 @@ test('reset password screen can be rendered', function () {
->set('email', $user->email) ->set('email', $user->email)
->call('sendPasswordResetLink'); ->call('sendPasswordResetLink');
Notification::assertSentTo($user, ResetPasswordNotification::class, function ($notification) { Notification::assertSentTo($user, ResetPasswordNotification::class, function ($notification): true {
$response = $this->get('/reset-password/'.$notification->token); $response = $this->get('/reset-password/'.$notification->token);
$response->assertStatus(200); $response->assertStatus(200);
@@ -43,7 +43,7 @@ test('reset password screen can be rendered', function () {
}); });
}); });
test('password can be reset with valid token', function () { test('password can be reset with valid token', function (): void {
Notification::fake(); Notification::fake();
$user = User::factory()->create(); $user = User::factory()->create();
@@ -52,7 +52,7 @@ test('password can be reset with valid token', function () {
->set('email', $user->email) ->set('email', $user->email)
->call('sendPasswordResetLink'); ->call('sendPasswordResetLink');
Notification::assertSentTo($user, ResetPasswordNotification::class, function ($notification) use ($user) { Notification::assertSentTo($user, ResetPasswordNotification::class, function ($notification) use ($user): true {
$response = Livewire::test(ResetPassword::class, ['token' => $notification->token]) $response = Livewire::test(ResetPassword::class, ['token' => $notification->token])
->set('email', $user->email) ->set('email', $user->email)
->set('password', 'password') ->set('password', 'password')

View File

@@ -3,13 +3,13 @@
use App\Livewire\Auth\Register; use App\Livewire\Auth\Register;
use Livewire\Livewire; use Livewire\Livewire;
test('registration screen can be rendered', function () { test('registration screen can be rendered', function (): void {
$response = $this->get('/register'); $response = $this->get('/register');
$response->assertStatus(200); $response->assertStatus(200);
}); });
test('new users can register', function () { test('new users can register', function (): void {
$response = Livewire::test(Register::class) $response = Livewire::test(Register::class)
->set('name', 'Test User') ->set('name', 'Test User')
->set('email', 'test@example.com') ->set('email', 'test@example.com')

View File

@@ -4,7 +4,7 @@ use App\Models\User;
use Laravel\Fortify\Features; use Laravel\Fortify\Features;
use Livewire\Livewire; use Livewire\Livewire;
test('two factor challenge redirects to login when not authenticated', function () { test('two factor challenge redirects to login when not authenticated', function (): void {
if (! Features::canManageTwoFactorAuthentication()) { if (! Features::canManageTwoFactorAuthentication()) {
$this->markTestSkipped('Two-factor authentication is not enabled.'); $this->markTestSkipped('Two-factor authentication is not enabled.');
} }
@@ -14,7 +14,7 @@ test('two factor challenge redirects to login when not authenticated', function
$response->assertRedirect(route('login')); $response->assertRedirect(route('login'));
}); });
test('two factor challenge can be rendered', function () { test('two factor challenge can be rendered', function (): void {
if (! Features::canManageTwoFactorAuthentication()) { if (! Features::canManageTwoFactorAuthentication()) {
$this->markTestSkipped('Two-factor authentication is not enabled.'); $this->markTestSkipped('Two-factor authentication is not enabled.');
} }

View File

@@ -2,11 +2,11 @@
use App\Models\User; use App\Models\User;
test('guests are redirected to the login page', function () { test('guests are redirected to the login page', function (): void {
$this->get('/dashboard')->assertRedirect('/login'); $this->get('/dashboard')->assertRedirect('/login');
}); });
test('authenticated users can visit the dashboard', function () { test('authenticated users can visit the dashboard', function (): void {
$this->actingAs($user = User::factory()->create()); $this->actingAs($user = User::factory()->create());
$this->get('/dashboard')->assertStatus(200); $this->get('/dashboard')->assertStatus(200);

View File

@@ -1,6 +1,6 @@
<?php <?php
test('returns a successful response', function () { test('returns a successful response', function (): void {
$response = $this->get('/'); $response = $this->get('/');
$response->assertStatus(200); $response->assertStatus(200);

View File

@@ -5,7 +5,7 @@ use App\Models\User;
use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Hash;
use Livewire\Livewire; use Livewire\Livewire;
test('password can be updated', function () { test('password can be updated', function (): void {
$user = User::factory()->create([ $user = User::factory()->create([
'password' => Hash::make('password'), 'password' => Hash::make('password'),
]); ]);
@@ -23,7 +23,7 @@ test('password can be updated', function () {
expect(Hash::check('new-password', $user->refresh()->password))->toBeTrue(); expect(Hash::check('new-password', $user->refresh()->password))->toBeTrue();
}); });
test('correct password must be provided to update password', function () { test('correct password must be provided to update password', function (): void {
$user = User::factory()->create([ $user = User::factory()->create([
'password' => Hash::make('password'), 'password' => Hash::make('password'),
]); ]);

View File

@@ -4,13 +4,13 @@ use App\Livewire\Settings\Profile;
use App\Models\User; use App\Models\User;
use Livewire\Livewire; use Livewire\Livewire;
test('profile page is displayed', function () { test('profile page is displayed', function (): void {
$this->actingAs($user = User::factory()->create()); $this->actingAs($user = User::factory()->create());
$this->get('/settings/profile')->assertOk(); $this->get('/settings/profile')->assertOk();
}); });
test('profile information can be updated', function () { test('profile information can be updated', function (): void {
$user = User::factory()->create(); $user = User::factory()->create();
$this->actingAs($user); $this->actingAs($user);
@@ -29,7 +29,7 @@ test('profile information can be updated', function () {
expect($user->email_verified_at)->toBeNull(); expect($user->email_verified_at)->toBeNull();
}); });
test('email verification status is unchanged when email address is unchanged', function () { test('email verification status is unchanged when email address is unchanged', function (): void {
$user = User::factory()->create(); $user = User::factory()->create();
$this->actingAs($user); $this->actingAs($user);
@@ -44,7 +44,7 @@ test('email verification status is unchanged when email address is unchanged', f
expect($user->refresh()->email_verified_at)->not->toBeNull(); expect($user->refresh()->email_verified_at)->not->toBeNull();
}); });
test('user can delete their account', function () { test('user can delete their account', function (): void {
$user = User::factory()->create(); $user = User::factory()->create();
$this->actingAs($user); $this->actingAs($user);
@@ -61,7 +61,7 @@ test('user can delete their account', function () {
expect(auth()->check())->toBeFalse(); expect(auth()->check())->toBeFalse();
}); });
test('correct password must be provided to delete account', function () { test('correct password must be provided to delete account', function (): void {
$user = User::factory()->create(); $user = User::factory()->create();
$this->actingAs($user); $this->actingAs($user);

View File

@@ -4,7 +4,7 @@ use App\Models\User;
use Laravel\Fortify\Features; use Laravel\Fortify\Features;
use Livewire\Livewire; use Livewire\Livewire;
beforeEach(function () { beforeEach(function (): void {
if (! Features::canManageTwoFactorAuthentication()) { if (! Features::canManageTwoFactorAuthentication()) {
$this->markTestSkipped('Two-factor authentication is not enabled.'); $this->markTestSkipped('Two-factor authentication is not enabled.');
} }
@@ -15,7 +15,7 @@ beforeEach(function () {
]); ]);
}); });
test('two factor settings page can be rendered', function () { test('two factor settings page can be rendered', function (): void {
$user = User::factory()->create(); $user = User::factory()->create();
$this->actingAs($user) $this->actingAs($user)
@@ -26,7 +26,7 @@ test('two factor settings page can be rendered', function () {
->assertSee('Disabled'); ->assertSee('Disabled');
}); });
test('two factor settings page requires password confirmation when enabled', function () { test('two factor settings page requires password confirmation when enabled', function (): void {
$user = User::factory()->create(); $user = User::factory()->create();
$response = $this->actingAs($user) $response = $this->actingAs($user)
@@ -35,7 +35,7 @@ test('two factor settings page requires password confirmation when enabled', fun
$response->assertRedirect(route('password.confirm')); $response->assertRedirect(route('password.confirm'));
}); });
test('two factor settings page returns forbidden response when two factor is disabled', function () { test('two factor settings page returns forbidden response when two factor is disabled', function (): void {
config(['fortify.features' => []]); config(['fortify.features' => []]);
$user = User::factory()->create(); $user = User::factory()->create();
@@ -47,7 +47,7 @@ test('two factor settings page returns forbidden response when two factor is dis
$response->assertForbidden(); $response->assertForbidden();
}); });
test('two factor authentication disabled when confirmation abandoned between requests', function () { test('two factor authentication disabled when confirmation abandoned between requests', function (): void {
$user = User::factory()->create(); $user = User::factory()->create();
$user->forceFill([ $user->forceFill([

View File

@@ -26,9 +26,7 @@ pest()->extend(Tests\TestCase::class)
| |
*/ */
expect()->extend('toBeOne', function () { expect()->extend('toBeOne', fn() => $this->toBe(1));
return $this->toBe(1);
});
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------
@@ -41,7 +39,7 @@ expect()->extend('toBeOne', function () {
| |
*/ */
function something() function something(): void
{ {
// .. // ..
} }

View File

@@ -1,5 +1,5 @@
<?php <?php
test('that true is true', function () { test('that true is true', function (): void {
expect(true)->toBeTrue(); expect(true)->toBeTrue();
}); });