1515 * @see https://github.com/guanguans/soar-php
1616 */
1717
18- use Composer \Autoload \ClassLoader ;
1918use Ergebnis \Rector \Rules \Arrays \SortAssociativeArrayByKeyRector ;
19+ use Guanguans \MonorepoBuilderWorker \Support \Rectors \AddNoinspectionsDocCommentToDeclareRector ;
20+ use Guanguans \MonorepoBuilderWorker \Support \Rectors \NewExceptionToNewAnonymousExtendsExceptionImplementsRector ;
21+ use Guanguans \MonorepoBuilderWorker \Support \Rectors \RemoveNamespaceRector ;
22+ use Guanguans \SoarPHP \Contracts \Throwable ;
2023use Guanguans \SoarPHP \Support \Rectors \AddHasOptionsDocCommentRector ;
21- use Guanguans \SoarPHP \Support \Rectors \TransformToInternalExceptionRector ;
2224use Rector \CodeQuality \Rector \If_ \ExplicitBoolCompareRector ;
2325use Rector \CodeQuality \Rector \LogicalAnd \LogicalToBooleanRector ;
2426use Rector \CodingStyle \Rector \ArrowFunction \StaticArrowFunctionRector ;
2527use Rector \CodingStyle \Rector \Closure \StaticClosureRector ;
2628use Rector \CodingStyle \Rector \Encapsed \EncapsedStringsToSprintfRector ;
2729use Rector \CodingStyle \Rector \Encapsed \WrapEncapsedVariableInCurlyBracesRector ;
2830use Rector \CodingStyle \Rector \FuncCall \ArraySpreadInsteadOfArrayMergeRector ;
31+ use Rector \CodingStyle \Rector \FunctionLike \FunctionLikeToFirstClassCallableRector ;
2932use Rector \CodingStyle \Rector \Stmt \NewlineAfterStatementRector ;
3033use Rector \Config \RectorConfig ;
3134use Rector \DeadCode \Rector \ClassLike \RemoveAnnotationRector ;
32- use Rector \DowngradePhp74 \Rector \Array_ \DowngradeArraySpreadRector ;
3335use Rector \EarlyReturn \Rector \If_ \ChangeOrIfContinueToMultiContinueRector ;
3436use Rector \EarlyReturn \Rector \Return_ \ReturnBinaryOrToEarlyReturnRector ;
3537use Rector \Php73 \Rector \FuncCall \JsonThrowOnErrorRector ;
3840use Rector \PHPUnit \Set \PHPUnitSetList ;
3941use Rector \Renaming \Rector \FuncCall \RenameFunctionRector ;
4042use Rector \ValueObject \PhpVersion ;
41-
42- function classes (): array
43- {
44- static $ classes ;
45-
46- foreach (spl_autoload_functions () as $ loader ) {
47- if (\is_array ($ loader ) && $ loader [0 ] instanceof ClassLoader) {
48- return $ classes ??= array_keys ($ loader [0 ]->getClassMap ());
49- }
50- }
51-
52- return $ classes ??= [];
53- }
43+ use function Guanguans \SoarPHP \Support \classes ;
5444
5545return RectorConfig::configure ()
5646 ->withPaths ([
57- __DIR__ .'/benchmarks ' ,
58- __DIR__ .'/examples ' ,
59- __DIR__ .'/src ' ,
60- __DIR__ .'/tests ' ,
61- ...glob (__DIR__ .'/{*,.*}.php ' , \GLOB_BRACE ),
47+ __DIR__ .'/benchmarks/ ' ,
48+ __DIR__ .'/examples/ ' ,
49+ __DIR__ .'/src/ ' ,
50+ __DIR__ .'/tests/ ' ,
6251 __DIR__ .'/composer-updater ' ,
6352 ])
6453 ->withRootFiles ()
65- // ->withSkipPath(__DIR__.'/tests.php')
54+ ->withAutoloadPaths ([
55+ // (new ReflectionClass(Throwable::class))->getFileName(),
56+ ])
57+ ->withBootstrapFiles ([
58+ // __DIR__.'/vendor/symplify/monorepo-builder/vendor/autoload.php',
59+ // __DIR__.'/vendor/symplify/monorepo-builder/vendor/scoper-autoload.php',
60+ ])
6661 ->withSkip ([
6762 '**/__snapshots__/* ' ,
6863 '**/Fixtures/* ' ,
64+ __DIR__ .'/_ide_helper.php ' ,
65+ __DIR__ .'/tests.php ' ,
6966 // __FILE__,
7067 ])
7168 ->withCache (__DIR__ .'/.build/rector/ ' )
69+ // ->withoutParallel()
7270 ->withParallel ()
73- ->withoutParallel ()
74- // ->withImportNames(importNames: false)
7571 ->withImportNames (importDocBlockNames: false , importShortClasses: false )
72+ // ->withImportNames(importNames: false)
73+ // ->withEditorUrl()
7674 ->withFluentCallNewLine ()
75+ ->withTreatClassesAsFinal ()
7776 ->withAttributesSets (phpunit: true , all: true )
78- ->withComposerBased (phpunit: true )
79- ->withPhpVersion (PhpVersion::PHP_80 )
80- ->withDowngradeSets (php80 : true )
81- ->withPhpSets (php80 : true )
77+ ->withComposerBased (phpunit: true /* , laravel: true */ )
78+ ->withPhpVersion (PhpVersion::PHP_81 )
79+ ->withDowngradeSets (php81 : true )
80+ ->withPhpSets (php81 : true )
8281 ->withPreparedSets (
8382 deadCode: true ,
8483 codeQuality: true ,
8584 codingStyle: true ,
8685 typeDeclarations: true ,
86+ typeDeclarationDocblocks: true ,
8787 privatization: true ,
8888 naming: true ,
8989 instanceOf: true ,
9090 earlyReturn: true ,
91- carbon: true ,
92- rectorPreset: true ,
93- phpunitCodeQuality: true ,
91+ // carbon: true,
9492 )
9593 ->withSets ([
96- PHPUnitSetList::PHPUNIT_90 ,
94+ PHPUnitSetList::PHPUNIT_100 ,
9795 ])
9896 ->withRules ([
9997 ArraySpreadInsteadOfArrayMergeRector::class,
10098 JsonThrowOnErrorRector::class,
101- SortAssociativeArrayByKeyRector::class,
10299 StaticArrowFunctionRector::class,
103100 StaticClosureRector::class,
101+ SortAssociativeArrayByKeyRector::class,
104102 AddHasOptionsDocCommentRector::class,
105- TransformToInternalExceptionRector::class,
103+ ])
104+ ->withConfiguredRule (AddNoinspectionsDocCommentToDeclareRector::class, [
105+ 'AnonymousFunctionStaticInspection ' ,
106+ 'NullPointerExceptionInspection ' ,
107+ 'PhpPossiblePolymorphicInvocationInspection ' ,
108+ 'PhpUndefinedClassInspection ' ,
109+ 'PhpUnhandledExceptionInspection ' ,
110+ 'PhpVoidFunctionResultUsedInspection ' ,
111+ 'StaticClosureCanBeUsedInspection ' ,
112+ ])
113+ ->withConfiguredRule (NewExceptionToNewAnonymousExtendsExceptionImplementsRector::class, [
114+ Throwable::class,
115+ ])
116+ ->withConfiguredRule (RemoveNamespaceRector::class, [
117+ 'Guanguans\SoarPHPTests ' ,
106118 ])
107119 ->withConfiguredRule (RemoveAnnotationRector::class, [
108120 'codeCoverageIgnore ' ,
121+ 'inheritDoc ' ,
109122 'phpstan-ignore ' ,
110123 'phpstan-ignore-next-line ' ,
111124 'psalm-suppress ' ,
@@ -119,6 +132,7 @@ function classes(): array
119132 'test ' => 'it ' ,
120133 ] + array_reduce (
121134 [
135+ 'classes ' ,
122136 'escape_argument ' ,
123137 'str_snake ' ,
124138 ],
@@ -133,23 +147,18 @@ static function (array $carry, string $func): array {
133147 )
134148 ->withConfiguredRule (
135149 AnnotationToAttributeRector::class,
136- array_map (
137- static fn (string $ class ): AnnotationToAttribute => new AnnotationToAttribute (
138- (new ReflectionClass ($ class ))->getShortName (),
139- $ class ,
150+ classes (static fn (string $ class ): bool => str_starts_with ($ class , 'PhpBench\Attributes ' ))
151+ ->filter (static fn (ReflectionClass $ reflectionClass ): bool => $ reflectionClass ->isInstantiable ())
152+ ->map (static fn (ReflectionClass $ reflectionClass ): AnnotationToAttribute => new AnnotationToAttribute (
153+ $ reflectionClass ->getShortName (),
154+ $ reflectionClass ->getName (),
140155 [],
141156 true
142- ),
143- array_filter (
144- classes (),
145- static fn (string $ class ): bool => str_starts_with ($ class , 'PhpBench\Attributes ' )
146- && (new ReflectionClass ($ class ))->isInstantiable ()
147- )
148- )
157+ ))
158+ ->all (),
149159 )
150160 ->withSkip ([
151161 ChangeOrIfContinueToMultiContinueRector::class,
152- DowngradeArraySpreadRector::class,
153162 EncapsedStringsToSprintfRector::class,
154163 ExplicitBoolCompareRector::class,
155164 LogicalToBooleanRector::class,
@@ -158,14 +167,48 @@ classes(),
158167 WrapEncapsedVariableInCurlyBracesRector::class,
159168 ])
160169 ->withSkip ([
170+ FunctionLikeToFirstClassCallableRector::class => [
171+ __DIR__ .'/src/Support/helpers.php ' ,
172+ __DIR__ .'/tests/Concerns/HasOptionsTest.php ' ,
173+ ],
161174 StaticArrowFunctionRector::class => $ staticClosureSkipPaths = [
162- __DIR__ .'/tests ' ,
175+ __DIR__ .'/tests/ ' ,
163176 ],
164177 StaticClosureRector::class => $ staticClosureSkipPaths ,
165178 SortAssociativeArrayByKeyRector::class => [
166- __DIR__ .'/benchmarks ' ,
167- __DIR__ .'/examples ' ,
168- __DIR__ .'/src ' ,
169- __DIR__ .'/tests ' ,
179+ __DIR__ .'/benchmarks/ ' ,
180+ __DIR__ .'/examples/ ' ,
181+ __DIR__ .'/src/ ' ,
182+ __DIR__ .'/tests/ ' ,
183+ ],
184+ AddNoinspectionsDocCommentToDeclareRector::class => [
185+ __DIR__ .'/benchmarks/ ' ,
186+ __DIR__ .'/examples/ ' ,
187+ __DIR__ .'/src/ ' ,
188+ // __DIR__.'/tests/',
189+ ...$ rootFiles = array_filter (
190+ glob (__DIR__ .'/{*,.*}.php ' , \GLOB_BRACE ),
191+ static fn (string $ filename ): bool => !\in_array (
192+ $ filename ,
193+ [
194+ __DIR__ .'/_ide_helper.php ' ,
195+ __DIR__ .'/tests.php ' ,
196+ ],
197+ true
198+ )
199+ ),
200+ __DIR__ .'/composer-updater ' ,
201+ ],
202+ NewExceptionToNewAnonymousExtendsExceptionImplementsRector::class => [
203+ __DIR__ .'/src/Support/Rectors/ ' ,
204+ ],
205+ RemoveNamespaceRector::class => [
206+ __DIR__ .'/benchmarks/ ' ,
207+ __DIR__ .'/examples/ ' ,
208+ __DIR__ .'/src/ ' ,
209+ // __DIR__.'/tests/',
210+ ...$ rootFiles ,
211+ __DIR__ .'/composer-updater ' ,
212+ __DIR__ .'/tests/TestCase.php ' ,
170213 ],
171214 ]);
0 commit comments