Skip to content

Commit f7f5349

Browse files
rector config
1 parent a0a3697 commit f7f5349

File tree

11 files changed

+122
-65
lines changed

11 files changed

+122
-65
lines changed

app/Filament/Resources/UserResource.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ public static function form(Form $form): Form
3636
Forms\Components\TextInput::make('password')
3737
->password()
3838
->maxLength(255)
39-
->required(fn ($component, $get, $livewire, $model, $record, $set, $state) => $record === null)
40-
->dehydrateStateUsing(fn ($state) => ! empty($state) ? Hash::make($state) : ''),
39+
->required(fn ($component, $get, $livewire, $model, $record, $set, $state): bool => $record === null)
40+
->dehydrateStateUsing(fn ($state) => empty($state) ? '' : Hash::make($state)),
4141
]);
4242
}
4343

app/Models/User.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Illuminate\Database\Eloquent\Factories\HasFactory;
1313
use Illuminate\Foundation\Auth\User as Authenticatable;
1414
use Illuminate\Notifications\Notifiable;
15-
use Illuminate\Support\Facades\Storage;
1615

1716
/**
1817
* @property int $id
@@ -32,7 +31,7 @@
3231
* @method static \Illuminate\Database\Eloquent\Builder|User newQuery()
3332
* @method static \Illuminate\Database\Eloquent\Builder|User query()
3433
*
35-
* @mixin \Eloquent
34+
* @mixin \Illuminate\Database\Eloquent\Model
3635
*/
3736
class User extends Authenticatable implements FilamentUser, HasAvatar, MustVerifyEmail
3837
{
@@ -91,6 +90,6 @@ public function canAccessPanel(Panel $panel): bool
9190

9291
public function getFilamentAvatarUrl(): ?string
9392
{
94-
return $this->avatar ? Storage::disk('public')->url($this->avatar) : 'https://gravatar.com/avatar/'.hash('sha256', $this->email);
93+
return $this->avatar ? diskPublic()->url($this->avatar) : 'https://gravatar.com/avatar/'.hash('sha256', $this->email);
9594
}
9695
}

app/helpers.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
use App\Models\User;
44
use Illuminate\Contracts\Container\BindingResolutionException;
5+
use Illuminate\Filesystem\FilesystemAdapter;
56
use Illuminate\Support\Facades\Auth;
7+
use Illuminate\Support\Facades\Storage;
68

79
if (! function_exists('formatVND')) {
810
function formatVND(int $number): string
@@ -23,6 +25,14 @@ function authUser(): User
2325
}
2426
}
2527

