Skip to content

Commit aa0b8ec

Browse files
committed
style: apply php-cs-fixer
1 parent b9fd990 commit aa0b8ec

12 files changed

+174
-129
lines changed

.php-cs-fixer.dist.php

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
use Ergebnis\PhpCsFixer\Config\RuleSet\Php81;
2424
use PhpCsFixer\Finder;
2525
use PhpCsFixer\Fixer\DeprecatedFixerInterface;
26-
use PhpCsFixerCustomFixers\Fixer\AbstractFixer;
26+
use PhpCsFixer\Fixer\FixerInterface;
2727

2828
require __DIR__.'/vendor/autoload.php';
2929

@@ -40,7 +40,7 @@
4040
__DIR__.'/LICENSE',
4141
Range::since(
4242
Year::fromString('2019'),
43-
new \DateTimeZone('Asia/Shanghai'),
43+
new DateTimeZone('Asia/Shanghai'),
4444
),
4545
Holder::fromString('guanguans<[email protected]>'),
4646
Url::fromString('https://github.com/guanguans/soar-php'),
@@ -51,11 +51,54 @@
5151
return $mit->header();
5252
})()
5353
)
54-
->withCustomFixers(Fixers::fromFixers(new ForceFQCNFixer))
54+
->withCustomFixers(Fixers::fromFixers($forceFQCNFixer = new ForceFQCNFixer))
55+
->withCustomFixers(Fixers::fromFixers(...$erickSkrauchFixers = array_filter(
56+
iterator_to_array(new ErickSkrauch\PhpCsFixer\Fixers),
57+
static fn (FixerInterface $fixer): bool => !$fixer instanceof DeprecatedFixerInterface
58+
&& !\array_key_exists($fixer->getName(), Php81::create()->rules()->toArray())
59+
&& !\in_array(
60+
$fixer->getName(),
61+
[
62+
'ErickSkrauch/align_multiline_parameters',
63+
'ErickSkrauch/blank_line_around_class_body',
64+
],
65+
true
66+
)
67+
)))
68+
->withRules(Rules::fromArray(array_reduce(
69+
$erickSkrauchFixers,
70+
static function (array $carry, FixerInterface $fixer): array {
71+
$carry[$fixer->getName()] = true;
72+
73+
return $carry;
74+
},
75+
[]
76+
)))
5577
->withCustomFixers(Fixers::fromFixers(...$phpCsFixerCustomFixers = array_filter(
56-
iterator_to_array(new \PhpCsFixerCustomFixers\Fixers),
57-
static fn (AbstractFixer $fixer): bool => !$fixer instanceof DeprecatedFixerInterface
78+
iterator_to_array(new PhpCsFixerCustomFixers\Fixers),
79+
static fn (FixerInterface $fixer): bool => !$fixer instanceof DeprecatedFixerInterface
5880
&& !\array_key_exists($fixer->getName(), Php81::create()->rules()->toArray())
81+
&& !\in_array(
82+
$fixer->getName(),
83+
[
84+
'PhpCsFixerCustomFixers/declare_after_opening_tag',
85+
'PhpCsFixerCustomFixers/isset_to_array_key_exists',
86+
'PhpCsFixerCustomFixers/no_commented_out_code',
87+
// 'PhpCsFixerCustomFixers/no_leading_slash_in_global_namespace',
88+
'PhpCsFixerCustomFixers/phpdoc_only_allowed_annotations',
89+
'PhpCsFixerCustomFixers/typed_class_constant', // @since 8.3
90+
],
91+
true
92+
)
93+
)))
94+
->withRules(Rules::fromArray(array_reduce(
95+
$phpCsFixerCustomFixers,
96+
static function (array $carry, FixerInterface $fixer): array {
97+
$carry[$fixer->getName()] = true;
98+
99+
return $carry;
100+
},
101+
[]
59102
)))
60103
->withRules(Rules::fromArray([
61104
// '@auto' => true,
@@ -85,7 +128,7 @@
85128
'@PHPUnit10x0Migration:risky' => true,
86129
]))
87130
->withRules(Rules::fromArray([
88-
'AdamWojs/phpdoc_force_fqcn_fixer' => true,
131+
$forceFQCNFixer->getName() => true,
89132
'align_multiline_comment' => [
90133
'comment_type' => 'phpdocs_only',
91134
],
@@ -138,7 +181,7 @@
138181
// 'final_public_method_for_abstract_class' => false,
139182
'fully_qualified_strict_types' => [
140183
'import_symbols' => false,
141-
'leading_backslash_in_global_namespace' => true,
184+
'leading_backslash_in_global_namespace' => false,
142185
'phpdoc_tags' => [
143186
// 'param',
144187
// 'phpstan-param',
@@ -315,5 +358,6 @@
315358
->ignoreVCSIgnored(true)
316359
->append([
317360
__DIR__.'/composer-bump',
361+
__DIR__.'/rule-doc-generator',
318362
])
319363
);

composer-bump

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ use Symfony\Component\Process\ExecutableFinder;
2525
use Symfony\Component\Process\PhpExecutableFinder;
2626
use Symfony\Component\Process\Process;
2727

28-
require __DIR__.'/vendor/autoload.php';
2928
file_exists($autoload = __DIR__.'/../../vendor/autoload.php') and require $autoload;
3029

30+
require __DIR__.'/vendor/autoload.php';
31+
3132
/** @noinspection PhpUnhandledExceptionInspection */
3233
/** @noinspection DuplicatedCode */
3334
$statusCode = (new SingleCommandApplication)
@@ -41,7 +42,7 @@ $statusCode = (new SingleCommandApplication)
4142
->setCode(static function (InputInterface $input, OutputInterface $output): void {
4243
assert_options(\ASSERT_BAIL, 1);
4344
\assert((bool) $input->getOption('highest-php-binary'));
44-
(new \ComposerBump(
45+
(new ComposerBump(
4546
$input->getOption('composer-json-path') ?: implode(\DIRECTORY_SEPARATOR, [__DIR__, 'composer.json']),
4647
$input->getOption('php-binary'),
4748
$input->getOption('highest-php-binary'),

composer-dependency-analyser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
__DIR__.'/tests/',
2828
])
2929
->ignoreUnknownClasses([
30-
\SensitiveParameter::class,
30+
SensitiveParameter::class,
3131
])
3232
/** @see \ShipMonk\ComposerDependencyAnalyser\Analyser::CORE_EXTENSIONS */
3333
->ignoreErrorsOnExtensions(

rector.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
use Illuminate\Support\Str;
2525
use Rector\CodeQuality\Rector\If_\ExplicitBoolCompareRector;
2626
use Rector\CodeQuality\Rector\LogicalAnd\LogicalToBooleanRector;
27+
use Rector\CodingStyle\Rector\ArrowFunction\ArrowFunctionDelegatingCallToFirstClassCallableRector;
2728
use Rector\CodingStyle\Rector\ArrowFunction\StaticArrowFunctionRector;
2829
use Rector\CodingStyle\Rector\ClassLike\NewlineBetweenClassLikeStmtsRector;
2930
use Rector\CodingStyle\Rector\Closure\StaticClosureRector;
3031
use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector;
3132
use Rector\CodingStyle\Rector\Encapsed\WrapEncapsedVariableInCurlyBracesRector;
3233
use Rector\CodingStyle\Rector\FuncCall\ArraySpreadInsteadOfArrayMergeRector;
33-
use Rector\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector;
3434
use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
3535
use Rector\Config\RectorConfig;
3636
use Rector\DeadCode\Rector\ClassLike\RemoveAnnotationRector;
@@ -137,8 +137,8 @@
137137
->withConfiguredRule(
138138
AnnotationToAttributeRector::class,
139139
classes(static fn (string $class): bool => str_starts_with($class, 'PhpBench\Attributes'))
140-
->filter(static fn (\ReflectionClass $reflectionClass): bool => $reflectionClass->isInstantiable())
141-
->map(static fn (\ReflectionClass $reflectionClass): AnnotationToAttribute => new AnnotationToAttribute(
140+
->filter(static fn (ReflectionClass $reflectionClass): bool => $reflectionClass->isInstantiable())
141+
->map(static fn (ReflectionClass $reflectionClass): AnnotationToAttribute => new AnnotationToAttribute(
142142
$reflectionClass->getShortName(),
143143
$reflectionClass->getName(),
144144
[],
@@ -149,11 +149,11 @@ classes(static fn (string $class): bool => str_starts_with($class, 'PhpBench\Att
149149
->withConfiguredRule(
150150
ChangeMethodVisibilityRector::class,
151151
classes(static fn (string $class, string $file): bool => str_starts_with($class, 'Guanguans\SoarPHP'))
152-
->filter(static fn (\ReflectionClass $reflectionClass): bool => $reflectionClass->isTrait())
152+
->filter(static fn (ReflectionClass $reflectionClass): bool => $reflectionClass->isTrait())
153153
->map(
154-
static fn (\ReflectionClass $reflectionClass): array => collect($reflectionClass->getMethods(\ReflectionMethod::IS_PRIVATE))
155-
->reject(static fn (\ReflectionMethod $reflectionMethod): bool => $reflectionMethod->isFinal() || $reflectionMethod->isInternal())
156-
->map(static fn (\ReflectionMethod $reflectionMethod): ChangeMethodVisibility => new ChangeMethodVisibility(
154+
static fn (ReflectionClass $reflectionClass): array => collect($reflectionClass->getMethods(ReflectionMethod::IS_PRIVATE))
155+
->reject(static fn (ReflectionMethod $reflectionMethod): bool => $reflectionMethod->isFinal() || $reflectionMethod->isInternal())
156+
->map(static fn (ReflectionMethod $reflectionMethod): ChangeMethodVisibility => new ChangeMethodVisibility(
157157
$reflectionClass->getName(),
158158
$reflectionMethod->getName(),
159159
Visibility::PROTECTED
@@ -195,8 +195,7 @@ static function (array $carry, string $func): array {
195195
WrapEncapsedVariableInCurlyBracesRector::class,
196196
])
197197
->withSkip([
198-
FunctionLikeToFirstClassCallableRector::class => [
199-
__DIR__.'/src/Support/helpers.php',
198+
ArrowFunctionDelegatingCallToFirstClassCallableRector::class => [
200199
__DIR__.'/tests/Concerns/HasOptionsTest.php',
201200
],
202201
StaticArrowFunctionRector::class => $staticClosureSkipPaths = [
@@ -208,6 +207,7 @@ static function (array $carry, string $func): array {
208207
__DIR__.'/examples/',
209208
__DIR__.'/src/',
210209
__DIR__.'/tests/',
210+
__FILE__,
211211
],
212212
AddNoinspectionsDocCommentToDeclareRector::class => [
213213
__DIR__.'/benchmarks/',

rule-doc-generator

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
declare(strict_types=1);
55

66
/**
7-
* Copyright (c) 2021-2025 guanguans<[email protected]>
7+
* Copyright (c) 2019-2025 guanguans<[email protected]>
88
*
99
* For the full copyright and license information, please view
1010
* the LICENSE file that was distributed with this source code.
1111
*
12-
* @see https://github.com/guanguans/laravel-skeleton
12+
* @see https://github.com/guanguans/soar-php
1313
*/
1414

1515
namespace RuleDocGenerator202408;

src/Concerns/WithRunable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ protected function toProcess(): Process
6363
$this->tap->call($process, $process);
6464
}
6565

66-
return $this->pipe instanceof \Closure ? ($this->pipe)->call($process, $process) : $process;
66+
return $this->pipe instanceof \Closure ? $this->pipe->call($process, $process) : $process;
6767
}
6868
}

src/Support/Rectors/AddDocCommentForHasOptionsRector.php

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -39,37 +39,6 @@ public function __construct(
3939
private readonly PhpDocInfoFactory $phpDocInfoFactory
4040
) {}
4141

42-
/**
43-
* @throws \Symplify\RuleDocGenerator\Exception\PoorDocumentationException
44-
*/
45-
public function getRuleDefinition(): RuleDefinition
46-
{
47-
return new RuleDefinition(
48-
'Add doc comment for has options rector',
49-
[
50-
new CodeSample(
51-
<<<'CODE_SAMPLE'
52-
trait HasOptions
53-
{
54-
}
55-
CODE_SAMPLE,
56-
<<<'CODE_SAMPLE'
57-
/**
58-
* @method \Guanguans\SoarPHP\Soar exceptVerbose() // Verbose
59-
* @method \Guanguans\SoarPHP\Soar exceptVersion() // Print version info
60-
* @method \Guanguans\SoarPHP\Soar exceptHelp() // Help
61-
*
62-
* @mixin \Guanguans\SoarPHP\Soar
63-
*/
64-
trait HasOptions
65-
{
66-
}
67-
CODE_SAMPLE,
68-
),
69-
],
70-
);
71-
}
72-
7342
public function getNodeTypes(): array
7443
{
7544
return [Trait_::class];
@@ -133,4 +102,35 @@ public function refactor(Node $node): ?Node
133102

134103
return $node;
135104
}
105+
106+
/**
107+
* @throws \Symplify\RuleDocGenerator\Exception\PoorDocumentationException
108+
*/
109+
public function getRuleDefinition(): RuleDefinition
110+
{
111+
return new RuleDefinition(
112+
'Add doc comment for has options rector',
113+
[
114+
new CodeSample(
115+
<<<'CODE_SAMPLE'
116+
trait HasOptions
117+
{
118+
}
119+
CODE_SAMPLE,
120+
<<<'CODE_SAMPLE'
121+
/**
122+
* @method \Guanguans\SoarPHP\Soar exceptVerbose() // Verbose
123+
* @method \Guanguans\SoarPHP\Soar exceptVersion() // Print version info
124+
* @method \Guanguans\SoarPHP\Soar exceptHelp() // Help
125+
*
126+
* @mixin \Guanguans\SoarPHP\Soar
127+
*/
128+
trait HasOptions
129+
{
130+
}
131+
CODE_SAMPLE,
132+
),
133+
],
134+
);
135+
}
136136
}

src/Support/Rectors/AddDocCommentForSoarOptionsRector.php

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -32,48 +32,6 @@ public function __construct(
3232
private readonly ValueResolver $valueResolver
3333
) {}
3434

35-
/**
36-
* @throws \Symplify\RuleDocGenerator\Exception\PoorDocumentationException
37-
*/
38-
public function getRuleDefinition(): RuleDefinition
39-
{
40-
return new RuleDefinition(
41-
'Add doc comment for soar options rector',
42-
[
43-
new CodeSample(
44-
<<<'CODE_SAMPLE'
45-
return [
46-
'-allow-charsets' => [
47-
0 => 'utf8',
48-
1 => 'utf8mb4',
49-
],
50-
'-allow-collates' => [
51-
],
52-
'-allow-drop-index' => false,
53-
];
54-
55-
CODE_SAMPLE,
56-
<<<'CODE_SAMPLE'
57-
return [
58-
// AllowCharsets (default "utf8,utf8mb4")
59-
'-allow-charsets' => [
60-
0 => 'utf8',
61-
1 => 'utf8mb4',
62-
],
63-
64-
// AllowCollates
65-
'-allow-collates' => [
66-
],
67-
68-
// AllowDropIndex, 允许输出删除重复索引的建议
69-
'-allow-drop-index' => false,
70-
];
71-
CODE_SAMPLE,
72-
),
73-
],
74-
);
75-
}
76-
7735
public function getNodeTypes(): array
7836
{
7937
return [
@@ -119,4 +77,46 @@ public function refactor(Node $node): ?Node
11977

12078
return $node;
12179
}
80+
81+
/**
82+
* @throws \Symplify\RuleDocGenerator\Exception\PoorDocumentationException
83+
*/
84+
public function getRuleDefinition(): RuleDefinition
85+
{
86+
return new RuleDefinition(
87+
'Add doc comment for soar options rector',
88+
[
89+
new CodeSample(
90+
<<<'CODE_SAMPLE'
91+
return [
92+
'-allow-charsets' => [
93+
0 => 'utf8',
94+
1 => 'utf8mb4',
95+
],
96+
'-allow-collates' => [
97+
],
98+
'-allow-drop-index' => false,
99+
];
100+
101+
CODE_SAMPLE,
102+
<<<'CODE_SAMPLE'
103+
return [
104+
// AllowCharsets (default "utf8,utf8mb4")
105+
'-allow-charsets' => [
106+
0 => 'utf8',
107+
1 => 'utf8mb4',
108+
],
109+
110+
// AllowCollates
111+
'-allow-collates' => [
112+
],
113+
114+
// AllowDropIndex, 允许输出删除重复索引的建议
115+
'-allow-drop-index' => false,
116+
];
117+
CODE_SAMPLE,
118+
),
119+
],
120+
);
121+
}
122122
}

0 commit comments

Comments
 (0)