From 5d07152cdfa0b25e7f4db6c2738933087a1c30a8 Mon Sep 17 00:00:00 2001 From: geni_jaho Date: Thu, 17 Oct 2024 18:33:17 +0200 Subject: [PATCH] Migrate the deprecated lists method in Laravel 5.3 --- config/sets/laravel53.php | 9 ++++++ tests/Sets/Laravel53/Fixture/fixture.php.inc | 23 ++++++++++++++ tests/Sets/Laravel53/Laravel53Test.php | 31 +++++++++++++++++++ .../Sets/Laravel53/config/configured_rule.php | 9 ++++++ 4 files changed, 72 insertions(+) create mode 100644 tests/Sets/Laravel53/Fixture/fixture.php.inc create mode 100644 tests/Sets/Laravel53/Laravel53Test.php create mode 100644 tests/Sets/Laravel53/config/configured_rule.php diff --git a/config/sets/laravel53.php b/config/sets/laravel53.php index 5b3ea4bc..d6c326c6 100644 --- a/config/sets/laravel53.php +++ b/config/sets/laravel53.php @@ -4,6 +4,8 @@ use Rector\Config\RectorConfig; use Rector\Removing\Rector\Class_\RemoveTraitUseRector; +use Rector\Renaming\Rector\MethodCall\RenameMethodRector; +use Rector\Renaming\ValueObject\MethodCallRename; return static function (RectorConfig $rectorConfig): void { $rectorConfig->import(__DIR__ . '/../config.php'); @@ -12,4 +14,11 @@ // see https://laravel.com/docs/5.3/upgrade 'Illuminate\Foundation\Auth\Access\AuthorizesResources', ]); + + $rectorConfig + ->ruleWithConfiguration(RenameMethodRector::class, [ + // https://laravel.com/docs/5.3/upgrade#5.2-deprecations + new MethodCallRename('Illuminate\Support\Collection', 'lists', 'pluck'), + new MethodCallRename('Illuminate\Database\Query\Builder', 'lists', 'pluck'), + ]); }; diff --git a/tests/Sets/Laravel53/Fixture/fixture.php.inc b/tests/Sets/Laravel53/Fixture/fixture.php.inc new file mode 100644 index 00000000..70fc5920 --- /dev/null +++ b/tests/Sets/Laravel53/Fixture/fixture.php.inc @@ -0,0 +1,23 @@ +lists('id'); +(new \Illuminate\Database\Eloquent\Builder())->lists('id'); +(new \Illuminate\Database\Query\Builder())->lists('id'); + +?> +----- +pluck('id'); +(new \Illuminate\Database\Eloquent\Builder())->pluck('id'); +(new \Illuminate\Database\Query\Builder())->pluck('id'); + +?> diff --git a/tests/Sets/Laravel53/Laravel53Test.php b/tests/Sets/Laravel53/Laravel53Test.php new file mode 100644 index 00000000..87f395c3 --- /dev/null +++ b/tests/Sets/Laravel53/Laravel53Test.php @@ -0,0 +1,31 @@ +doTestFile($filePath); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/Sets/Laravel53/config/configured_rule.php b/tests/Sets/Laravel53/config/configured_rule.php new file mode 100644 index 00000000..0a93a05c --- /dev/null +++ b/tests/Sets/Laravel53/config/configured_rule.php @@ -0,0 +1,9 @@ +import(__DIR__ . '/../../../../config/sets/laravel53.php'); +};