Skip to content

Commit 5f5a2e0

Browse files
committed
refactor: apply rector
1 parent 206abd9 commit 5f5a2e0

19 files changed

+110
-1039
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
/phpbench.json.dist export-ignore
5858
/phpstan.neon.dist export-ignore
5959
/phpunit.xml.dist export-ignore
60+
/rector-*.php export-ignore
6061
/rector.dist.php export-ignore
6162
/rule-doc-generator export-ignore
6263
/testbench.yaml export-ignore

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,13 @@
9191
"shipmonk/phpstan-rules": "^4.3",
9292
"sidz/phpstan-rules": "^0.5",
9393
"spatie/invade": "^2.1",
94-
"spatie/pest-plugin-snapshots": "^2.3",
9594
"spaze/phpstan-disallowed-calls": "^4.9",
9695
"staabm/annotate-pull-request-from-checkstyle": "^1.8",
9796
"staabm/phpstan-todo-by": "^0.3",
9897
"staabm/side-effects-detector": "^1.0",
9998
"symfony/thanks": "^1.4",
10099
"symfony/var-dumper": "^7.4 || ^8.0",
100+
"symfony/yaml": "^7.4 || ^8.0",
101101
"symplify/coding-standard": "^13.0",
102102
"symplify/easy-coding-standard": "^13.0",
103103
"symplify/phpstan-rules": "^14.9",
@@ -278,7 +278,7 @@
278278
"gitleaks:generate-baseline": "gitleaks git --report-path=gitleaks-baseline.json -v",
279279
"grumphp": "@php vendor/bin/grumphp run --ansi -vv",
280280
"jack": "@php vendor/bin/jack",
281-
"jack:breakpoint": "@jack breakpoint --limit=8",
281+
"jack:breakpoint": "@jack breakpoint --limit=9",
282282
"jack:breakpoint-dev": "@jack:breakpoint --dev",
283283
"jack:open-versions": "@jack open-versions --limit=99",
284284
"jack:open-versions-dev": "@jack:open-versions --dev",

phpstan.neon.dist

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ includes:
1616
# - vendor/shipmonk/dead-code-detector/rules.neon
1717
# - vendor/staabm/phpstan-todo-by/extension.neon
1818

19-
- vendor/symplify/phpstan-rules/config/code-complexity-rules.neon
19+
# - vendor/symplify/phpstan-rules/config/code-complexity-rules.neon
2020
# - vendor/symplify/phpstan-rules/config/configurable-rules.neon
21-
- vendor/symplify/phpstan-rules/config/naming-rules.neon
22-
- vendor/symplify/phpstan-rules/config/static-rules.neon
23-
# - vendor/symplify/phpstan-rules/config/symplify-rules.neon
21+
# - vendor/symplify/phpstan-rules/config/naming-rules.neon
22+
# - vendor/symplify/phpstan-rules/config/static-rules.neon
23+
- vendor/symplify/phpstan-rules/config/symplify-rules.neon
2424

2525
# - vendor/symplify/phpstan-rules/config/doctrine-rules.neon
2626
- vendor/symplify/phpstan-rules/config/phpunit-rules.neon
@@ -38,15 +38,18 @@ services:
3838
pretty: true
3939
# errorFormatter.checkstyle:
4040
# class: NickSdot\PhpStanPhpStormErrorIdentifiers\CheckstyleErrorFormatterPhpStorm
41-
# errorFormatter.llm:
42-
# class: NickSdot\PhpStanPhpStormErrorIdentifiers\LlmErrorFormatter
41+
errorFormatter.llm:
42+
class: NickSdot\PhpStanPhpStormErrorIdentifiers\LlmErrorFormatter
4343

