Skip to content

Commit 2d5d8a5

Browse files
committed
chore: update to new RectorConfig::configure() syntax for config
1 parent dd39902 commit 2d5d8a5

File tree

1 file changed

+59
-69
lines changed

1 file changed

+59
-69
lines changed

rector.php

Lines changed: 59 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@
5353
use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector;
5454
use Rector\PHPUnit\Set\PHPUnitSetList;
5555
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
56-
use Rector\Set\ValueObject\LevelSetList;
57-
use Rector\Set\ValueObject\SetList;
5856
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
5957
use Rector\Strict\Rector\If_\BooleanInIfConditionRuleFixerRector;
6058
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnNeverTypeRector;
@@ -64,38 +62,34 @@
6462
use Utils\Rector\RemoveErrorSuppressInTryCatchStmtsRector;
6563
use Utils\Rector\UnderscoreToCamelCaseVariableNameRector;
6664

67-
return static function (RectorConfig $rectorConfig): void {
68-
$rectorConfig->sets([
69-
SetList::DEAD_CODE,
70-
LevelSetList::UP_TO_PHP_81,
65+
return RectorConfig::configure()
66+
->withPhpSets(php81: true)
67+
->withPreparedSets(deadCode: true)
68+
->withSets([
7169
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
7270
PHPUnitSetList::PHPUNIT_100,
73-
]);
74-
75-
$rectorConfig->parallel(120, 8, 10);
76-
77-
// Github action cache
78-
$rectorConfig->cacheClass(FileCacheStorage::class);
79-
if (is_dir('/tmp')) {
80-
$rectorConfig->cacheDirectory('/tmp/rector');
81-
}
82-
71+
])
72+
->withParallel(120, 8, 10)
73+
->withCache(
74+
// Github action cache or local
75+
is_dir('/tmp') ? '/tmp/rector' : sys_get_temp_dir() . '/rector',
76+
FileCacheStorage::class
77+
)
8378
// paths to refactor; solid alternative to CLI arguments
84-
$rectorConfig->paths([__DIR__ . '/app', __DIR__ . '/system', __DIR__ . '/tests', __DIR__ . '/utils']);
85-
79+
->withPaths(
80+
[__DIR__ . '/app', __DIR__ . '/system', __DIR__ . '/tests', __DIR__ . '/utils']
81+
)
8682
// do you need to include constants, class aliases or custom autoloader? files listed will be executed
87-
$rectorConfig->bootstrapFiles([
83+
->withBootstrapFiles([
8884
__DIR__ . '/system/Test/bootstrap.php',
89-
]);
90-
91-
$rectorConfig->phpstanConfigs([
85+
])
86+
->withPHPStanConfigs([
9287
__DIR__ . '/phpstan.neon.dist',
9388
__DIR__ . '/vendor/codeigniter/phpstan-codeigniter/extension.neon',
9489
__DIR__ . '/vendor/phpstan/phpstan-strict-rules/rules.neon',
95-
]);
96-
90+
])
9791
// is there a file you need to skip?
98-
$rectorConfig->skip([
92+
->withSkip([
9993
__DIR__ . '/system/Debug/Toolbar/Views/toolbar.tpl.php',
10094
__DIR__ . '/system/ThirdParty',
10195
__DIR__ . '/tests/system/Config/fixtures',
@@ -187,48 +181,44 @@
187181
AnnotationWithValueToAttributeRector::class,
188182
AnnotationToAttributeRector::class,
189183
CoversAnnotationWithValueToAttributeRector::class,
190-
]);
191-
184+
])
192185
// auto import fully qualified class names
193-
$rectorConfig->importNames();
194-
$rectorConfig->removeUnusedImports();
195-
196-
$rectorConfig->rule(DeclareStrictTypesRector::class);
197-
$rectorConfig->rule(UnderscoreToCamelCaseVariableNameRector::class);
198-
$rectorConfig->rule(SimplifyUselessVariableRector::class);
199-
$rectorConfig->rule(RemoveAlwaysElseRector::class);
200-
$rectorConfig->rule(PassStrictParameterToFunctionParameterRector::class);
201-
$rectorConfig->rule(CountArrayToEmptyArrayComparisonRector::class);
202-
$rectorConfig->rule(ChangeNestedForeachIfsToEarlyContinueRector::class);
203-
$rectorConfig->rule(ChangeIfElseValueAssignToEarlyReturnRector::class);
204-
$rectorConfig->rule(SimplifyStrposLowerRector::class);
205-
$rectorConfig->rule(CombineIfRector::class);
206-
$rectorConfig->rule(SimplifyIfReturnBoolRector::class);
207-
$rectorConfig->rule(InlineIfToExplicitIfRector::class);
208-
$rectorConfig->rule(PreparedValueToEarlyReturnRector::class);
209-
$rectorConfig->rule(ShortenElseIfRector::class);
210-
$rectorConfig->rule(SimplifyIfElseToTernaryRector::class);
211-
$rectorConfig->rule(UnusedForeachValueToArrayKeysRector::class);
212-
$rectorConfig->rule(ChangeArrayPushToArrayAssignRector::class);
213-
$rectorConfig->rule(UnnecessaryTernaryExpressionRector::class);
214-
$rectorConfig->rule(RemoveErrorSuppressInTryCatchStmtsRector::class);
215-
$rectorConfig->rule(FuncGetArgsToVariadicParamRector::class);
216-
$rectorConfig->rule(MakeInheritedMethodVisibilitySameAsParentRector::class);
217-
$rectorConfig->rule(SimplifyEmptyArrayCheckRector::class);
218-
$rectorConfig->rule(SimplifyEmptyCheckOnEmptyArrayRector::class);
219-
$rectorConfig->rule(TernaryEmptyArrayArrayDimFetchToCoalesceRector::class);
220-
$rectorConfig->rule(EmptyOnNullableObjectToInstanceOfRector::class);
221-
$rectorConfig->rule(DisallowedEmptyRuleFixerRector::class);
222-
$rectorConfig->rule(PrivatizeFinalClassPropertyRector::class);
223-
$rectorConfig->rule(CompleteDynamicPropertiesRector::class);
224-
$rectorConfig->rule(BooleanInIfConditionRuleFixerRector::class);
225-
$rectorConfig->rule(SingleInArrayToCompareRector::class);
226-
$rectorConfig->rule(VersionCompareFuncCallToConstantRector::class);
227-
$rectorConfig->rule(ExplicitBoolCompareRector::class);
228-
229-
$rectorConfig
230-
->ruleWithConfiguration(StringClassNameToClassConstantRector::class, [
231-
// keep '\\' prefix string on string '\Foo\Bar'
232-
StringClassNameToClassConstantRector::SHOULD_KEEP_PRE_SLASH => true,
233-
]);
234-
};
186+
->withImportNames(removeUnusedImports: true)
187+
->withRules([
188+
DeclareStrictTypesRector::class,
189+
UnderscoreToCamelCaseVariableNameRector::class,
190+
SimplifyUselessVariableRector::class,
191+
RemoveAlwaysElseRector::class,
192+
PassStrictParameterToFunctionParameterRector::class,
193+
CountArrayToEmptyArrayComparisonRector::class,
194+
ChangeNestedForeachIfsToEarlyContinueRector::class,
195+
ChangeIfElseValueAssignToEarlyReturnRector::class,
196+
SimplifyStrposLowerRector::class,
197+
CombineIfRector::class,
198+
SimplifyIfReturnBoolRector::class,
199+
InlineIfToExplicitIfRector::class,
200+
PreparedValueToEarlyReturnRector::class,
201+
ShortenElseIfRector::class,
202+
SimplifyIfElseToTernaryRector::class,
203+
UnusedForeachValueToArrayKeysRector::class,
204+
ChangeArrayPushToArrayAssignRector::class,
205+
UnnecessaryTernaryExpressionRector::class,
206+
RemoveErrorSuppressInTryCatchStmtsRector::class,
207+
FuncGetArgsToVariadicParamRector::class,
208+
MakeInheritedMethodVisibilitySameAsParentRector::class,
209+
SimplifyEmptyArrayCheckRector::class,
210+
SimplifyEmptyCheckOnEmptyArrayRector::class,
211+
TernaryEmptyArrayArrayDimFetchToCoalesceRector::class,
212+
EmptyOnNullableObjectToInstanceOfRector::class,
213+
DisallowedEmptyRuleFixerRector::class,
214+
PrivatizeFinalClassPropertyRector::class,
215+
CompleteDynamicPropertiesRector::class,
216+
BooleanInIfConditionRuleFixerRector::class,
217+
SingleInArrayToCompareRector::class,
218+
VersionCompareFuncCallToConstantRector::class,
219+
ExplicitBoolCompareRector::class,
220+
])
221+
->withConfiguredRule(StringClassNameToClassConstantRector::class, [
222+
// keep '\\' prefix string on string '\Foo\Bar'
223+
StringClassNameToClassConstantRector::SHOULD_KEEP_PRE_SLASH => true,
224+
]);

0 commit comments

Comments
 (0)