Skip to content

Commit eb04fb4

Browse files
authored
[10.x] Uses PHP Native Type Declarations 🐘 (#44545)
* Adds types to `up` and `down` migration methods * Adds types casts `get` and `set` methods * Adds types to HTTP Authenticate `redirectTo` method * Adds types to `handle` middleware methods * Adds types to `join` channel method * Adds types to `handle` command method * Adds types to `render` component method * Adds types to `broadcastOn` event method * Improves types order * Adds types to `definition` model factory method * Adds types to `handle` job method * Types missing `render` method in Exception * Adds types to `handle` listener method * Adds types to `render` and `report` Exception method * Adds types to `build` Mail method * Fixes missing param type in `handle` middleware method * Adds types to notifications * Adds types to observers * Adds types to policies * Adds types to providers * Adds types to requests * Adds types to resources * Adds types to rules * Adds missing types to rules * Adds types to scopes * Adds types to seeds * Adds types to tests * Adds types to Auth user providers * Adds types to Authenticatable * Adds types to `SerializesCastableAttributes` * Adds missing type * Migrates missing job stub * Adds types to UrlRoutable * Reverts changes on test migrations * Reverts changes on test migrations * Reverts changes on test migrations * Reverts changes on `Authenticatable` * Reverts changes on `UserProvider` * Reverts changes on UserProvider * Changes the console stub * Fixes missing type annotation * Reverts changes in docs * Swaps order of params * Fixes key type * Reverts changes on UrlRoutable * Reverts changes on UrlRoutable * Types BroadcastsEvents * Simplifies event stub * Adds types to inbound stub * Makes `report` void return type * Makes `report` void return type * Adds missing type on validaton * Clarifies that `$notifiable` is an object * Fixes type on "render" errors * Avoids issues with Larastan * Reverts * Improves rules types * Simplifies policy's return type * Types controllers stubs * Adds types to singleton stubs * Fixes return type * Use `RedirectResponse` on non api controllers (#45485)
1 parent c152a97 commit eb04fb4

File tree

66 files changed

+210
-537
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+210
-537
lines changed

src/Illuminate/Auth/Middleware/Authenticate.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Illuminate\Auth\AuthenticationException;
77
use Illuminate\Contracts\Auth\Factory as Auth;
88
use Illuminate\Contracts\Auth\Middleware\AuthenticatesRequests;
9+
use Illuminate\Http\Request;
910

1011
class Authenticate implements AuthenticatesRequests
1112
{
@@ -90,7 +91,7 @@ protected function unauthenticated($request, array $guards)
9091
* @param \Illuminate\Http\Request $request
9192
* @return string|null
9293
*/
93-
protected function redirectTo($request)
94+
protected function redirectTo(Request $request)
9495
{
9596
//
9697
}

src/Illuminate/Cache/Console/stubs/cache.stub

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ return new class extends Migration
88
{
99
/**
1010
* Run the migrations.
11-
*
12-
* @return void
1311
*/
14-
public function up()
12+
public function up(): void
1513
{
1614
Schema::create('cache', function (Blueprint $table) {
1715
$table->string('key')->primary();
@@ -28,10 +26,8 @@ return new class extends Migration
2826

2927
/**
3028
* Reverse the migrations.
31-
*
32-
* @return void
3329
*/
34-
public function down()
30+
public function down(): void
3531
{
3632
Schema::dropIfExists('cache');
3733
Schema::dropIfExists('cache_locks');

src/Illuminate/Contracts/Database/Eloquent/CastsAttributes.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Illuminate\Contracts\Database\Eloquent;
44

5+
use Illuminate\Database\Eloquent\Model;
6+
57
interface CastsAttributes
68
{
79
/**
@@ -13,7 +15,7 @@ interface CastsAttributes
1315
* @param array $attributes
1416
* @return mixed
1517
*/
16-
public function get($model, string $key, $value, array $attributes);
18+
public function get(Model $model, string $key, mixed $value, array $attributes);
1719

1820
/**
1921
* Transform the attribute to its underlying model values.
@@ -24,5 +26,5 @@ public function get($model, string $key, $value, array $attributes);
2426
* @param array $attributes
2527
* @return mixed
2628
*/
27-
public function set($model, string $key, $value, array $attributes);
29+
public function set(Model $model, string $key, mixed $value, array $attributes);
2830
}

src/Illuminate/Contracts/Database/Eloquent/CastsInboundAttributes.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Illuminate\Contracts\Database\Eloquent;
44

5+
use Illuminate\Database\Eloquent\Model;
6+
57
interface CastsInboundAttributes
68
{
79
/**
@@ -13,5 +15,5 @@ interface CastsInboundAttributes
1315
* @param array $attributes
1416
* @return mixed
1517
*/
16-
public function set($model, string $key, $value, array $attributes);
18+
public function set(Model $model, string $key, mixed $value, array $attributes);
1719
}

src/Illuminate/Contracts/Database/Eloquent/SerializesCastableAttributes.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Illuminate\Contracts\Database\Eloquent;
44

5+
use Illuminate\Database\Eloquent\Model;
6+
57
interface SerializesCastableAttributes
68
{
79
/**
@@ -13,5 +15,5 @@ interface SerializesCastableAttributes
1315
* @param array $attributes
1416
* @return mixed
1517
*/
16-
public function serialize($model, string $key, $value, array $attributes);
18+
public function serialize(Model $model, string $key, mixed $value, array $attributes);
1719
}

src/Illuminate/Contracts/Validation/DataAwareRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ interface DataAwareRule
1010
* @param array $data
1111
* @return $this
1212
*/
13-
public function setData($data);
13+
public function setData(array $data);
1414
}

src/Illuminate/Contracts/Validation/InvokableRule.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Illuminate\Contracts\Validation;
44

5+
use Closure;
6+
57
interface InvokableRule
68
{
79
/**
@@ -12,5 +14,5 @@ interface InvokableRule
1214
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
1315
* @return void
1416
*/
15-
public function __invoke($attribute, $value, $fail);
17+
public function __invoke(string $attribute, mixed $value, Closure $fail);
1618
}

src/Illuminate/Contracts/Validation/ValidatorAwareRule.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Illuminate\Contracts\Validation;
44

5+
use Illuminate\Validation\Validator;
6+
57
interface ValidatorAwareRule
68
{
79
/**
@@ -10,5 +12,5 @@ interface ValidatorAwareRule
1012
* @param \Illuminate\Validation\Validator $validator
1113
* @return $this
1214
*/
13-
public function setValidator($validator);
15+
public function setValidator(Validator $validator);
1416
}

src/Illuminate/Database/Console/Factories/stubs/factory.stub

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class {{ factory }}Factory extends Factory
1414
*
1515
* @return array<string, mixed>
1616
*/
17-
public function definition()
17+
public function definition(): array
1818
{
1919
return [
2020
//

src/Illuminate/Database/Console/Seeds/stubs/seeder.stub

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ class {{ class }} extends Seeder
99
{
1010
/**
1111
* Run the database seeds.
12-
*
13-
* @return void
1412
*/
15-
public function run()
13+
public function run(): void
1614
{
1715
//
1816
}

0 commit comments

Comments
 (0)