From 233243e8b49f6828bc1b2d2e8d6a08c973efd48e Mon Sep 17 00:00:00 2001 From: ashish aryal Date: Wed, 15 Oct 2025 09:48:29 +0200 Subject: [PATCH 1/2] rector installed --- .../Auth/NewPasswordController.php | 2 +- app/Repositories/TripRepository.php | 6 +- composer.json | 3 +- composer.lock | 62 ++++++++++++++++++- rector.php | 29 +++++++++ routes/auth.php | 4 +- routes/console.php | 2 +- routes/web.php | 10 +-- tests/Feature/Auth/AuthenticationTest.php | 8 +-- tests/Feature/Auth/EmailVerificationTest.php | 6 +- .../Feature/Auth/PasswordConfirmationTest.php | 6 +- tests/Feature/Auth/PasswordResetTest.php | 8 +-- tests/Feature/Auth/PasswordUpdateTest.php | 4 +- tests/Feature/Auth/RegistrationTest.php | 4 +- tests/Feature/ExampleTest.php | 2 +- tests/Feature/ProfileTest.php | 10 +-- tests/Unit/ExampleTest.php | 2 +- 17 files changed, 129 insertions(+), 39 deletions(-) create mode 100644 rector.php diff --git a/app/Http/Controllers/Auth/NewPasswordController.php b/app/Http/Controllers/Auth/NewPasswordController.php index e8368bd..d7d5a8a 100644 --- a/app/Http/Controllers/Auth/NewPasswordController.php +++ b/app/Http/Controllers/Auth/NewPasswordController.php @@ -41,7 +41,7 @@ public function store(Request $request): RedirectResponse // database. Otherwise we will parse the error and return the response. $status = Password::reset( $request->only('email', 'password', 'password_confirmation', 'token'), - function (User $user) use ($request) { + function (User $user) use ($request): void { $user->forceFill([ 'password' => Hash::make($request->password), 'remember_token' => Str::random(60), diff --git a/app/Repositories/TripRepository.php b/app/Repositories/TripRepository.php index 4fa4515..55d5b54 100644 --- a/app/Repositories/TripRepository.php +++ b/app/Repositories/TripRepository.php @@ -27,12 +27,12 @@ public function findAll(): array public function findWithSuggestions(Trip $trip): Trip { return $trip->load([ - 'suggestions' => function ($query) { + 'suggestions' => function ($query): void { $query->withCount([ - 'vote as up_votes_count' => function ($q) { + 'vote as up_votes_count' => function ($q): void { $q->where('type', VoteType::UP); }, - 'vote as down_votes_count' => function ($q) { + 'vote as down_votes_count' => function ($q): void { $q->where('type', VoteType::DOWN); }, ]); diff --git a/composer.json b/composer.json index 0103a7f..1a8e657 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,8 @@ "mockery/mockery": "^1.6", "nunomaduro/collision": "^8.6", "pestphp/pest": "^4.1", - "pestphp/pest-plugin-laravel": "^4.0" + "pestphp/pest-plugin-laravel": "^4.0", + "rector/rector": "^2.2" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index 7ef2e7b..ed84f9b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "7ef754c0d5d29d962af1332e759084f9", + "content-hash": "d196f6291b4e81cfd443f0b829c4743a", "packages": [ { "name": "brick/math", @@ -8645,6 +8645,66 @@ ], "time": "2025-09-03T06:25:17+00:00" }, + { + "name": "rector/rector", + "version": "2.2.3", + "source": { + "type": "git", + "url": "https://github.com/rectorphp/rector.git", + "reference": "d27f976a332a87b5d03553c2e6f04adbe5da034f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/rectorphp/rector/zipball/d27f976a332a87b5d03553c2e6f04adbe5da034f", + "reference": "d27f976a332a87b5d03553c2e6f04adbe5da034f", + "shasum": "" + }, + "require": { + "php": "^7.4|^8.0", + "phpstan/phpstan": "^2.1.26" + }, + "conflict": { + "rector/rector-doctrine": "*", + "rector/rector-downgrade-php": "*", + "rector/rector-phpunit": "*", + "rector/rector-symfony": "*" + }, + "suggest": { + "ext-dom": "To manipulate phpunit.xml via the custom-rule command" + }, + "bin": [ + "bin/rector" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Instant Upgrade and Automated Refactoring of any PHP code", + "homepage": "https://getrector.com/", + "keywords": [ + "automation", + "dev", + "migration", + "refactoring" + ], + "support": { + "issues": "https://github.com/rectorphp/rector/issues", + "source": "https://github.com/rectorphp/rector/tree/2.2.3" + }, + "funding": [ + { + "url": "https://github.com/tomasvotruba", + "type": "github" + } + ], + "time": "2025-10-11T21:50:23+00:00" + }, { "name": "sebastian/cli-parser", "version": "4.2.0", diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..254fafa --- /dev/null +++ b/rector.php @@ -0,0 +1,29 @@ +withPaths([ + __DIR__ . '/app', + __DIR__ . '/bootstrap', + __DIR__ . '/config', + __DIR__ . '/public', + __DIR__ . '/resources', + __DIR__ . '/routes', + __DIR__ . '/tests', + ]) + // uncomment to reach your current PHP version + // ->withPhpSets() + ->withPreparedSets( +// deadCode: true, +// codeQuality: true, +// typeDeclarations: true, + privatization: true, + earlyReturn: true, + strictBooleans: true, + ) + ->withTypeCoverageLevel(0) + ->withDeadCodeLevel(0) + ->withCodeQualityLevel(0); diff --git a/routes/auth.php b/routes/auth.php index 3926ecf..c10e1e9 100644 --- a/routes/auth.php +++ b/routes/auth.php @@ -11,7 +11,7 @@ use App\Http\Controllers\Auth\VerifyEmailController; use Illuminate\Support\Facades\Route; -Route::middleware('guest')->group(function () { +Route::middleware('guest')->group(function (): void { Route::get('register', [RegisteredUserController::class, 'create']) ->name('register'); @@ -35,7 +35,7 @@ ->name('password.store'); }); -Route::middleware('auth')->group(function () { +Route::middleware('auth')->group(function (): void { Route::get('verify-email', EmailVerificationPromptController::class) ->name('verification.notice'); diff --git a/routes/console.php b/routes/console.php index 3c9adf1..fa9463c 100644 --- a/routes/console.php +++ b/routes/console.php @@ -3,6 +3,6 @@ use Illuminate\Foundation\Inspiring; use Illuminate\Support\Facades\Artisan; -Artisan::command('inspire', function () { +Artisan::command('inspire', function (): void { $this->comment(Inspiring::quote()); })->purpose('Display an inspiring quote'); diff --git a/routes/web.php b/routes/web.php index 0076433..943cb7a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -10,13 +10,13 @@ return view('welcome'); }); -Route::middleware('auth')->group(function () { +Route::middleware('auth')->group(function (): void { Route::get('/profile', [ProfileController::class, 'edit'])->name('profile.edit'); Route::patch('/profile', [ProfileController::class, 'update'])->name('profile.update'); Route::delete('/profile', [ProfileController::class, 'destroy'])->name('profile.destroy'); }); -Route::middleware(['auth'])->group(function () { +Route::middleware(['auth'])->group(function (): void { Route::get('/dashboard', [TripController::class, 'index'])->name('dashboard'); // Ungated @@ -24,19 +24,19 @@ Route::post('trips', [TripController::class, 'store'])->name('trips.store'); // They can view trip assigned to them - Route::middleware('can:view,trip')->group(function () { + Route::middleware('can:view,trip')->group(function (): void { Route::get('trips/{trip}/', [TripController::class, 'show'])->name('trips.show'); Route::resource('trips.suggestions', SuggestionController::class)->only(['store']); }); // - Route::middleware('can:view,suggestion.trip')->group(function () { + Route::middleware('can:view,suggestion.trip')->group(function (): void { Route::get('/suggestions/{suggestion}/status', [SuggestionController::class, 'status'])->name('suggestions.status'); Route::get('/suggestions/{suggestion}/vote', [VoteController::class, 'vote'])->name('suggestions.vote'); }); // They can update the trips - Route::middleware('can:update,trip')->group(function () { + Route::middleware('can:update,trip')->group(function (): void { Route::get('trips/{trip}/edit', [TripController::class, 'edit'])->name('trips.edit'); Route::put('trips/{trip}', [TripController::class, 'update'])->name('trips.update'); }); diff --git a/tests/Feature/Auth/AuthenticationTest.php b/tests/Feature/Auth/AuthenticationTest.php index a272b9d..4e772e7 100644 --- a/tests/Feature/Auth/AuthenticationTest.php +++ b/tests/Feature/Auth/AuthenticationTest.php @@ -2,13 +2,13 @@ use App\Models\User; -test('login screen can be rendered', function () { +test('login screen can be rendered', function (): void { $response = $this->get('/login'); $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(); $response = $this->post('/login', [ @@ -20,7 +20,7 @@ $response->assertRedirect(route('dashboard', absolute: false)); }); -test('users can not authenticate with invalid password', function () { +test('users can not authenticate with invalid password', function (): void { $user = User::factory()->create(); $this->post('/login', [ @@ -31,7 +31,7 @@ $this->assertGuest(); }); -test('users can logout', function () { +test('users can logout', function (): void { $user = User::factory()->create(); $response = $this->actingAs($user)->post('/logout'); diff --git a/tests/Feature/Auth/EmailVerificationTest.php b/tests/Feature/Auth/EmailVerificationTest.php index f282dff..dd8fef0 100644 --- a/tests/Feature/Auth/EmailVerificationTest.php +++ b/tests/Feature/Auth/EmailVerificationTest.php @@ -5,7 +5,7 @@ use Illuminate\Support\Facades\Event; 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(); $response = $this->actingAs($user)->get('/verify-email'); @@ -13,7 +13,7 @@ $response->assertStatus(200); }); -test('email can be verified', function () { +test('email can be verified', function (): void { $user = User::factory()->unverified()->create(); Event::fake(); @@ -31,7 +31,7 @@ $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(); $verificationUrl = URL::temporarySignedRoute( diff --git a/tests/Feature/Auth/PasswordConfirmationTest.php b/tests/Feature/Auth/PasswordConfirmationTest.php index 8a42902..2ff3f24 100644 --- a/tests/Feature/Auth/PasswordConfirmationTest.php +++ b/tests/Feature/Auth/PasswordConfirmationTest.php @@ -2,7 +2,7 @@ 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(); $response = $this->actingAs($user)->get('/confirm-password'); @@ -10,7 +10,7 @@ $response->assertStatus(200); }); -test('password can be confirmed', function () { +test('password can be confirmed', function (): void { $user = User::factory()->create(); $response = $this->actingAs($user)->post('/confirm-password', [ @@ -21,7 +21,7 @@ $response->assertSessionHasNoErrors(); }); -test('password is not confirmed with invalid password', function () { +test('password is not confirmed with invalid password', function (): void { $user = User::factory()->create(); $response = $this->actingAs($user)->post('/confirm-password', [ diff --git a/tests/Feature/Auth/PasswordResetTest.php b/tests/Feature/Auth/PasswordResetTest.php index 0504276..a002d81 100644 --- a/tests/Feature/Auth/PasswordResetTest.php +++ b/tests/Feature/Auth/PasswordResetTest.php @@ -4,13 +4,13 @@ use Illuminate\Auth\Notifications\ResetPassword; use Illuminate\Support\Facades\Notification; -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->assertStatus(200); }); -test('reset password link can be requested', function () { +test('reset password link can be requested', function (): void { Notification::fake(); $user = User::factory()->create(); @@ -20,7 +20,7 @@ Notification::assertSentTo($user, ResetPassword::class); }); -test('reset password screen can be rendered', function () { +test('reset password screen can be rendered', function (): void { Notification::fake(); $user = User::factory()->create(); @@ -36,7 +36,7 @@ }); }); -test('password can be reset with valid token', function () { +test('password can be reset with valid token', function (): void { Notification::fake(); $user = User::factory()->create(); diff --git a/tests/Feature/Auth/PasswordUpdateTest.php b/tests/Feature/Auth/PasswordUpdateTest.php index e3d1278..282358e 100644 --- a/tests/Feature/Auth/PasswordUpdateTest.php +++ b/tests/Feature/Auth/PasswordUpdateTest.php @@ -3,7 +3,7 @@ use App\Models\User; use Illuminate\Support\Facades\Hash; -test('password can be updated', function () { +test('password can be updated', function (): void { $user = User::factory()->create(); $response = $this @@ -22,7 +22,7 @@ $this->assertTrue(Hash::check('new-password', $user->refresh()->password)); }); -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(); $response = $this diff --git a/tests/Feature/Auth/RegistrationTest.php b/tests/Feature/Auth/RegistrationTest.php index 352ca78..1120908 100644 --- a/tests/Feature/Auth/RegistrationTest.php +++ b/tests/Feature/Auth/RegistrationTest.php @@ -1,12 +1,12 @@ get('/register'); $response->assertStatus(200); }); -test('new users can register', function () { +test('new users can register', function (): void { $response = $this->post('/register', [ 'name' => 'Test User', 'email' => 'test@example.com', diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php index 8b5843f..34782b1 100644 --- a/tests/Feature/ExampleTest.php +++ b/tests/Feature/ExampleTest.php @@ -1,6 +1,6 @@ get('/'); $response->assertStatus(200); diff --git a/tests/Feature/ProfileTest.php b/tests/Feature/ProfileTest.php index 1536458..c44f8a4 100644 --- a/tests/Feature/ProfileTest.php +++ b/tests/Feature/ProfileTest.php @@ -2,7 +2,7 @@ use App\Models\User; -test('profile page is displayed', function () { +test('profile page is displayed', function (): void { $user = User::factory()->create(); $response = $this @@ -12,7 +12,7 @@ $response->assertOk(); }); -test('profile information can be updated', function () { +test('profile information can be updated', function (): void { $user = User::factory()->create(); $response = $this @@ -33,7 +33,7 @@ $this->assertNull($user->email_verified_at); }); -test('email verification status is unchanged when the email address is unchanged', function () { +test('email verification status is unchanged when the email address is unchanged', function (): void { $user = User::factory()->create(); $response = $this @@ -50,7 +50,7 @@ $this->assertNotNull($user->refresh()->email_verified_at); }); -test('user can delete their account', function () { +test('user can delete their account', function (): void { $user = User::factory()->create(); $response = $this @@ -67,7 +67,7 @@ $this->assertNull($user->fresh()); }); -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(); $response = $this diff --git a/tests/Unit/ExampleTest.php b/tests/Unit/ExampleTest.php index 44a4f33..963bc0c 100644 --- a/tests/Unit/ExampleTest.php +++ b/tests/Unit/ExampleTest.php @@ -1,5 +1,5 @@ toBeTrue(); }); From 8eeac267770a262e57e230b461ae7a40bc5d0323 Mon Sep 17 00:00:00 2001 From: ashish64 <312075+ashish64@users.noreply.github.com> Date: Wed, 15 Oct 2025 07:48:58 +0000 Subject: [PATCH 2/2] Apply automatic changes --- rector.php | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/rector.php b/rector.php index 254fafa..a21eb3a 100644 --- a/rector.php +++ b/rector.php @@ -6,20 +6,20 @@ return RectorConfig::configure() ->withPaths([ - __DIR__ . '/app', - __DIR__ . '/bootstrap', - __DIR__ . '/config', - __DIR__ . '/public', - __DIR__ . '/resources', - __DIR__ . '/routes', - __DIR__ . '/tests', + __DIR__.'/app', + __DIR__.'/bootstrap', + __DIR__.'/config', + __DIR__.'/public', + __DIR__.'/resources', + __DIR__.'/routes', + __DIR__.'/tests', ]) // uncomment to reach your current PHP version // ->withPhpSets() ->withPreparedSets( -// deadCode: true, -// codeQuality: true, -// typeDeclarations: true, + // deadCode: true, + // codeQuality: true, + // typeDeclarations: true, privatization: true, earlyReturn: true, strictBooleans: true,