|
1 | 1 | <?php |
2 | 2 |
|
3 | | -use Rector\Config\RectorConfig; |
| 3 | +declare(strict_types=1); |
| 4 | + |
4 | 5 | use Rector\CodeQuality\Rector\BooleanAnd\SimplifyEmptyArrayCheckRector; |
| 6 | +use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector; |
5 | 7 | use Rector\CodeQuality\Rector\Expression\InlineIfToExplicitIfRector; |
6 | | -use Rector\CodeQuality\Rector\For_\ForToForeachRector; |
7 | 8 | use Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector; |
8 | | -use Rector\CodeQuality\Rector\FuncCall\AddPregQuoteDelimiterRector; |
9 | 9 | use Rector\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector; |
10 | 10 | use Rector\CodeQuality\Rector\FuncCall\SimplifyRegexPatternRector; |
11 | 11 | use Rector\CodeQuality\Rector\FuncCall\SimplifyStrposLowerRector; |
|
18 | 18 | use Rector\CodingStyle\Rector\ClassMethod\FuncGetArgsToVariadicParamRector; |
19 | 19 | use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector; |
20 | 20 | use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector; |
| 21 | +use Rector\Config\RectorConfig; |
21 | 22 | use Rector\Core\ValueObject\PhpVersion; |
22 | 23 | use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPromotedPropertyRector; |
23 | | -use Rector\DeadCode\Rector\MethodCall\RemoveEmptyMethodCallRector; |
24 | 24 | use Rector\EarlyReturn\Rector\Foreach_\ChangeNestedForeachIfsToEarlyContinueRector; |
25 | 25 | use Rector\EarlyReturn\Rector\If_\ChangeIfElseValueAssignToEarlyReturnRector; |
26 | 26 | use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector; |
27 | 27 | use Rector\EarlyReturn\Rector\Return_\PreparedValueToEarlyReturnRector; |
28 | 28 | use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector; |
29 | | -use Rector\Php56\Rector\FunctionLike\AddDefaultValueForUndefinedVariableRector; |
30 | 29 | use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector; |
31 | 30 | use Rector\Php73\Rector\FuncCall\StringifyStrNeedlesRector; |
32 | | -use Rector\Php74\Rector\Property\TypedPropertyRector; |
| 31 | +use Rector\PHPUnit\AnnotationsToAttributes\Rector\Class_\AnnotationWithValueToAttributeRector; |
| 32 | +use Rector\PHPUnit\CodeQuality\Rector\Class_\YieldDataProviderRector; |
33 | 33 | use Rector\PHPUnit\Set\PHPUnitSetList; |
34 | | -use Rector\PSR4\Rector\FileWithoutNamespace\NormalizeNamespaceByPSR4ComposerAutoloadRector; |
| 34 | +use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector; |
35 | 35 | use Rector\Set\ValueObject\LevelSetList; |
36 | 36 | use Rector\Set\ValueObject\SetList; |
| 37 | +use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector; |
37 | 38 |
|
38 | 39 | return static function (RectorConfig $rectorConfig): void { |
39 | | - $rectorConfig->sets([SetList::DEAD_CODE, LevelSetList::UP_TO_PHP_74, PHPUnitSetList::PHPUNIT_SPECIFIC_METHOD, PHPUnitSetList::PHPUNIT_80]); |
| 40 | + $rectorConfig->sets([ |
| 41 | + SetList::DEAD_CODE, |
| 42 | + LevelSetList::UP_TO_PHP_74, |
| 43 | + PHPUnitSetList::PHPUNIT_CODE_QUALITY, |
| 44 | + PHPUnitSetList::PHPUNIT_100, |
| 45 | + ]); |
| 46 | + |
40 | 47 | $rectorConfig->parallel(); |
| 48 | + |
41 | 49 | // The paths to refactor (can also be supplied with CLI arguments) |
42 | 50 | $rectorConfig->paths([ |
43 | 51 | __DIR__ . '/app/', |
|
58 | 66 | $rectorConfig->phpstanConfig(__DIR__ . '/phpstan.neon.dist'); |
59 | 67 | } |
60 | 68 |
|
| 69 | + // Set the target version for refactoring |
| 70 | + $rectorConfig->phpVersion(PhpVersion::PHP_74); |
61 | 71 |
|
62 | 72 | // Auto-import fully qualified class names |
63 | 73 | $rectorConfig->importNames(); |
64 | 74 |
|
65 | 75 | // Are there files or rules you need to skip? |
66 | 76 | $rectorConfig->skip([ |
67 | | - __DIR__ . '/app/Config/Pager.php', |
68 | | - __DIR__ . '/app/Config/Validation.php', |
69 | 77 | __DIR__ . '/app/Views', |
70 | 78 |
|
71 | 79 | JsonThrowOnErrorRector::class, |
72 | 80 | StringifyStrNeedlesRector::class, |
| 81 | + YieldDataProviderRector::class, |
73 | 82 |
|
74 | 83 | // Note: requires php 8 |
75 | 84 | RemoveUnusedPromotedPropertyRector::class, |
76 | | - |
77 | | - // Ignore tests that might make calls without a result |
78 | | - RemoveEmptyMethodCallRector::class => [ |
79 | | - __DIR__ . '/tests', |
80 | | - ], |
81 | | - |
82 | | - // Ignore files that should not be namespaced |
83 | | - NormalizeNamespaceByPSR4ComposerAutoloadRector::class => [ |
84 | | - __DIR__ . '/app/Helpers', |
85 | | - ], |
| 85 | + AnnotationWithValueToAttributeRector::class, |
86 | 86 |
|
87 | 87 | // May load view files directly when detecting classes |
88 | 88 | StringClassNameToClassConstantRector::class, |
89 | | - |
90 | | - // May be uninitialized on purpose |
91 | | - AddDefaultValueForUndefinedVariableRector::class, |
92 | 89 | ]); |
| 90 | + |
| 91 | + // auto import fully qualified class names |
| 92 | + $rectorConfig->importNames(); |
| 93 | + |
93 | 94 | $rectorConfig->rule(SimplifyUselessVariableRector::class); |
94 | 95 | $rectorConfig->rule(RemoveAlwaysElseRector::class); |
95 | 96 | $rectorConfig->rule(CountArrayToEmptyArrayComparisonRector::class); |
96 | | - $rectorConfig->rule(ForToForeachRector::class); |
97 | 97 | $rectorConfig->rule(ChangeNestedForeachIfsToEarlyContinueRector::class); |
98 | 98 | $rectorConfig->rule(ChangeIfElseValueAssignToEarlyReturnRector::class); |
99 | 99 | $rectorConfig->rule(SimplifyStrposLowerRector::class); |
|
106 | 106 | $rectorConfig->rule(UnusedForeachValueToArrayKeysRector::class); |
107 | 107 | $rectorConfig->rule(ChangeArrayPushToArrayAssignRector::class); |
108 | 108 | $rectorConfig->rule(UnnecessaryTernaryExpressionRector::class); |
109 | | - $rectorConfig->rule(AddPregQuoteDelimiterRector::class); |
110 | 109 | $rectorConfig->rule(SimplifyRegexPatternRector::class); |
111 | 110 | $rectorConfig->rule(FuncGetArgsToVariadicParamRector::class); |
112 | 111 | $rectorConfig->rule(MakeInheritedMethodVisibilitySameAsParentRector::class); |
113 | 112 | $rectorConfig->rule(SimplifyEmptyArrayCheckRector::class); |
114 | | - $rectorConfig->rule(NormalizeNamespaceByPSR4ComposerAutoloadRector::class); |
115 | 113 | $rectorConfig |
116 | | - ->ruleWithConfiguration(TypedPropertyRector::class, [ |
117 | | - // Set to false if you use in libraries, or it does create breaking changes. |
118 | | - TypedPropertyRector::INLINE_PUBLIC => false, |
| 114 | + ->ruleWithConfiguration(TypedPropertyFromAssignsRector::class, [ |
| 115 | + /** |
| 116 | + * The INLINE_PUBLIC value is default to false to avoid BC break, if you use for libraries and want to preserve BC break, you don't need to configure it, as it included in LevelSetList::UP_TO_PHP_74 |
| 117 | + * Set to true for projects that allow BC break |
| 118 | + */ |
| 119 | + TypedPropertyFromAssignsRector::INLINE_PUBLIC => false, |
119 | 120 | ]); |
| 121 | + $rectorConfig->rule(StringClassNameToClassConstantRector::class); |
| 122 | + $rectorConfig->rule(PrivatizeFinalClassPropertyRector::class); |
| 123 | + $rectorConfig->rule(CompleteDynamicPropertiesRector::class); |
120 | 124 | }; |
0 commit comments