Skip to content

Commit dcc6129

Browse files
committed
rector php82 refactor
1 parent 1d58ad2 commit dcc6129

File tree

15 files changed

+116
-120
lines changed

15 files changed

+116
-120
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
"orchestra/testbench": "^8.0",
3232
"pestphp/pest": "^1.21",
3333
"pestphp/pest-plugin-laravel": "^1.1",
34-
"phpunit/phpunit": "^9.5"
34+
"phpunit/phpunit": "^9.5",
35+
"rector/rector": "^0.15.16"
3536
},
3637
"autoload": {
3738
"psr-4": {

rector.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
6+
use Rector\Config\RectorConfig;
7+
use Rector\Set\ValueObject\LevelSetList;
8+
9+
return static function (RectorConfig $rectorConfig): void {
10+
$rectorConfig->paths([
11+
// __DIR__.'/config',
12+
// __DIR__.'/resources',
13+
// __DIR__.'/src',
14+
// __DIR__.'/tests',
15+
// __DIR__.'/stubs/app',
16+
// __DIR__.'/stubs/config',
17+
// __DIR__.'/stubs/database',
18+
// __DIR__.'/stubs/lang',
19+
// __DIR__.'/stubs/routes',
20+
]);
21+
22+
// register a single rule
23+
// $rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
24+
25+
// define sets of rules
26+
$rectorConfig->sets([
27+
LevelSetList::UP_TO_PHP_82,
28+
]);
29+
};

src/Acl/Http/Controllers/PermissionController.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,12 @@ public function index()
1818
->orderBy('name')
1919
->paginate(request('rowsPerPage', 10))
2020
->withQueryString()
21-
->through(function ($permission) {
22-
return [
23-
'id' => $permission->id,
24-
'name' => $permission->name,
25-
'guard' => $permission->guard,
21+
->through(fn($permission) => [
22+
'id' => $permission->id,
23+
'name' => $permission->name,
24+
'guard' => $permission->guard,
2625

27-
];
28-
});
26+
]);
2927

3028
return inertia('AclPermission/PermissionIndex', [
3129
'permissions' => $permissions,

src/Acl/Http/Controllers/RoleController.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@ public function index()
1717
->orderBy('name')
1818
->paginate(request('rowsPerPage', 10))
1919
->withQueryString()
20-
->through(function ($role) {
21-
return [
22-
'id' => $role->id,
23-
'name' => $role->name,
24-
'guard_name' => $role->guard_name,
25-
];
26-
});
20+
->through(fn($role) => [
21+
'id' => $role->id,
22+
'name' => $role->name,
23+
'guard_name' => $role->guard_name,
24+
]);
2725

2826
return inertia('AclRole/RoleIndex', [
2927
'roles' => $roles,

src/Acl/Services/GetUserPermissions.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,9 @@ public function run(int $userId): array
2626

2727
private function mapPermissions(Collection $permissions): array
2828
{
29-
return $permissions->map(function ($permission) {
30-
return [
31-
'id' => $permission->id,
32-
'name' => $permission->name,
33-
];
34-
})->toArray();
29+
return $permissions->map(fn($permission) => [
30+
'id' => $permission->id,
31+
'name' => $permission->name,
32+
])->toArray();
3533
}
3634
}

src/AdminAuth/Notifications/ResetPassword.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,31 @@
77

88
class ResetPassword extends Notification
99
{
10-
/**
11-
* The password reset token.
12-
*
13-
* @var string
14-
*/
15-
public $token;
16-
1710
/**
1811
* Create a notification instance.
1912
*
2013
* @param string $token
2114
*/
22-
public function __construct($token)
15+
public function __construct(public $token)
2316
{
24-
$this->token = $token;
2517
}
2618

2719
/**
2820
* Get the notification's delivery channels.
2921
*
30-
* @param mixed $notifiable
3122
* @return array
3223
*/
33-
public function via($notifiable)
24+
public function via(mixed $notifiable)
3425
{
3526
return ['mail'];
3627
}
3728

3829
/**
3930
* Get the mail representation of the notification.
4031
*
41-
* @param mixed $notifiable
4232
* @return \Illuminate\Notifications\Messages\MailMessage
4333
*/
44-
public function toMail($notifiable)
34+
public function toMail(mixed $notifiable)
4535
{
4636
$params = [
4737
'token' => $this->token,

src/Components/Translations.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ public function render()
2828
$locale = app()->getLocale();
2929

3030
if (app()->environment('production')) {
31-
$translations = cache()->rememberForever("translations_$locale", function () use ($locale) {
32-
return $this->getTranslations($locale);
33-
});
31+
$translations = cache()->rememberForever("translations_$locale", fn() => $this->getTranslations($locale));
3432
} else {
3533
$translations = $this->getTranslations($locale);
3634
}
@@ -57,17 +55,13 @@ private function getPHPTranslations(string $directory): array
5755
}
5856

5957
return collect(File::allFiles($directory))
60-
->filter(function ($file) {
61-
return $file->getExtension() === 'php';
62-
})->flatMap(function ($file) {
63-
return Arr::dot(File::getRequire($file->getRealPath()));
64-
})->toArray();
58+
->filter(fn($file) => $file->getExtension() === 'php')->flatMap(fn($file) => Arr::dot(File::getRequire($file->getRealPath())))->toArray();
6559
}
6660

6761
private function getJsonTranslations(string $filePath): array
6862
{
6963
if (File::exists($filePath)) {
70-
return json_decode(File::get($filePath), true);
64+
return json_decode(File::get($filePath), true, 512, JSON_THROW_ON_ERROR);
7165
} else {
7266
return [];
7367
}

src/Console/FrontendPackages.php

Lines changed: 42 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,49 +16,47 @@ protected function installFrontendPackages()
1616
{
1717
$this->components->info('Installing npm packages...');
1818

19-
$this->updateNodePackages(function ($packages) {
20-
return [
21-
22-
'@inertiajs/vue3' => '^1.0.0',
23-
24-
'@tailwindcss/forms' => '^0.5.3',
25-
'@vitejs/plugin-vue' => '^4.0.0',
26-
'@vueuse/core' => '^9.1.1',
27-
28-
'autoprefixer' => '^10.4.12',
29-
'axios' => '^1.2.3',
30-
'eslint' => '^8.23.0',
31-
'eslint-config-prettier' => '^8.5.0',
32-
'eslint-plugin-vue' => '^9.4.0',
33-
'laravel-vite-plugin' => '^0.7.3',
34-
'lodash' => '^4.17.19',
35-
36-
'postcss' => '^8.4.18',
37-
'postcss-import' => '^15.0.0',
38-
'prettier' => '^2.7.1',
39-
'prettier-plugin-tailwindcss' => '^0.2.1',
40-
'primeicons' => '^6.0.1',
41-
'primevue' => '^3.16.1',
42-
43-
'@tiptap/vue-3' => '^2.0.0-beta.204',
44-
'@tiptap/starter-kit' => '^2.0.0-beta.204',
45-
'@tiptap/extension-link' => '^2.0.0-beta.204',
46-
'@tiptap/extension-underline' => '^2.0.0-beta.204',
47-
'@tiptap/extension-image' => '^2.0.0-beta.209',
48-
'@tiptap/extension-youtube' => '^2.0.0-beta.204',
49-
'@tiptap/extension-table' => '^2.0.0-beta.204',
50-
'@tiptap/extension-table-header' => '^2.0.0-beta.204',
51-
'@tiptap/extension-table-row' => '^2.0.0-beta.204',
52-
'@tiptap/extension-table-cell' => '^2.0.0-beta.204',
53-
54-
'remixicon' => '^2.5.0',
55-
'tailwindcss' => '^3.2.1',
56-
'unplugin-vue-components' => '^0.22.7',
57-
'vite' => '^4.0.4',
58-
'vue' => '^3.2.45',
59-
60-
] + $packages;
61-
});
19+
static::updateNodePackages(fn($packages) => [
20+
21+
'@inertiajs/vue3' => '^1.0.0',
22+
23+
'@tailwindcss/forms' => '^0.5.3',
24+
'@vitejs/plugin-vue' => '^4.0.0',
25+
'@vueuse/core' => '^9.1.1',
26+
27+
'autoprefixer' => '^10.4.12',
28+
'axios' => '^1.2.3',
29+
'eslint' => '^8.23.0',
30+
'eslint-config-prettier' => '^8.5.0',
31+
'eslint-plugin-vue' => '^9.4.0',
32+
'laravel-vite-plugin' => '^0.7.3',
33+
'lodash' => '^4.17.19',
34+
35+
'postcss' => '^8.4.18',
36+
'postcss-import' => '^15.0.0',
37+
'prettier' => '^2.7.1',
38+
'prettier-plugin-tailwindcss' => '^0.2.1',
39+
'primeicons' => '^6.0.1',
40+
'primevue' => '^3.16.1',
41+
42+
'@tiptap/vue-3' => '^2.0.0-beta.204',
43+
'@tiptap/starter-kit' => '^2.0.0-beta.204',
44+
'@tiptap/extension-link' => '^2.0.0-beta.204',
45+
'@tiptap/extension-underline' => '^2.0.0-beta.204',
46+
'@tiptap/extension-image' => '^2.0.0-beta.209',
47+
'@tiptap/extension-youtube' => '^2.0.0-beta.204',
48+
'@tiptap/extension-table' => '^2.0.0-beta.204',
49+
'@tiptap/extension-table-header' => '^2.0.0-beta.204',
50+
'@tiptap/extension-table-row' => '^2.0.0-beta.204',
51+
'@tiptap/extension-table-cell' => '^2.0.0-beta.204',
52+
53+
'remixicon' => '^2.5.0',
54+
'tailwindcss' => '^3.2.1',
55+
'unplugin-vue-components' => '^0.22.7',
56+
'vite' => '^4.0.4',
57+
'vue' => '^3.2.45',
58+
59+
] + $packages);
6260

6361
// Config files...
6462
copy(__DIR__.'/../../stubs/stack-configs/postcss.config.js', base_path('postcss.config.js'));
@@ -88,7 +86,7 @@ protected static function updateNodePackages(callable $callback, $dev = true)
8886

8987
$configurationKey = $dev ? 'devDependencies' : 'dependencies';
9088

91-
$packages = json_decode(file_get_contents(base_path('package.json')), true);
89+
$packages = json_decode(file_get_contents(base_path('package.json')), true, 512, JSON_THROW_ON_ERROR);
9290

9391
$packages[$configurationKey] = $callback(
9492
array_key_exists($configurationKey, $packages) ? $packages[$configurationKey] : [],

src/User/Http/Controllers/UserController.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@ public function index()
1414
->search(request('searchContext'), request('searchTerm'))
1515
->paginate(request('rowsPerPage', 10))
1616
->withQueryString()
17-
->through(function ($user) {
18-
return [
19-
'id' => $user->id,
20-
'name' => $user->name,
21-
'email' => $user->email,
22-
'created_at' => $user->created_at->format('d/m/Y H:i').'h',
23-
];
24-
});
17+
->through(fn($user) => [
18+
'id' => $user->id,
19+
'name' => $user->name,
20+
'email' => $user->email,
21+
'created_at' => $user->created_at->format('d/m/Y H:i').'h',
22+
]);
2523

2624
return inertia('User/UserIndex', [
2725
'users' => $users,

src/helpers.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
function onlyAlphaNumeric($val)
55
{
66
if ($val) {
7-
return preg_replace('/[^A-Za-z0-9]/', '', $val);
7+
return preg_replace('/[^A-Za-z0-9]/', '', (string) $val);
88
}
99

1010
return $val;

stubs/app/Http/Middleware/HandleInertiaRequests.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,13 @@ public function share(Request $request)
3636
'auth' => [
3737
'user' => $request->user(),
3838
],
39-
'ziggy' => function () use ($request) {
40-
return array_merge((new Ziggy)->toArray(), [
41-
'location' => $request->url(),
42-
]);
43-
},
44-
'flash' => function () use ($request) {
45-
return [
46-
'success' => $request->session()->get('success'),
47-
'error' => $request->session()->get('error'),
48-
];
49-
},
39+
'ziggy' => fn() => array_merge((new Ziggy)->toArray(), [
40+
'location' => $request->url(),
41+
]),
42+
'flash' => fn() => [
43+
'success' => $request->session()->get('success'),
44+
'error' => $request->session()->get('error'),
45+
],
5046
]);
5147
}
5248
}

stubs/module-stub/modules/Http/Controllers/ModuleController.stub

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@ class {{ ResourceName }}Controller extends BackendController
1616
->search(request('searchContext'), request('searchTerm'))
1717
->paginate(request('rowsPerPage', 10))
1818
->withQueryString()
19-
->through(function (${{ resourceName }}) {
20-
return [
19+
->through(fn(${{ resourceName }}) => [
2120
'id' => ${{ resourceName }}->id,
2221
// 'name' => ${{ ModuleName }}->name,
2322
'created_at' => ${{ resourceName }}->created_at->format('d/m/Y H:i') . 'h'
24-
];
25-
});
23+
]);
2624

2725
return inertia('{{ ModuleName }}/{{ ResourceName }}Index', [
2826
'${{ resourceName }}s' => ${{ resourceName }}s

tests/Overrides/Http/Kernel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Kernel extends HttpKernel
3636
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
3737
// \App\Http\Middleware\VerifyCsrfToken::class,
3838
\Illuminate\Routing\Middleware\SubstituteBindings::class,
39-
'Modular\Modular\Tests\Overrides\Http\Middleware\HandleInertiaRequests',
39+
\Modular\Modular\Tests\Overrides\Http\Middleware\HandleInertiaRequests::class,
4040
],
4141

4242
'api' => [
@@ -65,6 +65,6 @@ class Kernel extends HttpKernel
6565
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
6666
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
6767

68-
'auth.user' => 'Modular\Modular\AdminAuth\Http\Middleware\UserAuth',
68+
'auth.user' => \Modular\Modular\AdminAuth\Http\Middleware\UserAuth::class,
6969
];
7070
}

tests/Overrides/Http/Middleware/HandleInertiaRequests.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,10 @@ public function share(Request $request)
4242
// 'location' => $request->url(),
4343
// ]);
4444
// },
45-
'flash' => function () use ($request) {
46-
return [
47-
'success' => $request->session()->get('success'),
48-
'error' => $request->session()->get('error'),
49-
];
50-
},
45+
'flash' => fn() => [
46+
'success' => $request->session()->get('success'),
47+
'error' => $request->session()->get('error'),
48+
],
5149
]);
5250
}
5351
}

tests/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected function setUp(): void
2828

2929
protected function resolveApplicationHttpKernel($app)
3030
{
31-
$app->singleton('Illuminate\Contracts\Http\Kernel', 'Modular\Modular\Tests\Overrides\Http\Kernel');
31+
$app->singleton(\Illuminate\Contracts\Http\Kernel::class, \Modular\Modular\Tests\Overrides\Http\Kernel::class);
3232
}
3333

3434
protected function getPackageProviders($app)

0 commit comments

Comments
 (0)