Skip to content

Commit b7efd3e

Browse files
committed
feat(config): Add Laravel configuration files for version 8.0 and 9.0
- Introduced new configuration files for Laravel 8.0 and 9.0. - Implemented rules for transforming function calls to static calls. - Added LaravelLevelSetList for managing Laravel version sets. - Ensured compatibility with existing configuration structure.
1 parent c751fd7 commit b7efd3e

File tree

6 files changed

+89
-16
lines changed

6 files changed

+89
-16
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ return RectorConfig::configure()
4949
// ...
5050
->registerDecoratingNodeVisitor(ParentConnectingVisitor::class)
5151
->withConfiguredRule(RenameToConventionalCaseNameRector::class, [
52-
'assertMatches*Snapshot',
53-
'beforeEach',
54-
'PDO',
52+
'assertMatches*Snapshot', // Exclude `spatie/pest-plugin-snapshots` function name
53+
'beforeEach', // Exclude `pestphp/pest` function name
54+
'PDO', // Exclude `ext-pdo` class name
5555
])
5656
// ...
5757
->withRules([

config/set/laravel/laravel-80.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/** @noinspection PhpInternalEntityUsedInspection */
4+
5+
declare(strict_types=1);
6+
7+
/**
8+
* Copyright (c) 2025-2026 guanguans<ityaozm@gmail.com>
9+
*
10+
* For the full copyright and license information, please view
11+
* the LICENSE file that was distributed with this source code.
12+
*
13+
* @see https://github.com/guanguans/rector-rules
14+
*/
15+
16+
use Illuminate\Support\Str;
17+
use Rector\Config\RectorConfig;
18+
use Rector\Transform\Rector\FuncCall\FuncCallToStaticCallRector;
19+
use Rector\Transform\ValueObject\FuncCallToStaticCall;
20+
21+
return static function (RectorConfig $rectorConfig): void {
22+
$rectorConfig->import(__DIR__.'/../../config.php');
23+
24+
/** @see https://github.com/laravel/framework/commit/d41e88519a6e4203b0986a40c5ac8670a157cf59 */
25+
$rectorConfig->ruleWithConfiguration(FuncCallToStaticCallRector::class, [
26+
new FuncCallToStaticCall('str', Str::class, 'of'),
27+
]);
28+
};

config/set/laravel/laravel-90.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/** @noinspection PhpInternalEntityUsedInspection */
4+
5+
declare(strict_types=1);
6+
7+
/**
8+
* Copyright (c) 2025-2026 guanguans<ityaozm@gmail.com>
9+
*
10+
* For the full copyright and license information, please view
11+
* the LICENSE file that was distributed with this source code.
12+
*
13+
* @see https://github.com/guanguans/rector-rules
14+
*/
15+
16+
use Illuminate\Support\Str;
17+
use Rector\Config\RectorConfig;
18+
use Rector\Transform\Rector\StaticCall\StaticCallToFuncCallRector;
19+
use Rector\Transform\ValueObject\StaticCallToFuncCall;
20+
21+
return static function (RectorConfig $rectorConfig): void {
22+
$rectorConfig->import(__DIR__.'/../../config.php');
23+
24+
/** @see https://github.com/laravel/framework/commit/d41e88519a6e4203b0986a40c5ac8670a157cf59 */
25+
$rectorConfig->ruleWithConfiguration(StaticCallToFuncCallRector::class, [
26+
new StaticCallToFuncCall(Str::class, 'of', 'str'),
27+
]);
28+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
/** @noinspection PhpInternalEntityUsedInspection */
4+
5+
declare(strict_types=1);
6+
7+
/**
8+
* Copyright (c) 2025-2026 guanguans<ityaozm@gmail.com>
9+
*
10+
* For the full copyright and license information, please view
11+
* the LICENSE file that was distributed with this source code.
12+
*
13+
* @see https://github.com/guanguans/rector-rules
14+
*/
15+
16+
use Carbon\Carbon;
17+
use Illuminate\Support\Carbon as IlluminateCarbon;
18+
use Rector\Config\RectorConfig;
19+
use Rector\Renaming\Rector\Name\RenameClassRector;
20+
21+
return static function (RectorConfig $rectorConfig): void {
22+
$rectorConfig->import(__DIR__.'/../../config.php');
23+
$rectorConfig->ruleWithConfiguration(RenameClassRector::class, [
24+
Carbon::class => IlluminateCarbon::class,
25+
]);
26+
};

rector.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@
1717
*/
1818

1919
use Ergebnis\Rector\Rules\Arrays\SortAssociativeArrayByKeyRector;
20-
use Guanguans\RectorRules\Contract\ThrowableContract;
2120
use Guanguans\RectorRules\Rector\Array_\SortListItemOfSameScalarTypeRector;
2221
use Guanguans\RectorRules\Rector\File\AddNoinspectionDocblockToFileFirstStmtRector;
2322
use Guanguans\RectorRules\Rector\Name\RenameToConventionalCaseNameRector;
2423
use Guanguans\RectorRules\Rector\New_\NewExceptionToNewAnonymousExtendsExceptionImplementsRector;
25-
use Illuminate\Support\Str;
2624
use PhpParser\NodeVisitor\ParentConnectingVisitor;
2725
use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector;
2826
use Rector\CodeQuality\Rector\LogicalAnd\LogicalToBooleanRector;
@@ -49,10 +47,6 @@
4947
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;
5048
use Rector\Set\ValueObject\DowngradeLevelSetList;
5149
use Rector\Set\ValueObject\SetList;
52-
use Rector\Transform\Rector\FuncCall\FuncCallToStaticCallRector;
53-
use Rector\Transform\Rector\StaticCall\StaticCallToFuncCallRector;
54-
use Rector\Transform\ValueObject\FuncCallToStaticCall;
55-
use Rector\Transform\ValueObject\StaticCallToFuncCall;
5650
use Rector\ValueObject\PhpVersion;
5751
use Rector\ValueObject\Visibility;
5852
use Rector\Visibility\Rector\ClassMethod\ChangeMethodVisibilityRector;
@@ -103,6 +97,7 @@
10397
// )
10498
->withSets([
10599
Guanguans\RectorRules\Set\SetList::ALL,
100+
Guanguans\RectorRules\Set\SetList::LARAVEL_80,
106101
PHPUnitSetList::PHPUNIT_90,
107102
DowngradeLevelSetList::DOWN_TO_PHP_74,
108103
SetList::DEAD_CODE,
@@ -141,7 +136,6 @@
141136
'StaticClosureCanBeUsedInspection',
142137
],
143138
])
144-
->withConfiguredRule(NewExceptionToNewAnonymousExtendsExceptionImplementsRector::class, [ThrowableContract::class])
145139
->registerDecoratingNodeVisitor(ParentConnectingVisitor::class)
146140
->withConfiguredRule(RenameToConventionalCaseNameRector::class, [
147141
'MIT',
@@ -157,12 +151,6 @@
157151
'phpstan-ignore-next-line',
158152
'psalm-suppress',
159153
])
160-
->withConfiguredRule(StaticCallToFuncCallRector::class, [
161-
// new StaticCallToFuncCall(Str::class, 'of', 'str'),
162-
])
163-
->withConfiguredRule(FuncCallToStaticCallRector::class, [
164-
new FuncCallToStaticCall('str', Str::class, 'of'),
165-
])
166154
->withConfiguredRule(
167155
ChangeMethodVisibilityRector::class,
168156
classes(static fn (string $class, string $file): bool => str_starts_with($class, 'Guanguans\RectorRules'))

src/Set/SetList.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ final class SetList
2020
{
2121
public const ALL = __DIR__.'/../../config/set/all.php';
2222
public const COMMON = __DIR__.'/../../config/set/common.php';
23+
public const LARAVEL_80 = __DIR__.'/../../config/set/laravel/laravel-80.php';
24+
public const LARAVEL_90 = __DIR__.'/../../config/set/laravel/laravel-90.php';
25+
public const LARAVEL_COMMON = __DIR__.'/../../config/set/laravel/laravel-common.php';
2326
public const PHPBENCH = __DIR__.'/../../config/set/phpbench.php';
2427
public const PHPSTAN = __DIR__.'/../../config/set/phpstan.php';
2528
public const RECTOR = __DIR__.'/../../config/set/rector.php';

0 commit comments

Comments
 (0)