|
23 | 23 | use Guanguans\Notify\Foundation\Rectors\ToInternalExceptionRector; |
24 | 24 | use Guanguans\Notify\Foundation\Response; |
25 | 25 | use GuzzleHttp\RequestOptions; |
| 26 | +use Kcs\ClassFinder\Finder\ComposerFinder; |
26 | 27 | use PhpParser\Node\Expr\ClassConstFetch; |
27 | 28 | use PhpParser\Node\Identifier; |
28 | 29 | use PhpParser\Node\Name\FullyQualified; |
|
41 | 42 | use Rector\EarlyReturn\Rector\Return_\ReturnBinaryOrToEarlyReturnRector; |
42 | 43 | use Rector\Naming\Rector\ClassMethod\RenameParamToMatchTypeRector; |
43 | 44 | use Rector\Php73\Rector\String_\SensitiveHereNowDocRector; |
| 45 | +use Rector\Php80\Rector\Class_\AnnotationToAttributeRector; |
| 46 | +use Rector\Php80\ValueObject\AnnotationToAttribute; |
44 | 47 | use Rector\Php82\Rector\Param\AddSensitiveParameterAttributeRector; |
45 | 48 | use Rector\PHPUnit\Set\PHPUnitSetList; |
46 | 49 | use Rector\Removing\Rector\Class_\RemoveTraitUseRector; |
|
60 | 63 | return RectorConfig::configure() |
61 | 64 | ->withRootFiles() |
62 | 65 | ->withPaths([ |
| 66 | + __DIR__.'/benchmarks', |
63 | 67 | __DIR__.'/src', |
64 | 68 | __DIR__.'/tests', |
65 | 69 | __DIR__.'/composer-updater', |
|
120 | 124 | new ClassMethodReference(HasOptions::class, 'offsetGet'), |
121 | 125 | new ClassMethodReference(Response::class, 'offsetGet'), |
122 | 126 | ]) |
| 127 | + ->withConfiguredRule(AnnotationToAttributeRector::class, array_map( |
| 128 | + static fn (string $class) => new AnnotationToAttribute(class_basename($class), $class, [], true), |
| 129 | + array_keys(iterator_to_array( |
| 130 | + (new ComposerFinder) |
| 131 | + ->inNamespace('PhpBench\Attributes') |
| 132 | + ->filter(static fn (ReflectionClass $reflectionClass): bool => $reflectionClass->isInstantiable()) |
| 133 | + )) |
| 134 | + )) |
123 | 135 | ->withConfiguredRule(AddSensitiveParameterAttributeRector::class, [ |
124 | 136 | AddSensitiveParameterAttributeRector::SENSITIVE_PARAMETERS => [ |
125 | 137 | 'accessToken', |
|
134 | 146 | 'webHook', |
135 | 147 | ], |
136 | 148 | ]) |
137 | | - ->withConfiguredRule( |
138 | | - StringToClassConstantRector::class, |
139 | | - array_reduce( |
140 | | - [ |
141 | | - Guanguans\Notify\Foundation\Method::class, |
142 | | - RequestOptions::class, |
143 | | - ], |
144 | | - static fn (array $carry, string $class): array => array_merge( |
145 | | - $carry, |
146 | | - array_map( |
147 | | - static fn (string $string, string $constant): StringToClassConstant => new StringToClassConstant( |
148 | | - $string, |
149 | | - $class, |
150 | | - $constant, |
151 | | - ), |
152 | | - $constants = (new ReflectionClass($class))->getConstants(), |
153 | | - array_keys($constants), |
| 149 | + ->withConfiguredRule(RenameFunctionRector::class, [ |
| 150 | + 'test' => 'it', |
| 151 | + 'Pest\Faker\faker' => 'faker', |
| 152 | + 'Pest\Faker\fake' => 'fake', |
| 153 | + // 'faker' => 'fake', |
| 154 | + ] + array_reduce( |
| 155 | + [ |
| 156 | + 'error_silencer', |
| 157 | + 'value', |
| 158 | + 'base64_encode_file', |
| 159 | + 'tap', |
| 160 | + ], |
| 161 | + static function (array $carry, string $func): array { |
| 162 | + /** @see https://github.com/laravel/framework/blob/11.x/src/Illuminate/Support/functions.php */ |
| 163 | + $carry[$func] = "Guanguans\\Notify\\Foundation\\Support\\$func"; |
| 164 | + |
| 165 | + return $carry; |
| 166 | + }, |
| 167 | + [] |
| 168 | + )) |
| 169 | + ->withConfiguredRule(StringToClassConstantRector::class, array_reduce( |
| 170 | + [ |
| 171 | + Guanguans\Notify\Foundation\Method::class, |
| 172 | + RequestOptions::class, |
| 173 | + ], |
| 174 | + static fn (array $carry, string $class): array => array_merge( |
| 175 | + $carry, |
| 176 | + array_map( |
| 177 | + static fn (string $string, string $constant): StringToClassConstant => new StringToClassConstant( |
| 178 | + $string, |
| 179 | + $class, |
| 180 | + $constant, |
154 | 181 | ), |
| 182 | + $constants = (new ReflectionClass($class))->getConstants(), |
| 183 | + array_keys($constants), |
155 | 184 | ), |
156 | | - [], |
157 | 185 | ), |
158 | | - ) |
159 | | - ->withConfiguredRule( |
160 | | - RenameFunctionRector::class, |
161 | | - [ |
162 | | - 'test' => 'it', |
163 | | - ] + array_reduce( |
164 | | - [ |
165 | | - 'error_silencer', |
166 | | - 'value', |
167 | | - 'base64_encode_file', |
168 | | - 'tap', |
169 | | - ], |
170 | | - static function (array $carry, string $func): array { |
171 | | - /** @see https://github.com/laravel/framework/blob/11.x/src/Illuminate/Support/functions.php */ |
172 | | - $carry[$func] = "Guanguans\\Notify\\Foundation\\Support\\$func"; |
173 | | - |
174 | | - return $carry; |
175 | | - }, |
176 | | - [] |
177 | | - ) |
178 | | - ) |
| 186 | + [], |
| 187 | + )) |
179 | 188 | ->withConfiguredRule(ScalarValueToConstFetchRector::class, array_map( |
180 | 189 | static fn (int $value, string $constant): ScalarValueToConstFetch => new ScalarValueToConstFetch( |
181 | 190 | new LNumber($value), |
@@ -214,13 +223,15 @@ static function (array $carry, string $func): array { |
214 | 223 | ], |
215 | 224 | StaticClosureRector::class => $staticArrowFunctionPaths, |
216 | 225 | StringToClassConstantRector::class => [ |
| 226 | + __DIR__.'/benchmarks', |
217 | 227 | __DIR__.'/src/Foundation/Rfc', |
218 | 228 | __DIR__.'/src/*/Messages/*.php', |
219 | 229 | __DIR__.'/tests', |
220 | 230 | __DIR__.'/src/Foundation/Support/Utils.php', |
221 | 231 | __DIR__.'/src/Foundation/Response.php', |
222 | 232 | ], |
223 | 233 | SortAssociativeArrayByKeyRector::class => [ |
| 234 | + __DIR__.'/benchmarks', |
224 | 235 | __DIR__.'/src', |
225 | 236 | __DIR__.'/tests', |
226 | 237 | ], |
|
0 commit comments