Skip to content

Commit cbd3fd7

Browse files
committed
Fix detecting invalid PHPDocs
1 parent a22ed83 commit cbd3fd7

File tree

9 files changed

+21
-65
lines changed

9 files changed

+21
-65
lines changed

conf/bleedingEdge.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ parameters:
3939
newRuleLevelHelper: true
4040
instanceofType: true
4141
paramOutVariance: true
42-
allInvalidPhpDocs: true
4342
strictStaticMethodTemplateTypeVariance: true
4443
propertyVariance: true
4544
genericPrototypeMessage: true

conf/config.level2.neon

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ services:
146146
-
147147
class: PHPStan\Rules\PhpDoc\InvalidPhpDocTagValueRule
148148
arguments:
149-
checkAllInvalidPhpDocs: %featureToggles.allInvalidPhpDocs%
150149
invalidPhpDocTagLine: %featureToggles.invalidPhpDocTagLine%
151150
tags:
152151
- phpstan.rules.rule
@@ -159,8 +158,6 @@ services:
159158
- phpstan.rules.rule
160159
-
161160
class: PHPStan\Rules\PhpDoc\InvalidPHPStanDocTagRule
162-
arguments:
163-
checkAllInvalidPhpDocs: %featureToggles.allInvalidPhpDocs%
164161
tags:
165162
- phpstan.rules.rule
166163
-

conf/config.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ parameters:
7474
newRuleLevelHelper: false
7575
instanceofType: false
7676
paramOutVariance: false
77-
allInvalidPhpDocs: false
77+
7878
strictStaticMethodTemplateTypeVariance: false
7979
propertyVariance: false
8080
genericPrototypeMessage: false

conf/parametersSchema.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ parametersSchema:
6969
newRuleLevelHelper: bool()
7070
instanceofType: bool()
7171
paramOutVariance: bool()
72-
allInvalidPhpDocs: bool()
7372
strictStaticMethodTemplateTypeVariance: bool()
7473
propertyVariance: bool()
7574
genericPrototypeMessage: bool()

src/PhpDoc/StubValidator.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,15 @@ private function getRuleRegistry(Container $container): RuleRegistry
217217
new InvalidPhpDocTagValueRule(
218218
$container->getByType(Lexer::class),
219219
$container->getByType(PhpDocParser::class),
220-
$container->getParameter('featureToggles')['allInvalidPhpDocs'],
221220
$container->getParameter('featureToggles')['invalidPhpDocTagLine'],
222221
),
223222
new IncompatibleParamImmediatelyInvokedCallableRule($fileTypeMapper),
224223
new IncompatibleSelfOutTypeRule($unresolvableTypeHelper, $genericObjectTypeCheck),
225224
new IncompatibleClassConstantPhpDocTypeRule($genericObjectTypeCheck, $unresolvableTypeHelper),
225+
new InvalidPHPStanDocTagRule(
226+
$container->getByType(Lexer::class),
227+
$container->getByType(PhpDocParser::class),
228+
),
226229
new InvalidThrowsPhpDocValueRule($fileTypeMapper),
227230

228231
// level 6
@@ -240,14 +243,6 @@ private function getRuleRegistry(Container $container): RuleRegistry
240243
$rules[] = new DuplicateFunctionDeclarationRule($reflector, $relativePathHelper);
241244
}
242245

