File tree Expand file tree Collapse file tree 3 files changed +47
-4
lines changed
tests/PHPStan/Rules/PhpDoc Expand file tree Collapse file tree 3 files changed +47
-4
lines changed Original file line number Diff line number Diff line change 3
3
namespace PHPStan \Rules \PhpDoc ;
4
4
5
5
use PhpParser \Node ;
6
+ use PhpParser \NodeAbstract ;
6
7
use PHPStan \Analyser \Scope ;
8
+ use PHPStan \Node \InPropertyHookNode ;
7
9
use PHPStan \Rules \Rule ;
8
10
use PHPStan \Rules \RuleErrorBuilder ;
9
11
use PHPStan \Type \FileTypeMapper ;
16
18
use function sprintf ;
17
19
18
20
/**
19
- * @implements Rule<Node\Stmt >
21
+ * @implements Rule<NodeAbstract >
20
22
*/
21
23
final class InvalidThrowsPhpDocValueRule implements Rule
22
24
{
@@ -27,13 +29,17 @@ public function __construct(private FileTypeMapper $fileTypeMapper)
27
29
28
30
public function getNodeType (): string
29
31
{
30
- return Node \Stmt ::class;
32
+ return NodeAbstract ::class;
31
33
}
32
34
33
35
public function processNode (Node $ node , Scope $ scope ): array
34
36
{
35
- if ($ node instanceof Node \Stmt \Function_ || $ node instanceof Node \Stmt \ClassMethod) {
36
- return []; // is handled by virtual nodes
37
+ if ($ node instanceof Node \Stmt) {
38
+ if ($ node instanceof Node \Stmt \Function_ || $ node instanceof Node \Stmt \ClassMethod) {
39
+ return []; // is handled by virtual nodes
40
+ }
41
+ } elseif (!$ node instanceof InPropertyHookNode) {
42
+ return [];
37
43
}
38
44
39
45
$ docComment = $ node ->getDocComment ();
Original file line number Diff line number Diff line change 9
9
use PHPStan \Testing \RuleTestCase ;
10
10
use PHPStan \Type \FileTypeMapper ;
11
11
use PHPStan \Type \VerbosityLevel ;
12
+ use const PHP_VERSION_ID ;
12
13
13
14
/**
14
15
* @extends RuleTestCase<InvalidThrowsPhpDocValueRule>
@@ -137,4 +138,18 @@ public function testMergeInheritedPhpDocs(
137
138
$ this ->assertSame ($ expectedType , $ throwsType ->describe (VerbosityLevel::precise ()));
138
139
}
139
140
141
+ public function testPropertyHooks (): void
142
+ {
143
+ if (PHP_VERSION_ID < 80400 ) {
144
+ $ this ->markTestSkipped ('Test requires PHP 8.4. ' );
145
+ }
146
+
147
+ $ this ->analyse ([__DIR__ . '/data/invalid-throws-property-hook.php ' ], [
148
+ [
149
+ 'PHPDoc tag @throws with type DateTimeImmutable is not subtype of Throwable ' ,
150
+ 17 ,
151
+ ],
152
+ ]);
153
+ }
154
+
140
155
}
Original file line number Diff line number Diff line change
1
+ <?php // lint >= 8.4
2
+
3
+ namespace InvalidThrowsPropertyHook ;
4
+
5
+ class Foo
6
+ {
7
+
8
+ public int $ i {
9
+ /** @throws \InvalidArgumentException */
10
+ get {
11
+ return 1 ;
12
+ }
13
+ }
14
+
15
+ public int $ j {
16
+ /** @throws \DateTimeImmutable */
17
+ get {
18
+ return 1 ;
19
+ }
20
+ }
21
+
22
+ }
You can’t perform that action at this time.
0 commit comments