4444
parameters:
4545
paths:
4646
- src/
47+
scanDirectories:
48+
# - vendor/rector/rector/vendor/symplify/rule-doc-generator-contracts/
4749
scanFiles:
4850
- vendor/composer/InstalledVersions.php
4951
excludePaths:
52+
- src/Support/ComposerScripts.php
5053
- tests/Fixtures/
5154
tmpDir: .build/phpstan/
5255
phpVersion: 80200
@@ -63,6 +66,12 @@ parameters:
6366
allRules: true
6467
booleansInConditions: false
6568
disallowedShortTernary: false
69+
ergebnis:
70+
guanguans:
71+
# exceptionMustImplementNativeThrowable:
72+
# nativeThrowable: Guanguans\MonorepoBuilderWorker\Contract\ThrowableContract
73+
# sidzIgnoreNumericStrings: true
74+
sidzIgnoreMagicNumbers: [0.9, 1, 2, 3, 5, 100, 600, 512, 1024, 1000, 0o755]
6675
cognitive_complexity:
6776
class: 42
6877
function: 8
@@ -83,6 +92,13 @@ parameters:
8392
no_mixed: false
8493
no_mixed_property: true
8594
no_mixed_caller: false
95+
unused_public:
96+
constants: true
97+
properties: true
98+
methods: true
99+
local_methods: true
100+
template_paths:
101+
# - resources/views/
86102
disallowedFunctionCalls:
87103
-
88104
function: 'env()'
@@ -91,23 +107,66 @@ parameters:
91107
function: 'env_explode()'
92108
message: 'use config() instead'
93109
ignoreErrors:
110+
# - identifier: argument.templateType
111+
# - identifier: argument.type
94112
# - identifier: arrayFilter.strict
95113
# - identifier: assign.propertyType
96114
# - identifier: binaryOp.invalid
97115
# - identifier: cast.double
98116
# - identifier: cast.int
99117
# - identifier: cast.string
118+
# - identifier: class.extendsFinalByPhpDoc
119+
# - identifier: disallowed.function
100120
# - identifier: empty.notAllowed
101121
# - identifier: encapsedStringPart.nonString
122+
# - identifier: ergebnis.final
123+
# - identifier: ergebnis.finalInAbstractClass
124+
# - identifier: ergebnis.noAssignByReference
125+
# - identifier: ergebnis.noConstructorParameterWithDefaultValue
126+
# - identifier: ergebnis.noExtends
127+
# - identifier: ergebnis.noIsset
128+
# - identifier: ergebnis.noNamedArgument
129+
# - identifier: ergebnis.noNullableReturnTypeDeclaration
130+
# - identifier: ergebnis.noParameterPassedByReference
131+
# - identifier: ergebnis.noParameterWithNullableTypeDeclaration
132+
# - identifier: ergebnis.noParameterWithNullDefaultValue
102133
# - identifier: foreach.valueOverwrite
134+
# - identifier: guanguans.forbiddenSideEffects
135+
# - identifier: logicalAnd.resultUnused
103136
# - identifier: logicalOr.resultUnused
137+
# - identifier: method.childParameterType
138+
# - identifier: method.dynamicName
139+
# - identifier: missingType.generics
140+
# - identifier: missingType.iterableValue
104141
# - identifier: new.static
105142
# - identifier: offsetAccess.nonOffsetAccessible
143+
# - identifier: offsetAccess.notFound
106144
# - identifier: paramOut.type
145+
# - identifier: phpstanApi.class
146+
# - identifier: return.type
107147
# - identifier: return.void
148+
# - identifier: shipmonk.binaryOperationWithNull
149+
# - identifier: shipmonk.checkedExceptionInCallable
150+
# - identifier: shipmonk.forbiddenCast
151+
# - identifier: shipmonk.iteratorToArrayWithoutPreserveKeys
152+
# - identifier: shipmonk.nonNormalizedType
153+
# - identifier: shipmonk.variableTypeOverwritten
154+
# - identifier: symplify.explicitInterfaceSuffixName
155+
# - identifier: symplify.explicitTraitSuffixName
156+
# - identifier: symplify.forbiddenArrayMethodCall
157+
# - identifier: symplify.forbiddenExtendOfNonAbstractClass
158+
# - identifier: symplify.forbiddenFuncCall
159+
# - identifier: symplify.forbiddenNode
160+
# - identifier: symplify.forbiddenStaticClassConstFetch
161+
# - identifier: symplify.noArrayMapWithArrayCallable
162+
# - identifier: symplify.noDynamicName
163+
# - identifier: symplify.noGlobalConst
108164
# - identifier: symplify.noReference
165+
# - identifier: symplify.noReturnSetterMethod
166+
# - identifier: symplify.requireExceptionNamespace
109167
# - identifier: trait.unused
110168
# - identifier: typePerfect.noMixedMethodCaller
169+
# - message: '#^Unused Guanguans\\Notify\\Rector\\.*\\.*\:\:__construct$#'
111170

112171
- identifier: argument.templateType
113172
- identifier: argument.type