243-
if ((bool) $container->getParameter('featureToggles')['allInvalidPhpDocs']) {
244-
$rules[] = new InvalidPHPStanDocTagRule(
245-
$container->getByType(Lexer::class),
246-
$container->getByType(PhpDocParser::class),
247-
true,
248-
);
249-
}
250-
251246
if ((bool) $container->getParameter('featureToggles')['absentTypeChecks']) {
252247
$rules[] = new MissingMethodSelfOutTypeRule($missingTypehintCheck);
253248

src/Rules/PhpDoc/InvalidPHPStanDocTagRule.php

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use function str_starts_with;
1616

1717
/**
18-
* @implements Rule<Node>
18+
* @implements Rule<Node\Stmt>
1919
*/
2020
final class InvalidPHPStanDocTagRule implements Rule
2121
{
@@ -63,39 +63,23 @@ final class InvalidPHPStanDocTagRule implements Rule
6363
public function __construct(
6464
private Lexer $phpDocLexer,
6565
private PhpDocParser $phpDocParser,
66-
private bool $checkAllInvalidPhpDocs,
6766
)
6867
{
6968
}
7069

7170
public function getNodeType(): string
7271
{
73-
return Node::class;
72+
return Node\Stmt::class;
7473
}
7574

7675
public function processNode(Node $node, Scope $scope): array
7776
{
78-
if (!$this->checkAllInvalidPhpDocs) {
79-
if (
80-
!$node instanceof Node\Stmt\ClassLike
81-
&& !$node instanceof Node\FunctionLike
82-
&& !$node instanceof Node\Stmt\Foreach_
83-
&& !$node instanceof Node\Stmt\Property
84-
&& !$node instanceof Node\Expr\Assign
85-
&& !$node instanceof Node\Expr\AssignRef
86-
&& !$node instanceof Node\Stmt\ClassConst
87-
) {
88-
return [];
89-
}
90-
} else {
91-
// mirrored with InvalidPhpDocTagValueRule
92-
if ($node instanceof VirtualNode) {
93-
return [];
94-
}
95-
if ($node instanceof Node\Stmt\Expression) {
96-
return [];
97-
}
98-
if ($node instanceof Node\Expr && !$node instanceof Node\Expr\Assign && !$node instanceof Node\Expr\AssignRef) {
77+
// mirrored with InvalidPhpDocTagValueRule
78+
if ($node instanceof VirtualNode) {
79+
return [];
80+
}
81+
if ($node instanceof Node\Stmt\Expression) {
82+
if (!$node->expr instanceof Node\Expr\Assign && !$node->expr instanceof Node\Expr\AssignRef) {
9983
return [];
10084
}
10185
}

src/Rules/PhpDoc/InvalidPhpDocTagValueRule.php

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,48 +18,32 @@
1818
use function str_starts_with;
1919

2020
/**
21-
* @implements Rule<Node>
21+
* @implements Rule<Node\Stmt>
2222
*/
2323
final class InvalidPhpDocTagValueRule implements Rule
2424
{
2525

2626
public function __construct(
2727
private Lexer $phpDocLexer,
2828
private PhpDocParser $phpDocParser,
29-
private bool $checkAllInvalidPhpDocs,
3029
private bool $invalidPhpDocTagLine,
3130
)
3231
{
3332
}
3433

3534
public function getNodeType(): string
3635
{
37-
return Node::class;
36+
return Node\Stmt::class;
3837
}
3938

4039
public function processNode(Node $node, Scope $scope): array
4140
{
42-
if (!$this->checkAllInvalidPhpDocs) {
43-
if (
44-
!$node instanceof Node\Stmt\ClassLike
45-
&& !$node instanceof Node\FunctionLike
46-
&& !$node instanceof Node\Stmt\Foreach_
47-
&& !$node instanceof Node\Stmt\Property
48-
&& !$node instanceof Node\Expr\Assign
49-
&& !$node instanceof Node\Expr\AssignRef
50-
&& !$node instanceof Node\Stmt\ClassConst
51-
) {
52-
return [];
53-
}
54-
} else {
55-
// mirrored with InvalidPHPStanDocTagRule
56-
if ($node instanceof VirtualNode) {
57-
return [];
58-
}
59-
if ($node instanceof Node\Stmt\Expression) {
60-
return [];
61-
}
62-
if ($node instanceof Node\Expr && !$node instanceof Node\Expr\Assign && !$node instanceof Node\Expr\AssignRef) {
41+
// mirrored with InvalidPHPStanDocTagRule
42+
if ($node instanceof VirtualNode) {
43+
return [];
44+
}
45+
if ($node instanceof Node\Stmt\Expression) {
46+
if (!$node->expr instanceof Node\Expr\Assign && !$node->expr instanceof Node\Expr\AssignRef) {
6347
return [];
6448
}
6549
}

tests/PHPStan/Rules/PhpDoc/InvalidPHPStanDocTagRuleTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ protected function getRule(): Rule
1818
return new InvalidPHPStanDocTagRule(
1919
self::getContainer()->getByType(Lexer::class),
2020
self::getContainer()->getByType(PhpDocParser::class),
21-
true,
2221
);
2322
}
2423

tests/PHPStan/Rules/PhpDoc/InvalidPhpDocTagValueRuleTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ protected function getRule(): Rule
1919
self::getContainer()->getByType(Lexer::class),
2020
self::getContainer()->getByType(PhpDocParser::class),
2121
true,
22-
true,
2322
);
2423
}
2524

0 commit comments

Comments
 (0)