Skip to content

Commit 54e7c79

Browse files
committed
ci: apply rector
1 parent 666e9ee commit 54e7c79

File tree

7 files changed

+465
-132
lines changed

7 files changed

+465
-132
lines changed

benchmarks/SoarBench.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
final class SoarBench
3030
{
31-
private ?\Guanguans\SoarPHP\Soar $soar;
31+
private ?\Guanguans\SoarPHP\Soar $soar = null;
3232

3333
public function setUp(): void
3434
{

composer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,11 @@
182182
"psalm": "@php ./vendor/bin/psalm",
183183
"psalm-baseline": "@psalm --update-baseline",
184184
"rector": "@php ./vendor/bin/rector --ansi -v",
185+
"rector-custom-rule": "@rector custom-rule",
186+
"rector-detect-node": "@rector detect-node --loop",
185187
"rector-dry-run": "@rector --dry-run",
188+
"rector-list-rules": "@rector list-rules",
189+
"rector-setup-ci": "@rector setup-ci",
186190
"release": "@php ./vendor/bin/monorepo-builder release --ansi -v",
187191
"release-major": "@release major",
188192
"release-major-dry-run": "@release-major --dry-run",

rector-dist.php

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* Copyright (c) 2019-2025 guanguans<ityaozm@gmail.com>
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE file that was distributed with this source code.
10+
*
11+
* @see https://github.com/guanguans/soar-php
12+
*/
13+
14+
use Rector\Caching\ValueObject\Storage\FileCacheStorage;
15+
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
16+
use Rector\CodeQuality\Rector\Expression\InlineIfToExplicitIfRector;
17+
use Rector\CodeQuality\Rector\Identical\SimplifyBoolIdenticalTrueRector;
18+
use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector;
19+
use Rector\CodeQuality\Rector\LogicalAnd\LogicalToBooleanRector;
20+
use Rector\CodingStyle\Rector\Closure\StaticClosureRector;
21+
use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector;
22+
use Rector\CodingStyle\Rector\Encapsed\WrapEncapsedVariableInCurlyBracesRector;
23+
use Rector\Config\RectorConfig;
24+
use Rector\Configuration\Option;
25+
use Rector\DeadCode\Rector\Assign\RemoveUnusedVariableAssignRector;
26+
use Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector;
27+
use Rector\EarlyReturn\Rector\Return_\ReturnBinaryOrToEarlyReturnRector;
28+
use Rector\EarlyReturn\Rector\StmtsAwareInterface\ReturnEarlyIfVariableRector;
29+
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\RemoveExpectAnyFromMockRector;
30+
use Rector\PHPUnit\Set\PHPUnitSetList;
31+
use Rector\Set\ValueObject\DowngradeLevelSetList;
32+
use Rector\Set\ValueObject\LevelSetList;
33+
use Rector\Set\ValueObject\SetList;
34+
use Rector\Strict\Rector\BooleanNot\BooleanInBooleanNotRuleFixerRector;
35+
use Rector\TypeDeclaration\Rector\ClassMethod\StrictArrayParamDimFetchRector;
36+
use Rector\ValueObject\PhpVersion;
37+
38+
return static function (RectorConfig $rectorConfig): void {
39+
\define('MHASH_XXH3', 2 << 0);
40+
\define('MHASH_XXH32', 2 << 1);
41+
\define('MHASH_XXH64', 2 << 2);
42+
\define('MHASH_XXH128', 2 << 3);
43+
$rectorConfig->importNames(false, false);
44+
$rectorConfig->importShortClasses(false);
45+
// $rectorConfig->disableParallel();
46+
$rectorConfig->parallel(240);
47+
$rectorConfig->phpstanConfig(__DIR__.'/phpstan.neon');
48+
$rectorConfig->phpVersion(PhpVersion::PHP_73);
49+
// $rectorConfig->cacheClass(FileCacheStorage::class);
50+
// $rectorConfig->cacheDirectory(__DIR__.'/.build/rector');
51+
// $rectorConfig->containerCacheDirectory(__DIR__.'/.build/rector');
52+
// $rectorConfig->disableParallel();
53+
// $rectorConfig->fileExtensions(['php']);
54+
// $rectorConfig->indent(' ', 4);
55+
// $rectorConfig->memoryLimit('2G');
56+
// $rectorConfig->nestedChainMethodCallLimit(3);
57+
// $rectorConfig->noDiffs();
58+
// $rectorConfig->parameters()->set(Option::APPLY_AUTO_IMPORT_NAMES_ON_CHANGED_FILES_ONLY, true);
59+
// $rectorConfig->removeUnusedImports();
60+
61+
$rectorConfig->bootstrapFiles([
62+
// __DIR__.'/vendor/autoload.php',
63+
]);
64+
65+
$rectorConfig->autoloadPaths([
66+
// __DIR__.'/vendor/autoload.php',
67+
]);
68+
69+
$rectorConfig->paths([
70+
__DIR__.'/benchmarks',
71+
__DIR__.'/examples',
72+
__DIR__.'/src',
73+
__DIR__.'/tests',
74+
__DIR__.'/.*.php',
75+
__DIR__.'/*.php',
76+
__DIR__.'/composer-updater',
77+
]);
78+
79+
$rectorConfig->skip([
80+
// rules
81+
// RemoveEmptyClassMethodRector::class,
82+
// RemoveUnusedVariableAssignRector::class,
83+
// ReturnBinaryOrToEarlyReturnRector::class,
84+
// SimplifyBoolIdenticalTrueRector::class,
85+
// StaticClosureRector::class,
86+
87+
ExplicitBoolCompareRector::class,
88+
EncapsedStringsToSprintfRector::class,
89+
InlineIfToExplicitIfRector::class,
90+
LogicalToBooleanRector::class,
91+
WrapEncapsedVariableInCurlyBracesRector::class,
92+
93+
// BooleanInBooleanNotRuleFixerRector::class => [
94+
// __DIR__.'/src/Support/EscapeArg.php',
95+
// ],
96+
ReturnEarlyIfVariableRector::class => [
97+
__DIR__.'/src/Support/EscapeArg.php',
98+
],
99+
RemoveExpectAnyFromMockRector::class => [
100+
__DIR__.'/tests/Concerns/WithDumpableTest.php',
101+
],
102+
StaticClosureRector::class => [
103+
__DIR__.'/tests',
104+
],
105+
StrictArrayParamDimFetchRector::class => [
106+
__DIR__.'/src/Concerns/WithDumpable.php',
107+
],
108+
109+
// paths
110+
__DIR__.'/tests/Concerns/WithRunableTest.php',
111+
__DIR__.'/tests/AspectMock',
112+
'**/Fixture*',
113+
'**/Fixture/*',
114+
'**/Fixtures*',
115+
'**/Fixtures/*',
116+
'**/Stub*',
117+
'**/Stub/*',
118+
'**/Stubs*',
119+
'**/Stubs/*',
120+
'**/Source*',
121+
'**/Source/*',
122+
'**/Expected/*',
123+
'**/Expected*',
124+
'**/__snapshots__/*',
125+
'**/__snapshots__*',
126+
]);
127+
128+
$rectorConfig->sets([
129+
DowngradeLevelSetList::DOWN_TO_PHP_73,
130+
LevelSetList::UP_TO_PHP_73,
131+
// SetList::ACTION_INJECTION_TO_CONSTRUCTOR_INJECTION,
132+
SetList::CODE_QUALITY,
133+
SetList::CODING_STYLE,
134+
SetList::DEAD_CODE,
135+
// SetList::STRICT_BOOLEANS,
136+
// SetList::GMAGICK_TO_IMAGICK,
137+
// SetList::MYSQL_TO_MYSQLI,
138+
SetList::NAMING,
139+
// SetList::PRIVATIZATION,
140+
// SetList::PSR_4,
141+
SetList::TYPE_DECLARATION,
142+
SetList::EARLY_RETURN,
143+
SetList::INSTANCEOF,
144+
145+
PHPUnitSetList::PHPUNIT_90,
146+
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
147+
PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES,
148+
]);
149+
150+
$rectorConfig->rules([
151+
InlineConstructorDefaultToPropertyRector::class,
152+
StaticClosureRector::class,
153+
]);
154+
};

0 commit comments

Comments
 (0)