Skip to content

Commit 55af546

Browse files
authored
[10.x] Uses PHP Native Type Declarations 🐘 (laravel#6010)
* Adds basic typing around method's arguments and return types * Adds missing `closure` type * Adds typing on tests * Fixes `RedirectIfAuthenticated` * Fixes `Authenticate` * Improves `RedirectIfAuthenticated` types * Fixes user factory `unverified` return type
1 parent 21b826f commit 55af546

19 files changed

+34
-86
lines changed

app/Console/Kernel.php

+2-7
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,16 @@ class Kernel extends ConsoleKernel
99
{
1010
/**
1111
* Define the application's command schedule.
12-
*
13-
* @param \Illuminate\Console\Scheduling\Schedule $schedule
14-
* @return void
1512
*/
16-
protected function schedule(Schedule $schedule)
13+
protected function schedule(Schedule $schedule): void
1714
{
1815
// $schedule->command('inspire')->hourly();
1916
}
2017

2118
/**
2219
* Register the commands for the application.
23-
*
24-
* @return void
2520
*/
26-
protected function commands()
21+
protected function commands(): void
2722
{
2823
$this->load(__DIR__.'/Commands');
2924

app/Exceptions/Handler.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,8 @@ class Handler extends ExceptionHandler
3838

3939
/**
4040
* Register the exception handling callbacks for the application.
41-
*
42-
* @return void
4341
*/
44-
public function register()
42+
public function register(): void
4543
{
4644
$this->reportable(function (Throwable $e) {
4745
//

app/Http/Middleware/Authenticate.php

+3-7
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@
33
namespace App\Http\Middleware;
44

55
use Illuminate\Auth\Middleware\Authenticate as Middleware;
6+
use Illuminate\Http\Request;
67

78
class Authenticate extends Middleware
89
{
910
/**
1011
* Get the path the user should be redirected to when they are not authenticated.
11-
*
12-
* @param \Illuminate\Http\Request $request
13-
* @return string|null
1412
*/
15-
protected function redirectTo($request)
13+
protected function redirectTo(Request $request): string|null
1614
{
17-
if (! $request->expectsJson()) {
18-
return route('login');
19-
}
15+
return $request->expectsJson() ? null : route('login');
2016
}
2117
}

app/Http/Middleware/RedirectIfAuthenticated.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@
66
use Closure;
77
use Illuminate\Http\Request;
88
use Illuminate\Support\Facades\Auth;
9+
use Symfony\Component\HttpFoundation\Response;
910

1011
class RedirectIfAuthenticated
1112
{
1213
/**
1314
* Handle an incoming request.
1415
*
15-
* @param \Illuminate\Http\Request $request
16-
* @param \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse) $next
17-
* @param string|null ...$guards
18-
* @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
16+
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
1917
*/
20-
public function handle(Request $request, Closure $next, ...$guards)
18+
public function handle(Request $request, Closure $next, string ...$guards): Response
2119
{
2220
$guards = empty($guards) ? [null] : $guards;
2321

app/Http/Middleware/TrustHosts.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class TrustHosts extends Middleware
1111
*
1212
* @return array<int, string|null>
1313
*/
14-
public function hosts()
14+
public function hosts(): array
1515
{
1616
return [
1717
$this->allSubdomainsOfApplicationUrl(),

app/Providers/AppServiceProvider.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,16 @@ class AppServiceProvider extends ServiceProvider
88
{
99
/**
1010
* Register any application services.
11-
*
12-
* @return void
1311
*/
14-
public function register()
12+
public function register(): void
1513
{
1614
//
1715
}
1816

1917
/**
2018
* Bootstrap any application services.
21-
*
22-
* @return void
2319
*/
24-
public function boot()
20+
public function boot(): void
2521
{
2622
//
2723
}

app/Providers/AuthServiceProvider.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@ class AuthServiceProvider extends ServiceProvider
1818

1919
/**
2020
* Register any authentication / authorization services.
21-
*
22-
* @return void
2321
*/
24-
public function boot()
22+
public function boot(): void
2523
{
2624
$this->registerPolicies();
2725

app/Providers/BroadcastServiceProvider.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ class BroadcastServiceProvider extends ServiceProvider
99
{
1010
/**
1111
* Bootstrap any application services.
12-
*
13-
* @return void
1412
*/
15-
public function boot()
13+
public function boot(): void
1614
{
1715
Broadcast::routes();
1816

app/Providers/EventServiceProvider.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,16 @@ class EventServiceProvider extends ServiceProvider
2222

2323
/**
2424
* Register any events for your application.
25-
*
26-
* @return void
2725
*/
28-
public function boot()
26+
public function boot(): void
2927
{
3028
//
3129
}
3230

3331
/**
3432
* Determine if events and listeners should be automatically discovered.
35-
*
36-
* @return bool
3733
*/
38-
public function shouldDiscoverEvents()
34+
public function shouldDiscoverEvents(): bool
3935
{
4036
return false;
4137
}

app/Providers/RouteServiceProvider.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ class RouteServiceProvider extends ServiceProvider
2121

2222
/**
2323
* Define your route model bindings, pattern filters, and other route configuration.
24-
*
25-
* @return void
2624
*/
27-
public function boot()
25+
public function boot(): void
2826
{
2927
$this->configureRateLimiting();
3028

@@ -40,10 +38,8 @@ public function boot()
4038

4139
/**
4240
* Configure the rate limiters for the application.
43-
*
44-
* @return void
4541
*/
46-
protected function configureRateLimiting()
42+
protected function configureRateLimiting(): void
4743
{
4844
RateLimiter::for('api', function (Request $request) {
4945
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());

database/factories/UserFactory.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class UserFactory extends Factory
1515
*
1616
* @return array<string, mixed>
1717
*/
18-
public function definition()
18+
public function definition(): array
1919
{
2020
return [
2121
'name' => fake()->name(),
@@ -29,9 +29,9 @@ public function definition()
2929
/**
3030
* Indicate that the model's email address should be unverified.
3131
*
32-
* @return static
32+
* @return $this
3333
*/
34-
public function unverified()
34+
public function unverified(): static
3535
{
3636
return $this->state(fn (array $attributes) => [
3737
'email_verified_at' => null,

database/migrations/2014_10_12_000000_create_users_table.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
{
99
/**
1010
* Run the migrations.
11-
*
12-
* @return void
1311
*/
14-
public function up()
12+
public function up(): void
1513
{
1614
Schema::create('users', function (Blueprint $table) {
1715
$table->id();
@@ -26,10 +24,8 @@ public function up()
2624

2725
/**
2826
* Reverse the migrations.
29-
*
30-
* @return void
3127
*/
32-
public function down()
28+
public function down(): void
3329
{
3430
Schema::dropIfExists('users');
3531
}

database/migrations/2014_10_12_100000_create_password_resets_table.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
{
99
/**
1010
* Run the migrations.
11-
*
12-
* @return void
1311
*/
14-
public function up()
12+
public function up(): void
1513
{
1614
Schema::create('password_resets', function (Blueprint $table) {
1715
$table->string('email')->index();
@@ -22,10 +20,8 @@ public function up()
2220

2321
/**
2422
* Reverse the migrations.
25-
*
26-
* @return void
2723
*/
28-
public function down()
24+
public function down(): void
2925
{
3026
Schema::dropIfExists('password_resets');
3127
}

database/migrations/2019_08_19_000000_create_failed_jobs_table.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
{
99
/**
1010
* Run the migrations.
11-
*
12-
* @return void
1311
*/
14-
public function up()
12+
public function up(): void
1513
{
1614
Schema::create('failed_jobs', function (Blueprint $table) {
1715
$table->id();
@@ -26,10 +24,8 @@ public function up()
2624

2725
/**
2826
* Reverse the migrations.
29-
*
30-
* @return void
3127
*/
32-
public function down()
28+
public function down(): void
3329
{
3430
Schema::dropIfExists('failed_jobs');
3531
}

database/migrations/2019_12_14_000001_create_personal_access_tokens_table.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
{
99
/**
1010
* Run the migrations.
11-
*
12-
* @return void
1311
*/
14-
public function up()
12+
public function up(): void
1513
{
1614
Schema::create('personal_access_tokens', function (Blueprint $table) {
1715
$table->id();
@@ -27,10 +25,8 @@ public function up()
2725

2826
/**
2927
* Reverse the migrations.
30-
*
31-
* @return void
3228
*/
33-
public function down()
29+
public function down(): void
3430
{
3531
Schema::dropIfExists('personal_access_tokens');
3632
}

database/seeders/DatabaseSeeder.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ class DatabaseSeeder extends Seeder
99
{
1010
/**
1111
* Seed the application's database.
12-
*
13-
* @return void
1412
*/
15-
public function run()
13+
public function run(): void
1614
{
1715
// \App\Models\User::factory(10)->create();
1816

tests/CreatesApplication.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
namespace Tests;
44

55
use Illuminate\Contracts\Console\Kernel;
6+
use Illuminate\Foundation\Application;
67

78
trait CreatesApplication
89
{
910
/**
1011
* Creates the application.
11-
*
12-
* @return \Illuminate\Foundation\Application
1312
*/
14-
public function createApplication()
13+
public function createApplication(): Application
1514
{
1615
$app = require __DIR__.'/../bootstrap/app.php';
1716

tests/Feature/ExampleTest.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ class ExampleTest extends TestCase
99
{
1010
/**
1111
* A basic test example.
12-
*
13-
* @return void
1412
*/
15-
public function test_the_application_returns_a_successful_response()
13+
public function test_the_application_returns_a_successful_response(): void
1614
{
1715
$response = $this->get('/');
1816

tests/Unit/ExampleTest.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ class ExampleTest extends TestCase
88
{
99
/**
1010
* A basic test example.
11-
*
12-
* @return void
1311
*/
14-
public function test_that_true_is_true()
12+
public function test_that_true_is_true(): void
1513
{
1614
$this->assertTrue(true);
1715
}

0 commit comments

Comments
 (0)