rector.dist.php

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
use Ergebnis\Rector\Rules\Arrays\SortAssociativeArrayByKeyRector;
1919
use Ergebnis\Rector\Rules\Faker\GeneratorPropertyFetchToMethodCallRector;
20+
use Ergebnis\Rector\Rules\Files\ReferenceNamespacedSymbolsRelativeToNamespacePrefixRector;
2021
use Guanguans\RectorRules\Rector\File\AddNoinspectionDocblockToFileFirstStmtRector;
2122
use Guanguans\RectorRules\Rector\Name\RenameToConventionalCaseNameRector;
2223
use Guanguans\RectorRules\Set\SetList;
@@ -32,14 +33,17 @@
3233
use Rector\CodingStyle\Rector\Encapsed\WrapEncapsedVariableInCurlyBracesRector;
3334
use Rector\CodingStyle\Rector\Enum_\EnumCaseToPascalCaseRector;
3435
use Rector\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector;
35-
use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
3636
use Rector\Config\RectorConfig;
37-
use Rector\DeadCode\Rector\ClassLike\RemoveAnnotationRector;
3837
use Rector\EarlyReturn\Rector\If_\ChangeOrIfContinueToMultiContinueRector;
3938
use Rector\EarlyReturn\Rector\Return_\ReturnBinaryOrToEarlyReturnRector;
4039
use Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector;
40+
use Rector\Php82\Rector\Param\AddSensitiveParameterAttributeRector;
41+
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
42+
use Rector\Transform\Rector\Scalar\ScalarValueToConstFetchRector;
4143
use Rector\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector;
4244
use Rector\ValueObject\PhpVersion;
45+
use RectorPest\Set\PestLevelSetList;
46+
use RectorPest\Set\PestSetList;
4347

