Skip to content

Commit b9fd990

Browse files
committed
style(namespaces): Prefix global class references with leading backslashes
- Use leading backslashes for all global class references (e.g. \ComposerBump, \ReflectionClass) to ensure correct resolution. - Qualify SensitiveParameter with a leading backslash in composer-dependency-analyser.php. - Apply fully-qualified global names in tests and config to prevent conflicts. Signed-off-by: guanguans <[email protected]>
1 parent d678beb commit b9fd990

File tree

11 files changed

+29
-28
lines changed

11 files changed

+29
-28
lines changed

.php-cs-fixer.dist.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* @see https://github.com/guanguans/soar-php
1212
*/
1313

14+
use AdamWojs\PhpCsFixerPhpdocForceFQCN\Fixer\Phpdoc\ForceFQCNFixer;
1415
use Ergebnis\License\Holder;
1516
use Ergebnis\License\Range;
1617
use Ergebnis\License\Type\MIT;
@@ -39,7 +40,7 @@
3940
__DIR__.'/LICENSE',
4041
Range::since(
4142
Year::fromString('2019'),
42-
new DateTimeZone('Asia/Shanghai'),
43+
new \DateTimeZone('Asia/Shanghai'),
4344
),
4445
Holder::fromString('guanguans<[email protected]>'),
4546
Url::fromString('https://github.com/guanguans/soar-php'),
@@ -50,8 +51,9 @@
5051
return $mit->header();
5152
})()
5253
)
54+
->withCustomFixers(Fixers::fromFixers(new ForceFQCNFixer))
5355
->withCustomFixers(Fixers::fromFixers(...$phpCsFixerCustomFixers = array_filter(
54-
iterator_to_array(new PhpCsFixerCustomFixers\Fixers),
56+
iterator_to_array(new \PhpCsFixerCustomFixers\Fixers),
5557
static fn (AbstractFixer $fixer): bool => !$fixer instanceof DeprecatedFixerInterface
5658
&& !\array_key_exists($fixer->getName(), Php81::create()->rules()->toArray())
5759
)))
@@ -83,6 +85,7 @@
8385
'@PHPUnit10x0Migration:risky' => true,
8486
]))
8587
->withRules(Rules::fromArray([
88+
'AdamWojs/phpdoc_force_fqcn_fixer' => true,
8689
'align_multiline_comment' => [
8790
'comment_type' => 'phpdocs_only',
8891
],
@@ -126,16 +129,16 @@
126129
'concat_space' => [
127130
'spacing' => 'none',
128131
],
129-
// 'empty_loop_condition' => [
130-
// 'style' => 'for',
131-
// ],
132+
'empty_loop_condition' => [
133+
'style' => 'for',
134+
],
132135
'explicit_string_variable' => false,
133136
'final_class' => false,
134137
// 'final_internal_class' => false,
135138
// 'final_public_method_for_abstract_class' => false,
136139
'fully_qualified_strict_types' => [
137140
'import_symbols' => false,
138-
'leading_backslash_in_global_namespace' => false,
141+
'leading_backslash_in_global_namespace' => true,
139142
'phpdoc_tags' => [
140143
// 'param',
141144
// 'phpstan-param',

composer-bump

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ $statusCode = (new SingleCommandApplication)
4141
->setCode(static function (InputInterface $input, OutputInterface $output): void {
4242
assert_options(\ASSERT_BAIL, 1);
4343
\assert((bool) $input->getOption('highest-php-binary'));
44-
(new ComposerBump(
44+
(new \ComposerBump(
4545
$input->getOption('composer-json-path') ?: implode(\DIRECTORY_SEPARATOR, [__DIR__, 'composer.json']),
4646
$input->getOption('php-binary'),
4747
$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(

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"symfony/process": "^6.4 || ^7.0 || ^8.0"
4545
},
4646
"require-dev": {
47+
"adamwojs/php-cs-fixer-phpdoc-force-fqcn": "^2.0",
4748
"bamarni/composer-bin-plugin": "^1.8",
4849
"brainmaestro/composer-git-hooks": "^3.0",
4950
"composer/composer": "^2.9",

rector.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

src/Support/Rectors/AddDocCommentForHasOptionsRector.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
2727
use Rector\Rector\AbstractRector;
2828
use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
29-
use Symplify\RuleDocGenerator\Exception\PoorDocumentationException;
3029
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
3130
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
3231

@@ -41,7 +40,7 @@ public function __construct(
4140
) {}
4241

4342
/**
44-
* @throws PoorDocumentationException
43+
* @throws \Symplify\RuleDocGenerator\Exception\PoorDocumentationException
4544
*/
4645
public function getRuleDefinition(): RuleDefinition
4746
{
@@ -77,7 +76,7 @@ public function getNodeTypes(): array
7776
}
7877

7978
/**
80-
* @param Trait_ $node
79+
* @param \PhpParser\Node\Stmt\Trait_ $node
8180
*
8281
* @throws \Guanguans\SoarPHP\Exceptions\InvalidOptionException
8382
*/

src/Support/Rectors/AddDocCommentForSoarOptionsRector.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use Rector\PhpParser\Node\Value\ValueResolver;
2121
use Rector\Rector\AbstractRector;
2222
use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
23-
use Symplify\RuleDocGenerator\Exception\PoorDocumentationException;
2423
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
2524
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
2625

@@ -34,7 +33,7 @@ public function __construct(
3433
) {}
3534

3635
/**
37-
* @throws PoorDocumentationException
36+
* @throws \Symplify\RuleDocGenerator\Exception\PoorDocumentationException
3837
*/
3938
public function getRuleDefinition(): RuleDefinition
4039
{
@@ -83,7 +82,7 @@ public function getNodeTypes(): array
8382
}
8483

8584
/**
86-
* @param Node\ArrayItem $node
85+
* @param \PhpParser\Node\ArrayItem $node
8786
*
8887
* @throws \Guanguans\SoarPHP\Exceptions\InvalidOptionException
8988
*/

src/Support/Rectors/SimplifyListIndexRector.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
use Rector\PhpParser\Node\Value\ValueResolver;
2222
use Rector\Rector\AbstractRector;
2323
use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
24-
use Symplify\RuleDocGenerator\Exception\PoorDocumentationException;
2524
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
2625
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
2726

@@ -35,7 +34,7 @@ public function __construct(
3534
) {}
3635

3736
/**
38-
* @throws PoorDocumentationException
37+
* @throws \Symplify\RuleDocGenerator\Exception\PoorDocumentationException
3938
*/
4039
public function getRuleDefinition(): RuleDefinition
4140
{
@@ -70,7 +69,7 @@ public function getNodeTypes(): array
7069
}
7170

7271
/**
73-
* @param Array_ $node
72+
* @param \PhpParser\Node\Expr\Array_ $node
7473
*/
7574
public function refactor(Node $node): ?Node
7675
{

tests/Concerns/HasOptionsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function __invoke(): string
9797
return 'traditional';
9898
}
9999
},
100-
'-explain-type' => new class implements Stringable {
100+
'-explain-type' => new class implements \Stringable {
101101
public function __toString(): string
102102
{
103103
return 'extended';

tests/Pest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
*/
5656
expect()->extend(
5757
'toAssert',
58-
function (Closure $assertions): Expectation {
58+
function (\Closure $assertions): Expectation {
5959
$assertions($this->value);
6060

6161
return $this;
@@ -90,7 +90,7 @@ function class_namespace(object|string $class): string
9090
{
9191
$class = \is_object($class) ? $class::class : $class;
9292

93-
return (new ReflectionClass($class))->getNamespaceName();
93+
return (new \ReflectionClass($class))->getNamespaceName();
9494
}
9595

9696
function fixtures_path(string $path = ''): string
@@ -102,7 +102,7 @@ function fixtures_path(string $path = ''): string
102102
/**
103103
* @see https://github.com/laravel/framework/blob/12.x/src/Illuminate/Foundation/helpers.php#L515
104104
*/
105-
function fake(string $locale = Factory::DEFAULT_LOCALE): Generator
105+
function fake(string $locale = Factory::DEFAULT_LOCALE): \Generator
106106
{
107107
return Factory::create($locale);
108108
}

0 commit comments

Comments
 (0)