28+
if (! function_exists('diskPublic')) {
29+
function diskPublic(): FilesystemAdapter
30+
{
31+
// @phpstan-ignore-next-line
32+
return Storage::disk('public');
33+
}
34+
}
35+
2636
if (! function_exists('typeString')) {
2737
function typeString(mixed $value, string $fallback = ''): string
2838
{

composer.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
"name": "laravel/laravel",
33
"type": "project",
44
"description": "The skeleton application for the Laravel framework.",
5-
"keywords": ["laravel", "framework"],
5+
"keywords": [
6+
"laravel",
7+
"framework"
8+
],
69
"license": "MIT",
710
"require": {
811
"php": "^8.2",
@@ -54,6 +57,7 @@
5457
],
5558
"ide": [
5659
"php artisan ide-helper:models --write --reset",
60+
"./vendor/bin/rector",
5761
"./vendor/bin/pint"
5862
]
5963
},

config/ide-helper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@
180180
*/
181181

182182
'extra' => [
183-
'Eloquent' => ['Illuminate\Database\Eloquent\Builder', 'Illuminate\Database\Query\Builder'],
184-
'Session' => ['Illuminate\Session\Store'],
183+
'Eloquent' => [\Illuminate\Database\Eloquent\Builder::class, \Illuminate\Database\Query\Builder::class],
184+
'Session' => [\Illuminate\Session\Store::class],
185185
],
186186

187187
'magic' => [],

database/factories/UserFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function definition(): array
3737
*/
3838
public function unverified(): static
3939
{
40-
return $this->state(fn (array $attributes) => [
40+
return $this->state(fn (array $attributes): array => [
4141
'email_verified_at' => null,
4242
]);
4343
}

database/migrations/0001_01_01_000000_create_users_table.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,30 @@
1111
*/
1212
public function up(): void
1313
{
14-
Schema::create('users', function (Blueprint $table) {
15-
$table->id();
16-
$table->string('name');
17-
$table->string('email')->unique();
18-
$table->string('avatar')->nullable();
19-
$table->timestamp('email_verified_at')->nullable();
20-
$table->string('password');
21-
$table->rememberToken();
22-
$table->timestamps();
14+
Schema::create('users', function (Blueprint $blueprint): void {
15+
$blueprint->id();
16+
$blueprint->string('name');
17+
$blueprint->string('email')->unique();
18+
$blueprint->string('avatar')->nullable();
19+
$blueprint->timestamp('email_verified_at')->nullable();
20+
$blueprint->string('password');
21+
$blueprint->rememberToken();
22+
$blueprint->timestamps();
2323
});
2424

25-
Schema::create('password_reset_tokens', function (Blueprint $table) {
26-
$table->string('email')->primary();
27-
$table->string('token');
28-
$table->timestamp('created_at')->nullable();
25+
Schema::create('password_reset_tokens', function (Blueprint $blueprint): void {
26+
$blueprint->string('email')->primary();
27+
$blueprint->string('token');
28+
$blueprint->timestamp('created_at')->nullable();
2929
});
3030

31-
Schema::create('sessions', function (Blueprint $table) {
32-
$table->string('id')->primary();
33-
$table->foreignId('user_id')->nullable()->index();
34-
$table->string('ip_address', 45)->nullable();
35-
$table->text('user_agent')->nullable();
36-
$table->longText('payload');
37-
$table->integer('last_activity')->index();
31+
Schema::create('sessions', function (Blueprint $blueprint): void {
32+
$blueprint->string('id')->primary();
33+
$blueprint->foreignId('user_id')->nullable()->index();
34+
$blueprint->string('ip_address', 45)->nullable();
35+
$blueprint->text('user_agent')->nullable();
36+
$blueprint->longText('payload');
37+
$blueprint->integer('last_activity')->index();
3838
});
3939
}
4040

database/migrations/0001_01_01_000001_create_cache_table.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
*/
1212
public function up(): void
1313
{
14-
Schema::create('cache', function (Blueprint $table) {
15-
$table->string('key')->primary();
16-
$table->mediumText('value');
17-
$table->integer('expiration');
14+
Schema::create('cache', function (Blueprint $blueprint): void {
15+
$blueprint->string('key')->primary();
16+
$blueprint->mediumText('value');
17+
$blueprint->integer('expiration');
1818
});
1919

20-
Schema::create('cache_locks', function (Blueprint $table) {
21-
$table->string('key')->primary();
22-
$table->string('owner');
23-
$table->integer('expiration');
20+
Schema::create('cache_locks', function (Blueprint $blueprint): void {
21+
$blueprint->string('key')->primary();
22+
$blueprint->string('owner');
23+
$blueprint->integer('expiration');
2424
});
2525
}
2626

database/migrations/0001_01_01_000002_create_jobs_table.php

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,37 @@
1111
*/
1212
public function up(): void
1313
{
14-
Schema::create('jobs', function (Blueprint $table) {
15-
$table->id();
16-
$table->string('queue')->index();
17-
$table->longText('payload');
18-
$table->unsignedTinyInteger('attempts');
19-
$table->unsignedInteger('reserved_at')->nullable();
20-
$table->unsignedInteger('available_at');
21-
$table->unsignedInteger('created_at');
14+
Schema::create('jobs', function (Blueprint $blueprint): void {
15+
$blueprint->id();
16+
$blueprint->string('queue')->index();
17+
$blueprint->longText('payload');
18+
$blueprint->unsignedTinyInteger('attempts');
19+
$blueprint->unsignedInteger('reserved_at')->nullable();
20+
$blueprint->unsignedInteger('available_at');
21+
$blueprint->unsignedInteger('created_at');
2222
});
2323

24-
Schema::create('job_batches', function (Blueprint $table) {
25-
$table->string('id')->primary();
26-
$table->string('name');
27-
$table->integer('total_jobs');
28-
$table->integer('pending_jobs');
29-
$table->integer('failed_jobs');
30-
$table->longText('failed_job_ids');
31-
$table->mediumText('options')->nullable();
32-
$table->integer('cancelled_at')->nullable();
33-
$table->integer('created_at');
34-
$table->integer('finished_at')->nullable();
24+
Schema::create('job_batches', function (Blueprint $blueprint): void {
25+
$blueprint->string('id')->primary();
26+
$blueprint->string('name');
27+
$blueprint->integer('total_jobs');
28+
$blueprint->integer('pending_jobs');
29+
$blueprint->integer('failed_jobs');
30+
$blueprint->longText('failed_job_ids');
31+
$blueprint->mediumText('options')->nullable();
32+
$blueprint->integer('cancelled_at')->nullable();
33+
$blueprint->integer('created_at');
34+
$blueprint->integer('finished_at')->nullable();
3535
});
3636

37-
Schema::create('failed_jobs', function (Blueprint $table) {
38-
$table->id();
39-
$table->string('uuid')->unique();
40-
$table->text('connection');
41-
$table->text('queue');
42-
$table->longText('payload');
43-
$table->longText('exception');
44-
$table->timestamp('failed_at')->useCurrent();
37+
Schema::create('failed_jobs', function (Blueprint $blueprint): void {
38+
$blueprint->id();
39+
$blueprint->string('uuid')->unique();
40+
$blueprint->text('connection');
41+
$blueprint->text('queue');
42+
$blueprint->longText('payload');
43+
$blueprint->longText('exception');
44+
$blueprint->timestamp('failed_at')->useCurrent();
4545
});
4646
}
4747

rector.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
use Rector\CodingStyle\Rector\ArrowFunction\StaticArrowFunctionRector;
4+
use Rector\CodingStyle\Rector\Closure\StaticClosureRector;
5+
use Rector\Config\RectorConfig;
6+
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector;
7+
use RectorLaravel\Set\LaravelLevelSetList;
8+
use RectorLaravel\Set\LaravelSetList;
9+
10+
return RectorConfig::configure()
11+
->withPaths([
12+
__DIR__.'/app',
13+
__DIR__.'/config',
14+
__DIR__.'/database',
15+
__DIR__.'/routes',
16+
])
17+
// register single rule
18+
->withRules([
19+
TypedPropertyFromStrictConstructorRector::class,
20+
])
21+
->withSkip([
22+
StaticArrowFunctionRector::class,
23+
StaticClosureRector::class,
24+
])
25+
// here we can define, what prepared sets of rules will be applied
26+
->withPreparedSets(
27+
deadCode: true,
28+
codeQuality: true,
29+
codingStyle: true,
30+
typeDeclarations: true,
31+
privatization: true,
32+
naming: true,
33+
instanceOf: true,
34+
earlyReturn: true,
35+
strictBooleans: true,
36+
)
37+
->withSets([
38+
LaravelLevelSetList::UP_TO_LARAVEL_110,
39+
LaravelSetList::LARAVEL_ARRAY_STR_FUNCTION_TO_STATIC_CALL,
40+
LaravelSetList::LARAVEL_CODE_QUALITY,
41+
LaravelSetList::LARAVEL_ELOQUENT_MAGIC_METHOD_TO_QUERY_BUILDER,
42+
LaravelSetList::LARAVEL_FACADE_ALIASES_TO_FULL_NAMES,
43+
LaravelSetList::LARAVEL_LEGACY_FACTORIES_TO_CLASSES,
44+
]);

0 commit comments

Comments
 (0)