|
3 | 3 | declare(strict_types=1); |
4 | 4 |
|
5 | 5 | use Rector\Caching\ValueObject\Storage\FileCacheStorage; |
6 | | -use Rector\CodeQuality\Rector\BooleanAnd\SimplifyEmptyArrayCheckRector; |
7 | | -use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector; |
8 | | -use Rector\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRector; |
9 | | -use Rector\CodeQuality\Rector\Expression\InlineIfToExplicitIfRector; |
10 | | -use Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector; |
11 | | -use Rector\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector; |
12 | | -use Rector\CodeQuality\Rector\FuncCall\SimplifyRegexPatternRector; |
13 | | -use Rector\CodeQuality\Rector\FuncCall\SimplifyStrposLowerRector; |
14 | | -use Rector\CodeQuality\Rector\FuncCall\SingleInArrayToCompareRector; |
15 | 6 | use Rector\CodeQuality\Rector\FunctionLike\SimplifyUselessVariableRector; |
16 | | -use Rector\CodeQuality\Rector\If_\CombineIfRector; |
17 | | -use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector; |
18 | | -use Rector\CodeQuality\Rector\If_\ShortenElseIfRector; |
19 | | -use Rector\CodeQuality\Rector\If_\SimplifyIfElseToTernaryRector; |
20 | | -use Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector; |
21 | | -use Rector\CodeQuality\Rector\Ternary\TernaryEmptyArrayArrayDimFetchToCoalesceRector; |
22 | | -use Rector\CodeQuality\Rector\Ternary\UnnecessaryTernaryExpressionRector; |
23 | 7 | use Rector\CodingStyle\Rector\ClassMethod\FuncGetArgsToVariadicParamRector; |
24 | 8 | use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector; |
25 | 9 | use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector; |
|
32 | 16 | use Rector\EarlyReturn\Rector\Return_\PreparedValueToEarlyReturnRector; |
33 | 17 | use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector; |
34 | 18 | use Rector\Php73\Rector\FuncCall\StringifyStrNeedlesRector; |
35 | | -use Rector\PHPUnit\AnnotationsToAttributes\Rector\Class_\AnnotationWithValueToAttributeRector; |
36 | | -use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector; |
37 | | -use Rector\PHPUnit\Set\PHPUnitSetList; |
38 | 19 | use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector; |
39 | | -use Rector\Set\ValueObject\LevelSetList; |
40 | | -use Rector\Set\ValueObject\SetList; |
41 | 20 | use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector; |
42 | 21 | use Rector\TypeDeclaration\Rector\Empty_\EmptyOnNullableObjectToInstanceOfRector; |
43 | 22 | use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector; |
44 | | -use Rector\ValueObject\PhpVersion; |
45 | 23 |
|
46 | | -return static function (RectorConfig $rectorConfig): void { |
47 | | - $rectorConfig->sets([ |
48 | | - SetList::DEAD_CODE, |
49 | | - LevelSetList::UP_TO_PHP_74, |
50 | | - PHPUnitSetList::PHPUNIT_CODE_QUALITY, |
51 | | - PHPUnitSetList::PHPUNIT_100, |
52 | | - ]); |
53 | | - |
54 | | - $rectorConfig->parallel(); |
55 | | - |
56 | | - // Github action cache |
57 | | - $rectorConfig->cacheClass(FileCacheStorage::class); |
58 | | - if (is_dir('/tmp')) { |
59 | | - $rectorConfig->cacheDirectory('/tmp/rector'); |
60 | | - } |
61 | | - |
62 | | - // The paths to refactor (can also be supplied with CLI arguments) |
63 | | - $rectorConfig->paths([ |
64 | | - __DIR__ . '/src/', |
65 | | - ]); |
66 | | - |
67 | | - // Include Composer's autoload - required for global execution, remove if running locally |
68 | | - $rectorConfig->autoloadPaths([ |
| 24 | +return RectorConfig::configure() |
| 25 | + ->withPhpSets(php81: true) |
| 26 | + ->withPreparedSets(deadCode: true, codeQuality: true) |
| 27 | + ->withComposerBased(phpunit: true) |
| 28 | + ->withParallel(120, 8, 10) |
| 29 | + ->withCache( |
| 30 | + is_dir('/tmp') ? '/tmp/rector' : null, |
| 31 | + FileCacheStorage::class, |
| 32 | + ) |
| 33 | + ->withPaths([ |
| 34 | + __DIR__ . '/src', |
| 35 | + ]) |
| 36 | + ->withAutoloadPaths([ |
69 | 37 | __DIR__ . '/vendor/autoload.php', |
70 | | - ]); |
71 | | - |
72 | | - // Do you need to include constants, class aliases, or a custom autoloader? |
73 | | - $rectorConfig->bootstrapFiles([ |
74 | | - realpath(getcwd()) . '/vendor/codeigniter4/framework/system/Test/bootstrap.php', |
75 | | - ]); |
76 | | - |
77 | | - if (is_file(__DIR__ . '/phpstan.neon.dist')) { |
78 | | - $rectorConfig->phpstanConfig(__DIR__ . '/phpstan.neon.dist'); |
79 | | - } |
80 | | - |
81 | | - // Set the target version for refactoring |
82 | | - $rectorConfig->phpVersion(PhpVersion::PHP_74); |
83 | | - |
84 | | - // Auto-import fully qualified class names |
85 | | - $rectorConfig->importNames(); |
86 | | - |
87 | | - // Are there files or rules you need to skip? |
88 | | - $rectorConfig->skip([ |
89 | | - __DIR__ . '/src/Views', |
90 | | - |
| 38 | + ]) |
| 39 | + ->withBootstrapFiles([ |
| 40 | + __DIR__ . '/vendor/codeigniter4/framework/system/Test/bootstrap.php', |
| 41 | + ]) |
| 42 | + ->withPHPStanConfigs([ |
| 43 | + __DIR__ . '/phpstan.neon.dist', |
| 44 | + ]) |
| 45 | + ->withImportNames(removeUnusedImports: true) |
| 46 | + ->withSkip([ |
91 | 47 | StringifyStrNeedlesRector::class, |
92 | | - YieldDataProviderRector::class, |
93 | | - |
94 | | - // Note: requires php 8 |
95 | | - RemoveUnusedPromotedPropertyRector::class, |
96 | | - AnnotationWithValueToAttributeRector::class, |
97 | | - |
98 | | - // May load view files directly when detecting classes |
| 48 | + RemoveUnusedPromotedPropertyRector::class, // Note: requires php 8 |
| 49 | + ]) |
| 50 | + ->withRules([ |
| 51 | + ChangeIfElseValueAssignToEarlyReturnRector::class, |
| 52 | + ChangeNestedForeachIfsToEarlyContinueRector::class, |
| 53 | + CountArrayToEmptyArrayComparisonRector::class, |
| 54 | + DisallowedEmptyRuleFixerRector::class, |
| 55 | + EmptyOnNullableObjectToInstanceOfRector::class, |
| 56 | + FuncGetArgsToVariadicParamRector::class, |
| 57 | + MakeInheritedMethodVisibilitySameAsParentRector::class, |
| 58 | + PreparedValueToEarlyReturnRector::class, |
| 59 | + PrivatizeFinalClassPropertyRector::class, |
| 60 | + RemoveAlwaysElseRector::class, |
| 61 | + SimplifyUselessVariableRector::class, |
99 | 62 | StringClassNameToClassConstantRector::class, |
| 63 | + VersionCompareFuncCallToConstantRector::class, |
| 64 | + ]) |
| 65 | + ->withConfiguredRule(TypedPropertyFromAssignsRector::class, [ |
| 66 | + // Allow public property inlining when BC breaks are acceptable. |
| 67 | + TypedPropertyFromAssignsRector::INLINE_PUBLIC => true, |
100 | 68 | ]); |
101 | | - |
102 | | - // auto import fully qualified class names |
103 | | - $rectorConfig->importNames(); |
104 | | - |
105 | | - $rectorConfig->rule(SimplifyUselessVariableRector::class); |
106 | | - $rectorConfig->rule(RemoveAlwaysElseRector::class); |
107 | | - $rectorConfig->rule(CountArrayToEmptyArrayComparisonRector::class); |
108 | | - $rectorConfig->rule(ChangeNestedForeachIfsToEarlyContinueRector::class); |
109 | | - $rectorConfig->rule(ChangeIfElseValueAssignToEarlyReturnRector::class); |
110 | | - $rectorConfig->rule(SimplifyStrposLowerRector::class); |
111 | | - $rectorConfig->rule(CombineIfRector::class); |
112 | | - $rectorConfig->rule(SimplifyIfReturnBoolRector::class); |
113 | | - $rectorConfig->rule(InlineIfToExplicitIfRector::class); |
114 | | - $rectorConfig->rule(PreparedValueToEarlyReturnRector::class); |
115 | | - $rectorConfig->rule(ShortenElseIfRector::class); |
116 | | - $rectorConfig->rule(SimplifyIfElseToTernaryRector::class); |
117 | | - $rectorConfig->rule(UnusedForeachValueToArrayKeysRector::class); |
118 | | - $rectorConfig->rule(ChangeArrayPushToArrayAssignRector::class); |
119 | | - $rectorConfig->rule(UnnecessaryTernaryExpressionRector::class); |
120 | | - $rectorConfig->rule(SimplifyRegexPatternRector::class); |
121 | | - $rectorConfig->rule(FuncGetArgsToVariadicParamRector::class); |
122 | | - $rectorConfig->rule(MakeInheritedMethodVisibilitySameAsParentRector::class); |
123 | | - $rectorConfig->rule(SimplifyEmptyArrayCheckRector::class); |
124 | | - $rectorConfig->rule(SimplifyEmptyCheckOnEmptyArrayRector::class); |
125 | | - $rectorConfig->rule(TernaryEmptyArrayArrayDimFetchToCoalesceRector::class); |
126 | | - $rectorConfig->rule(EmptyOnNullableObjectToInstanceOfRector::class); |
127 | | - $rectorConfig->rule(DisallowedEmptyRuleFixerRector::class); |
128 | | - $rectorConfig |
129 | | - ->ruleWithConfiguration(TypedPropertyFromAssignsRector::class, [ |
130 | | - /** |
131 | | - * The INLINE_PUBLIC value is default to false to avoid BC break, |
132 | | - * if you use for libraries and want to preserve BC break, you don't |
133 | | - * need to configure it, as it included in LevelSetList::UP_TO_PHP_74 |
134 | | - * Set to true for projects that allow BC break |
135 | | - */ |
136 | | - TypedPropertyFromAssignsRector::INLINE_PUBLIC => true, |
137 | | - ]); |
138 | | - $rectorConfig->rule(StringClassNameToClassConstantRector::class); |
139 | | - $rectorConfig->rule(PrivatizeFinalClassPropertyRector::class); |
140 | | - $rectorConfig->rule(CompleteDynamicPropertiesRector::class); |
141 | | - $rectorConfig->rule(SingleInArrayToCompareRector::class); |
142 | | - $rectorConfig->rule(VersionCompareFuncCallToConstantRector::class); |
143 | | - $rectorConfig->rule(ExplicitBoolCompareRector::class); |
144 | | -}; |
0 commit comments