-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathrector.php
More file actions
241 lines (224 loc) · 8.94 KB
/
rector.php
File metadata and controls
241 lines (224 loc) · 8.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
<?php
use Rector\Config\RectorConfig;
// CodeQuality
use Rector\CodeQuality\Rector\Assign\CombinedAssignRector;
use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector;
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\CodeQuality\Rector\ClassMethod\LocallyCalledStaticMethodToNonStaticRector;
use Rector\CodeQuality\Rector\Concat\JoinStringConcatRector;
use Rector\CodeQuality\Rector\Empty_\SimplifyEmptyCheckOnEmptyArrayRector;
use Rector\CodeQuality\Rector\Foreach_\UnusedForeachValueToArrayKeysRector;
use Rector\CodeQuality\Rector\FuncCall\ChangeArrayPushToArrayAssignRector;
use Rector\CodeQuality\Rector\FuncCall\CompactToVariablesRector;
use Rector\CodeQuality\Rector\FuncCall\SimplifyRegexPatternRector;
use Rector\CodeQuality\Rector\FuncCall\SingleInArrayToCompareRector;
use Rector\CodeQuality\Rector\If_\CombineIfRector;
use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector;
use Rector\CodeQuality\Rector\If_\ShortenElseIfRector;
use Rector\CodeQuality\Rector\Include_\AbsolutizeRequireAndIncludePathRector;
use Rector\CodeQuality\Rector\Isset_\IssetOnPropertyObjectToPropertyExistsRector;
use Rector\CodeQuality\Rector\Switch_\SingularSwitchToIfRector;
use Rector\CodeQuality\Rector\Ternary\SwitchNegatedTernaryRector;
// CodingStyle
use Rector\CodingStyle\Rector\Catch_\CatchExceptionNameMatchingTypeRector;
use Rector\CodingStyle\Rector\ClassLike\NewlineBetweenClassLikeStmtsRector;
use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector;
use Rector\CodingStyle\Rector\ClassMethod\NewlineBeforeNewAssignSetRector;
use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector;
use Rector\CodingStyle\Rector\Encapsed\WrapEncapsedVariableInCurlyBracesRector;
use Rector\CodingStyle\Rector\FuncCall\CallUserFuncArrayToVariadicRector;
use Rector\CodingStyle\Rector\FuncCall\StrictArraySearchRector;
use Rector\CodingStyle\Rector\If_\NullableCompareToNullRector;
use Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector;
use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
use Rector\CodingStyle\Rector\String_\SimplifyQuoteEscapeRector;
// DeadCode
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedConstructorParamRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodParameterRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessParamTagRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector;
use Rector\DeadCode\Rector\Foreach_\RemoveUnusedForeachKeyRector;
use Rector\DeadCode\Rector\FunctionLike\RemoveDeadReturnRector;
use Rector\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector;
use Rector\DeadCode\Rector\StaticCall\RemoveParentCallWithoutParentRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveVoidDocblockFromMagicMethodRector;
use Rector\DeadCode\Rector\Node\RemoveNonExistingVarAnnotationRector;
// EarlyReturn
use Rector\EarlyReturn\Rector\If_\ChangeOrIfContinueToMultiContinueRector;
use Rector\EarlyReturn\Rector\Return_\ReturnBinaryOrToEarlyReturnRector;
// Php53, Php54, Php70
use Rector\Php53\Rector\Ternary\TernaryToElvisRector;
use Rector\Php54\Rector\Array_\LongArrayToShortArrayRector;
use Rector\Php70\Rector\FuncCall\MultiDirnameRector;
// Strict
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
// TypeDeclarationDocblocks
use Rector\TypeDeclarationDocblocks\Rector\ClassMethod\AddReturnDocblockForDimFetchArrayFromAssignsRector;
use Rector\TypeDeclarationDocblocks\Rector\ClassMethod\AddParamArrayDocblockFromAssignsParamToParamReferenceRector;
use Rector\TypeDeclarationDocblocks\Rector\ClassMethod\AddParamArrayDocblockFromDimFetchAccessRector;
use Rector\TypeDeclarationDocblocks\Rector\ClassMethod\DocblockReturnArrayFromDirectArrayInstanceRector;
// PHP Unit
use Rector\PHPUnit\CodeQuality\Rector\StmtsAwareInterface\DeclareStrictTypesTestsRector;
use Rector\Privatization\Rector\Class_\FinalizeTestCaseClassRector;
use Rector\Privatization\Rector\Property\PrivatizeFinalClassPropertyRector;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\StringCastAssertStringContainsStringRector;
return RectorConfig::configure()
->withBootstrapFiles(
array(
__DIR__ . '/stubs.php',
)
)
->withAutoloadPaths(
array(
__DIR__ . '/tests/phpunit/base',
)
)
->withPaths(
array(
__DIR__ . '/classes',
__DIR__ . '/stripe',
__DIR__ . '/square',
__DIR__ . '/css',
__DIR__ . '/tests',
)
)
// Here we can define, what prepared sets of rules will be applied
->withPreparedSets(
// deadCode
true,
// codeQuality
true,
// codingStyle
true,
// typeDeclarations
false,
// typeDeclarationDocblocks
true,
// privatization
true,
// naming
false,
// instanceOf
true,
// earlyReturn
true,
// strictBooleans
false,
// carbon
false,
// rectorPreset
true,
// phpunitCodeQuality
true,
// doctrineCodeQuality
false,
// symfonyCodeQuality
false,
// symfonyConfigs
false
)
->withPhpSets(
// PHP 8.3
false,
// PHP 8.2
false,
// PHP 8.1
false,
// PHP 8.0
false,
// PHP 7.4
false,
// PHP 7.3
false,
// PHP 7.2
false,
// PHP 7.1
false,
// PHP 7.0
true
)
->withSkip(
array(
// CodeQuality
AbsolutizeRequireAndIncludePathRector::class,
ChangeArrayPushToArrayAssignRector::class,
CombinedAssignRector::class,
// This gets rid of comments as well, so the resulting code can be less easy to follow.
CombineIfRector::class,
// Prefer compact() for now since it uses less code.
CompactToVariablesRector::class,
CompleteDynamicPropertiesRector::class,
// Ignore this rule. Truthy and falsy checks are encouraged.
ExplicitBoolCompareRector::class,
InlineConstructorDefaultToPropertyRector::class,
IssetOnPropertyObjectToPropertyExistsRector::class,
// This changes \t to an actual tab character. We don't want this rule.
JoinStringConcatRector::class,
LocallyCalledStaticMethodToNonStaticRector::class,
ShortenElseIfRector::class,
// This change seems unsafe. It replace empty in cases where the variable might never be set.
SimplifyEmptyCheckOnEmptyArrayRector::class,
SimplifyRegexPatternRector::class,
SingleInArrayToCompareRector::class,
SingularSwitchToIfRector::class,
// This flips ! empty to empty in ternary statements, but ! empty statements are typically easier to read.
SwitchNegatedTernaryRector::class,
UnusedForeachValueToArrayKeysRector::class,
// CodingStyle
CallUserFuncArrayToVariadicRector::class,
CatchExceptionNameMatchingTypeRector::class,
EncapsedStringsToSprintfRector::class,
MakeInheritedMethodVisibilitySameAsParentRector::class,
// We do not need these many new lines.
NewlineAfterStatementRector::class,
NewlineBeforeNewAssignSetRector::class,
NewlineBetweenClassLikeStmtsRector::class,
NullableCompareToNullRector::class,
PostIncDecToPreIncDecRector::class,
SimplifyQuoteEscapeRector::class,
StrictArraySearchRector::class,
WrapEncapsedVariableInCurlyBracesRector::class,
// DeadCode
RemoveAlwaysTrueIfConditionRector::class,
// The FrmFieldType.php file has a few empty functions with only a return; line.
// We may want to remove that at some point, but I think it's there to prevent another
// Static analysis error.
RemoveDeadReturnRector::class,
RemoveParentCallWithoutParentRector::class,
RemoveUnusedConstructorParamRector::class,
RemoveUnusedForeachKeyRector::class,
RemoveUnusedPrivateMethodParameterRector::class,
RemoveUnusedPrivateMethodRector::class,
RemoveVoidDocblockFromMagicMethodRector::class,
RemoveNonExistingVarAnnotationRector::class,
// We never want to remove a valid param tag. Leave this exception.
RemoveUselessParamTagRector::class,
RemoveUselessReturnTagRector::class,
// EarlyReturn
// This breaks if statements up into multiple if statements. It adds too many lines.
ChangeOrIfContinueToMultiContinueRector::class,
// This breaks a return statement up into multiple return statements. It adds too many lines.
ReturnBinaryOrToEarlyReturnRector::class,
// Php53, Php54, Php70
// The WP standard still uses the long array syntax, so ignore this for now.
LongArrayToShortArrayRector::class,
MultiDirnameRector::class,
// The WP standard does not encourage the Elvis operator for readability.
TernaryToElvisRector::class,
// Strict
DisallowedEmptyRuleFixerRector::class,
// TypeDeclarationDocblocks
AddParamArrayDocblockFromAssignsParamToParamReferenceRector::class,
AddParamArrayDocblockFromDimFetchAccessRector::class,
DocblockReturnArrayFromDirectArrayInstanceRector::class,
AddReturnDocblockForDimFetchArrayFromAssignsRector::class,
// PHP Unit
DeclareStrictTypesTestsRector::class,
FinalizeTestCaseClassRector::class,
PrivatizeFinalClassPropertyRector::class,
StringClassNameToClassConstantRector::class,
StringCastAssertStringContainsStringRector::class,
)
);