4448
return RectorConfig::configure()
4549
->withPaths([
@@ -50,11 +54,7 @@
5054
__DIR__.'/composer-bump',
5155
])
5256
->withRootFiles()
53-
->withSkip([
54-
'**/Fixtures/*',
55-
__DIR__.'/_ide_helper.php',
56-
__DIR__.'/tests.php',
57-
])
57+
->withSkip(['**/Fixtures/*', __DIR__.'/tests.php'])
5858
->withCache(__DIR__.'/.build/rector/')
5959
// ->withoutParallel()
6060
->withParallel()
@@ -83,7 +83,11 @@
8383
rectorPreset: true,
8484
phpunitCodeQuality: true,
8585
)
86-
->withSets([SetList::ALL])
86+
->withSets([
87+
SetList::ALL,
88+
PestLevelSetList::UP_TO_PEST_30,
89+
PestSetList::PEST_CODE_QUALITY,
90+
])
8791
->withRules([
8892
AddDocCommentForHasOptionsRector::class,
8993
ArraySpreadInsteadOfArrayMergeRector::class,
@@ -108,23 +112,21 @@
108112
],
109113
])
110114
->registerDecoratingNodeVisitor(ParentConnectingVisitor::class)
111-
->withConfiguredRule(RenameToConventionalCaseNameRector::class, [
112-
'assertMatches*Snapshot',
113-
'MIT',
114-
])
115-
->withConfiguredRule(RemoveAnnotationRector::class, [
116-
'codeCoverageIgnore',
117-
'inheritDoc',
118-
'phpstan-ignore',
119-
'phpstan-ignore-next-line',
120-
'psalm-suppress',
115+
->withConfiguredRule(RenameToConventionalCaseNameRector::class, ['MIT'])
116+
->withConfiguredRule(ReferenceNamespacedSymbolsRelativeToNamespacePrefixRector::class, [
117+
'namespacePrefixes' => [
118+
// 'Guanguans\\SoarPHP',
119+
],
121120
])
122121
->withSkip([
122+
AddSensitiveParameterAttributeRector::class,
123+
ScalarValueToConstFetchRector::class,
124+
123125
ChangeOrIfContinueToMultiContinueRector::class,
126+
DisallowedEmptyRuleFixerRector::class,
124127
EncapsedStringsToSprintfRector::class,
125128
ExplicitBoolCompareRector::class,
126129
LogicalToBooleanRector::class,
127-
NewlineAfterStatementRector::class,
128130
NewlineBetweenClassLikeStmtsRector::class,
129131
ReturnBinaryOrToEarlyReturnRector::class,
130132
WrapEncapsedVariableInCurlyBracesRector::class,
@@ -140,7 +142,8 @@
140142
__DIR__.'/tests/',
141143
],
142144
StaticArrowFunctionRector::class => $staticClosureSkipPaths = [
143-
__DIR__.'/tests/',
145+
__DIR__.'/tests/*Test.php',
146+
__DIR__.'/tests/Pest.php',
144147
],
145148
StaticClosureRector::class => $staticClosureSkipPaths,
146149
]);

tests/__snapshots__/ConcreteScoresTest__it_can_get_array_scores__2.txt renamed to tests/.pest/snapshots/Concerns/ConcreteScoresTest/it_can_get_array_scores.snap

File renamed without changes.

tests/__snapshots__/ConcreteScoresTest__it_can_get_html_scores__1.txt renamed to tests/.pest/snapshots/Concerns/ConcreteScoresTest/it_can_get_html_scores.snap

File renamed without changes.

tests/__snapshots__/ConcreteScoresTest__it_can_get_json_scores__2.txt renamed to tests/.pest/snapshots/Concerns/ConcreteScoresTest/it_can_get_json_scores.snap

File renamed without changes.

tests/__snapshots__/ConcreteScoresTest__it_can_get_markdown_scores__1.txt renamed to tests/.pest/snapshots/Concerns/ConcreteScoresTest/it_can_get_markdown_scores.snap

File renamed without changes.

tests/Concerns/ConcreteScoresTest.php

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
use Guanguans\SoarPHP\Soar;
2525
use Guanguans\SoarPHP\Support\OsHelper;
2626
use Pest\Expectation;
27-
use function Spatie\Snapshots\assertMatchesJsonSnapshot;
28-
use function Spatie\Snapshots\assertMatchesTextSnapshot;
2927

3028
it('can get array scores', function (): void {
3129
$queries = [
@@ -78,25 +76,24 @@
7876
->when(OsHelper::isWindows(), function (Expectation $expectation): void {
7977
dump($expectation->value);
8078
})
81-
->when(!OsHelper::isWindows(), function (Expectation $expectation): void {
82-
$scores = json_encode(
79+
->unless(
80+
OsHelper::isWindows(),
81+
fn (Expectation $expectation): Expectation => expect(json_encode(
8382
$expectation->value,
8483
\JSON_PRETTY_PRINT | \JSON_UNESCAPED_UNICODE | \JSON_UNESCAPED_SLASHES | \JSON_THROW_ON_ERROR,
85-
);
86-
assertMatchesJsonSnapshot($scores);
87-
assertMatchesTextSnapshot($scores);
88-
});
84+
))->toMatchSnapshot()
85+
);
8986
})->group(__DIR__, __FILE__);
9087

9188
it('can get json scores', function (): void {
9289
expect(Soar::make())
9390
->jsonScores('select * from foo')
9491
->toBeJson()
9592
->toBeTruthy()
96-
->when(!OsHelper::isWindows(), function (Expectation $expectation): void {
97-
assertMatchesJsonSnapshot($expectation->value);
98-
assertMatchesTextSnapshot($expectation->value);
99-
});
93+
->unless(
94+
OsHelper::isWindows(),
95+
fn (Expectation $expectation): Expectation => $expectation->toMatchSnapshot()
96+
);
10097
})->group(__DIR__, __FILE__);
10198

10299
it('can get html scores', function (): void {
@@ -105,9 +102,10 @@
105102
->toBeString()
106103
->toBeTruthy()
107104
->toContain('foo', '<h1>', '<p>', '<pre>', '<h2>', '<ul>', '<li>')
108-
->when(!OsHelper::isWindows(), function (Expectation $expectation): void {
109-
assertMatchesTextSnapshot($expectation->value);
110-
});
105+
->unless(
106+
OsHelper::isWindows(),
107+
fn (Expectation $expectation): Expectation => $expectation->toMatchSnapshot()
108+
);
111109
})->group(__DIR__, __FILE__);
112110

113111
it('can get markdown scores', function (): void {
@@ -116,7 +114,8 @@
116114
->toBeString()
117115
->toBeTruthy()
118116
->toContain('foo', '#', '```sql', '##', '*')
119-
->when(!OsHelper::isWindows(), function (Expectation $expectation): void {
120-
assertMatchesTextSnapshot($expectation->value);
121-
});
117+
->unless(
118+
OsHelper::isWindows(),
119+
fn (Expectation $expectation): Expectation => $expectation->toMatchSnapshot()
120+
);
122121
});

tests/Pest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
use Guanguans\SoarPHPTests\TestCase;
2727
use Pest\Expectation;
2828

29-
uses(TestCase::class)
29+
pest()
30+
->extend(TestCase::class)
3031
// ->compact()
3132
->beforeAll(function (): void {})
3233
->beforeEach(function (): void {})

0 commit comments

Comments
 (0)