Skip to content

Commit cefbadd

Browse files
authored
Add migration rules for Laravel 5.3 (#261)
* Migrate the deprecated lists method in Laravel 5.3 * Migrate even more deprecations Laravel 5.3
1 parent da04b05 commit cefbadd

File tree

4 files changed

+124
-0
lines changed

4 files changed

+124
-0
lines changed

config/sets/laravel53.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,46 @@
33
declare(strict_types=1);
44

55
use Rector\Config\RectorConfig;
6+
use Rector\Removing\Rector\Class_\RemoveInterfacesRector;
67
use Rector\Removing\Rector\Class_\RemoveTraitUseRector;
8+
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
9+
use Rector\Renaming\Rector\Name\RenameClassRector;
10+
use Rector\Renaming\ValueObject\MethodCallRename;
11+
use Rector\Transform\Rector\StaticCall\StaticCallToFuncCallRector;
12+
use Rector\Transform\ValueObject\StaticCallToFuncCall;
713

814
return static function (RectorConfig $rectorConfig): void {
915
$rectorConfig->import(__DIR__ . '/../config.php');
16+
1017
$rectorConfig
1118
->ruleWithConfiguration(RemoveTraitUseRector::class, [
1219
// see https://laravel.com/docs/5.3/upgrade
1320
'Illuminate\Foundation\Auth\Access\AuthorizesResources',
1421
]);
22+
23+
// https://laravel.com/docs/5.3/upgrade#5.2-deprecations
24+
$rectorConfig
25+
->ruleWithConfiguration(RenameMethodRector::class, [
26+
new MethodCallRename('Illuminate\Support\Collection', 'lists', 'pluck'),
27+
new MethodCallRename('Illuminate\Database\Query\Builder', 'lists', 'pluck'),
28+
new MethodCallRename('Illuminate\Database\Eloquent\Collection', 'withHidden', 'makeVisible'),
29+
new MethodCallRename('Illuminate\Database\Eloquent\Model', 'withHidden', 'makeVisible'),
30+
]);
31+
32+
$rectorConfig
33+
->ruleWithConfiguration(RemoveInterfacesRector::class, [
34+
'Illuminate\Contracts\Bus\SelfHandling',
35+
]);
36+
37+
$rectorConfig
38+
->ruleWithConfiguration(RenameClassRector::class, [
39+
'Illuminate\Database\Eloquent\ScopeInterface' => 'Illuminate\Database\Eloquent\Scope',
40+
'Illuminate\View\Expression' => 'Illuminate\Support\HtmlString',
41+
]);
42+
43+
$rectorConfig
44+
->ruleWithConfiguration(StaticCallToFuncCallRector::class, [
45+
new StaticCallToFuncCall('Illuminate\Support\Str', 'randomBytes', 'random_bytes'),
46+
new StaticCallToFuncCall('Illuminate\Support\Str', 'equals', 'hash_equals'),
47+
]);
1548
};
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace RectorLaravel\Tests\Sets\Laravel53;
4+
5+
(new \Illuminate\Support\Collection())->lists('id');
6+
(new \Illuminate\Database\Eloquent\Builder())->lists('id');
7+
(new \Illuminate\Database\Query\Builder())->lists('id');
8+
(new \Illuminate\Database\Eloquent\Collection())->withHidden([]);
9+
(new \Illuminate\Database\Eloquent\Model())->withHidden([]);
10+
\Illuminate\Support\Str::randomBytes(16);
11+
\Illuminate\Support\Str::equals('knownString', 'userInput');
12+
13+
class SomeJob implements \Illuminate\Contracts\Bus\SelfHandling
14+
{
15+
}
16+
17+
class SomeScope implements \Illuminate\Database\Eloquent\ScopeInterface
18+
{
19+
}
20+
21+
class SomeView extends \Illuminate\View\Expression
22+
{
23+
}
24+
25+
?>
26+
-----
27+
<?php
28+
29+
namespace RectorLaravel\Tests\Sets\Laravel53;
30+
31+
(new \Illuminate\Support\Collection())->pluck('id');
32+
(new \Illuminate\Database\Eloquent\Builder())->pluck('id');
33+
(new \Illuminate\Database\Query\Builder())->pluck('id');
34+
(new \Illuminate\Database\Eloquent\Collection())->makeVisible([]);
35+
(new \Illuminate\Database\Eloquent\Model())->makeVisible([]);
36+
\random_bytes(16);
37+
\hash_equals('knownString', 'userInput');
38+
39+
class SomeJob
40+
{
41+
}
42+
43+
class SomeScope implements \Illuminate\Database\Eloquent\Scope
44+
{
45+
}
46+
47+
class SomeView extends \Illuminate\Support\HtmlString
48+
{
49+
}
50+
51+
?>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace RectorLaravel\Tests\Sets\Laravel53;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
10+
11+
final class Laravel53Test extends AbstractRectorTestCase
12+
{
13+
public static function provideData(): Iterator
14+
{
15+
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
16+
}
17+
18+
/**
19+
* @test
20+
*/
21+
#[DataProvider('provideData')]
22+
public function test(string $filePath): void
23+
{
24+
$this->doTestFile($filePath);
25+
}
26+
27+
public function provideConfigFilePath(): string
28+
{
29+
return __DIR__ . '/config/configured_rule.php';
30+
}
31+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
7+
return static function (RectorConfig $rectorConfig): void {
8+
$rectorConfig->import(__DIR__ . '/../../../../config/sets/laravel53.php');
9+
};

0 commit comments

Comments
 (0)