Skip to content

Commit eda8d4b

Browse files
committed
refactor: apply rector
1 parent 564fdc6 commit eda8d4b

File tree

15 files changed

+62
-268
lines changed

15 files changed

+62
-268
lines changed

ide.json

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -166,29 +166,6 @@
166166
]
167167
}
168168
},
169-
{
170-
"complete": "staticStrings",
171-
"condition": [
172-
{
173-
"classFqn": [
174-
"Guanguans\\Notify\\Chanify\\Messages\\Message"
175-
],
176-
"newClassFqn": [
177-
"Guanguans\\Notify\\Chanify\\Messages\\Message"
178-
],
179-
"methodNames": [
180-
"make"
181-
],
182-
"parameters": [
183-
1
184-
],
185-
"place": "arrayKey"
186-
}
187-
],
188-
"options": {
189-
"strings": []
190-
}
191-
},
192169
{
193170
"complete": "staticStrings",
194171
"condition": [
@@ -222,29 +199,6 @@
222199
]
223200
}
224201
},
225-
{
226-
"complete": "staticStrings",
227-
"condition": [
228-
{
229-
"classFqn": [
230-
"Guanguans\\Notify\\DingTalk\\Messages\\AbstractMessage"
231-
],
232-
"newClassFqn": [
233-
"Guanguans\\Notify\\DingTalk\\Messages\\AbstractMessage"
234-
],
235-
"methodNames": [
236-
"make"
237-
],
238-
"parameters": [
239-
1
240-
],
241-
"place": "arrayKey"
242-
}
243-
],
244-
"options": {
245-
"strings": []
246-
}
247-
},
248202
{
249203
"complete": "staticStrings",
250204
"condition": [
@@ -541,29 +495,6 @@
541495
]
542496
}
543497
},
544-
{
545-
"complete": "staticStrings",
546-
"condition": [
547-
{
548-
"classFqn": [
549-
"Guanguans\\Notify\\Lark\\Messages\\AbstractMessage"
550-
],
551-
"newClassFqn": [
552-
"Guanguans\\Notify\\Lark\\Messages\\AbstractMessage"
553-
],
554-
"methodNames": [
555-
"make"
556-
],
557-
"parameters": [
558-
1
559-
],
560-
"place": "arrayKey"
561-
}
562-
],
563-
"options": {
564-
"strings": []
565-
}
566-
},
567498
{
568499
"complete": "staticStrings",
569500
"condition": [
@@ -1350,29 +1281,6 @@
13501281
]
13511282
}
13521283
},
1353-
{
1354-
"complete": "staticStrings",
1355-
"condition": [
1356-
{
1357-
"classFqn": [
1358-
"Guanguans\\Notify\\Telegram\\Messages\\AbstractMessage"
1359-
],
1360-
"newClassFqn": [
1361-
"Guanguans\\Notify\\Telegram\\Messages\\AbstractMessage"
1362-
],
1363-
"methodNames": [
1364-
"make"
1365-
],
1366-
"parameters": [
1367-
1
1368-
],
1369-
"place": "arrayKey"
1370-
}
1371-
],
1372-
"options": {
1373-
"strings": []
1374-
}
1375-
},
13761284
{
13771285
"complete": "staticStrings",
13781286
"condition": [
@@ -1958,29 +1866,6 @@
19581866
]
19591867
}
19601868
},
1961-
{
1962-
"complete": "staticStrings",
1963-
"condition": [
1964-
{
1965-
"classFqn": [
1966-
"Guanguans\\Notify\\WeWork\\Messages\\AbstractMessage"
1967-
],
1968-
"newClassFqn": [
1969-
"Guanguans\\Notify\\WeWork\\Messages\\AbstractMessage"
1970-
],
1971-
"methodNames": [
1972-
"make"
1973-
],
1974-
"parameters": [
1975-
1
1976-
],
1977-
"place": "arrayKey"
1978-
}
1979-
],
1980-
"options": {
1981-
"strings": []
1982-
}
1983-
},
19841869
{
19851870
"complete": "staticStrings",
19861871
"condition": [

rector.dist.php

Lines changed: 17 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,13 @@
1717
use Ergebnis\Rector\Rules\Arrays\SortAssociativeArrayByKeyRector;
1818
use Guanguans\Notify\Foundation\Concerns\AsJson;
1919
use Guanguans\Notify\Foundation\Concerns\AsPost;
20-
use Guanguans\Notify\Foundation\Concerns\HasOptions;
21-
use Guanguans\Notify\Foundation\Method;
2220
use Guanguans\Notify\Foundation\Rectors\AddSensitiveParameterAttributeRector;
2321
use Guanguans\Notify\Foundation\Rectors\HasHttpClientDocCommentRector;
2422
use Guanguans\Notify\Foundation\Rectors\MessageRector;
25-
use Guanguans\Notify\Foundation\Response;
2623
use Guanguans\RectorRules\Rector\File\AddNoinspectionDocblockToFileFirstStmtRector;
27-
use Guanguans\RectorRules\Rector\FunctionLike\RenameGarbageParamNameRector;
2824
use Guanguans\RectorRules\Rector\Name\RenameToConventionalCaseNameRector;
2925
use Guanguans\RectorRules\Set\SetList;
30-
use GuzzleHttp\RequestOptions;
31-
use PhpParser\Node\Expr\ClassConstFetch;
32-
use PhpParser\Node\Identifier;
33-
use PhpParser\Node\Name\FullyQualified;
34-
use PhpParser\Node\Scalar\Int_;
3526
use PhpParser\NodeVisitor\ParentConnectingVisitor;
36-
use Rector\CodeQuality\Rector\Class_\ConvertStaticToSelfRector;
3727
use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector;
3828
use Rector\CodeQuality\Rector\LogicalAnd\LogicalToBooleanRector;
3929
use Rector\CodingStyle\Rector\ArrowFunction\ArrowFunctionDelegatingCallToFirstClassCallableRector;
@@ -42,41 +32,26 @@
4232
use Rector\CodingStyle\Rector\Closure\StaticClosureRector;
4333
use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector;
4434
use Rector\CodingStyle\Rector\Encapsed\WrapEncapsedVariableInCurlyBracesRector;
35+
use Rector\CodingStyle\Rector\Enum_\EnumCaseToPascalCaseRector;
4536
use Rector\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector;
46-
use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
4737
use Rector\Config\RectorConfig;
48-
use Rector\DeadCode\Rector\ClassLike\RemoveAnnotationRector;
4938
use Rector\DeadCode\Rector\ClassMethod\RemoveParentDelegatingConstructorRector;
5039
use Rector\EarlyReturn\Rector\If_\ChangeOrIfContinueToMultiContinueRector;
5140
use Rector\EarlyReturn\Rector\Return_\ReturnBinaryOrToEarlyReturnRector;
5241
use Rector\Naming\Rector\Assign\RenameVariableToMatchMethodCallReturnTypeRector;
5342
use Rector\Naming\Rector\ClassMethod\RenameParamToMatchTypeRector;
5443
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
55-
use Rector\Php81\Rector\Array_\ArrayToFirstClassCallableRector;
5644
use Rector\Removing\Rector\Class_\RemoveTraitUseRector;
5745
use Rector\Renaming\Rector\FuncCall\RenameFunctionRector;
5846
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
59-
use Rector\Transform\Rector\ClassMethod\ReturnTypeWillChangeRector;
60-
use Rector\Transform\Rector\Scalar\ScalarValueToConstFetchRector;
6147
use Rector\Transform\Rector\String_\StringToClassConstantRector;
62-
use Rector\Transform\ValueObject\ClassMethodReference;
63-
use Rector\Transform\ValueObject\ScalarValueToConstFetch;
64-
use Rector\Transform\ValueObject\StringToClassConstant;
6548
use Rector\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector;
6649
use Rector\ValueObject\PhpVersion;
6750

6851
return RectorConfig::configure()
69-
->withPaths([
70-
__DIR__.'/benchmarks/',
71-
__DIR__.'/src/',
72-
__DIR__.'/tests/',
73-
__DIR__.'/composer-bump',
74-
])
52+
->withPaths([__DIR__.'/benchmarks/', __DIR__.'/src/', __DIR__.'/tests/', __DIR__.'/composer-bump'])
7553
->withRootFiles()
76-
->withSkip([
77-
'*/Fixtures/*',
78-
__DIR__.'/tests.php',
79-
])
54+
->withSkip(['*/Fixtures/*', __DIR__.'/tests.php'])
8055
->withCache(__DIR__.'/.build/rector/')
8156
// ->withoutParallel()
8257
->withParallel()
@@ -100,7 +75,10 @@
10075
naming: true,
10176
instanceOf: true,
10277
earlyReturn: true,
78+
// strictBooleans: true,
10379
// carbon: true,
80+
rectorPreset: true,
81+
phpunitCodeQuality: true,
10482
)
10583
->withSets([
10684
SetList::ALL,
@@ -111,6 +89,7 @@
11189
MessageRector::class,
11290

11391
ArraySpreadInsteadOfArrayMergeRector::class,
92+
EnumCaseToPascalCaseRector::class,
11493
JsonThrowOnErrorRector::class,
11594
SafeDeclareStrictTypesRector::class,
11695
SortAssociativeArrayByKeyRector::class,
@@ -126,86 +105,24 @@
126105
'PhpUndefinedClassInspection',
127106
'PhpUnhandledExceptionInspection',
128107
'PhpVoidFunctionResultUsedInspection',
129-
// 'SqlResolve',
130108
'StaticClosureCanBeUsedInspection',
131109
],
132110
])
133111
->registerDecoratingNodeVisitor(ParentConnectingVisitor::class)
134-
->withConfiguredRule(RenameToConventionalCaseNameRector::class, [
135-
'beforeEach',
136-
'MIT',
137-
'PDO',
138-
])
139-
->withConfiguredRule(RemoveAnnotationRector::class, [
140-
'codeCoverageIgnore',
141-
'inheritDoc',
142-
'phpstan-ignore',
143-
'phpstan-ignore-next-line',
144-
'psalm-suppress',
145-
])
146-
->withConfiguredRule(RemoveTraitUseRector::class, [
147-
AsJson::class,
148-
AsPost::class,
149-
])
150-
// ->withConfiguredRule(ReturnTypeWillChangeRector::class, [
151-
// new ClassMethodReference(ArrayAccess::class, 'offsetGet'),
152-
// new ClassMethodReference(HasOptions::class, 'offsetGet'),
153-
// new ClassMethodReference(Response::class, 'offsetGet'),
154-
// ])
155-
156-
->withConfiguredRule(RenameFunctionRector::class, array_reduce(
157-
[
158-
'base64_encode_file',
159-
'tap',
160-
'value',
161-
],
162-
static function (array $carry, string $func): array {
163-
/** @see https://github.com/laravel/framework/blob/11.x/src/Illuminate/Support/functions.php */
164-
$carry[$func] = "Guanguans\\Notify\\Foundation\\Support\\$func";
165-
166-
return $carry;
167-
},
168-
[]
169-
))
170-
->withConfiguredRule(StringToClassConstantRector::class, array_reduce(
171-
[
172-
// Method::class,
173-
RequestOptions::class,
174-
],
175-
static fn (array $carry, string $class): array => [...$carry, ...array_map(
176-
static fn (string $string, string $constant): StringToClassConstant => new StringToClassConstant(
177-
$string,
178-
$class,
179-
$constant,
180-
),
181-
$constants = (new ReflectionClass($class))->getConstants(),
182-
array_keys($constants),
183-
)],
184-
[],
185-
))
186-
->withConfiguredRule(ScalarValueToConstFetchRector::class, array_map(
187-
static fn (int $value, string $constant): ScalarValueToConstFetch => new ScalarValueToConstFetch(
188-
new Int_($value),
189-
new ClassConstFetch(new FullyQualified(Response::class), new Identifier($constant))
190-
),
191-
$constants = array_filter(
192-
(new ReflectionClass(Response::class))->getConstants(),
193-
\is_int(...),
194-
),
195-
array_keys($constants)
196-
))
112+
->withConfiguredRule(RenameToConventionalCaseNameRector::class, ['beforeEach', 'MIT', 'PDO'])
113+
->withConfiguredRule(RemoveTraitUseRector::class, [AsJson::class, AsPost::class])
114+
->withConfiguredRule(
115+
RenameFunctionRector::class,
116+
collect(['base64_encode_file', 'tap', 'value'])
117+
->mapWithKeys(static fn (string $func): array => [$func => "Guanguans\\Notify\\Foundation\\Support\\$func"])
118+
->all()
119+
)
197120
->withSkip([
198-
// ArrayToFirstClassCallableRector::class,
199-
// ArrowFunctionDelegatingCallToFirstClassCallableRector::class,
200-
RenameGarbageParamNameRector::class,
201-
ScalarValueToConstFetchRector::class,
202-
203121
ChangeOrIfContinueToMultiContinueRector::class,
204122
DisallowedEmptyRuleFixerRector::class,
205123
EncapsedStringsToSprintfRector::class,
206124
ExplicitBoolCompareRector::class,
207125
LogicalToBooleanRector::class,
208-
NewlineAfterStatementRector::class,
209126
NewlineBetweenClassLikeStmtsRector::class,
210127
ReturnBinaryOrToEarlyReturnRector::class,
211128
WrapEncapsedVariableInCurlyBracesRector::class,
@@ -214,13 +131,6 @@ static function (array $carry, string $func): array {
214131
ArrowFunctionDelegatingCallToFirstClassCallableRector::class => [
215132
__DIR__.'/tests/Foundation/MessageTest.php',
216133
],
217-
ConvertStaticToSelfRector::class => [
218-
__DIR__.'/src/Foundation/Support/Arr.php',
219-
__DIR__.'/src/Foundation/Support/Str.php',
220-
],
221-
RemoveAnnotationRector::class => [
222-
__DIR__.'/src/Foundation/Concerns/Dumpable.php',
223-
],
224134
RemoveParentDelegatingConstructorRector::class => [
225135
__DIR__.'/src/Zulip/Authenticator.php',
226136
],
@@ -229,7 +139,6 @@ static function (array $carry, string $func): array {
229139
],
230140
RenameParamToMatchTypeRector::class => [
231141
__DIR__.'/src/Foundation/Rectors/',
232-
__DIR__.'/src/Foundation/Authenticators/AggregateAuthenticator.php',
233142
__DIR__.'/src/Foundation/Exceptions/RequestException.php',
234143
],
235144
RenameVariableToMatchMethodCallReturnTypeRector::class => [
@@ -241,14 +150,13 @@ static function (array $carry, string $func): array {
241150
__DIR__.'/tests/',
242151
],
243152
StaticArrowFunctionRector::class => $staticClosureSkipPaths = [
244-
__DIR__.'/tests/',
153+
__DIR__.'/tests/*Test.php',
154+
__DIR__.'/tests/Pest.php',
245155
],
246156
StaticClosureRector::class => $staticClosureSkipPaths,
247157
StringToClassConstantRector::class => [
248158
__DIR__.'/benchmarks/',
249159
__DIR__.'/src/*/Messages/*.php',
250-
__DIR__.'/src/Foundation/Response.php',
251-
__DIR__.'/src/Foundation/Rfc/',
252160
__DIR__.'/src/Foundation/Support/Utils.php',
253161
__DIR__.'/tests/',
254162
__DIR__.'/composer-bump',

src/Discord/Messages/Message.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ protected function configureOptionsResolver(OptionsResolver $optionsResolver): v
9696
'fields',
9797
])
9898
->setNormalizer('color', static fn (
99-
OptionsResolver $optionsResolver,
99+
OptionsResolver $_,
100100
int|string $value
101101
): float|int => \is_int($value) ? $value : hexdec($value))
102102
->setAllowedTypes('footer', 'array')

src/Foundation/Concerns/Dumpable.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,11 @@
1717

1818
trait Dumpable
1919
{
20-
/**
21-
* @codeCoverageIgnore
22-
*/
2320
public function dd(mixed ...$args): void
2421
{
25-
$this->dump(...$args);
22+
$this->dump(...$args); // @codeCoverageIgnoreStart
2623

27-
exit(1);
24+
exit(1); // @codeCoverageIgnoreEnd
2825
}
2926

3027
/**

0 commit comments

Comments
 (0)