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 33namespace PHPStan \Rules \PhpDoc ;
44
55use PhpParser \Node ;
6+ use PhpParser \NodeAbstract ;
67use PHPStan \Analyser \Scope ;
8+ use PHPStan \Node \InPropertyHookNode ;
79use PHPStan \Rules \Rule ;
810use PHPStan \Rules \RuleErrorBuilder ;
911use PHPStan \Type \FileTypeMapper ;
1618use function sprintf ;
1719
1820/**
19- * @implements Rule<Node\Stmt >
21+ * @implements Rule<NodeAbstract >
2022 */
2123final class InvalidThrowsPhpDocValueRule implements Rule
2224{
@@ -27,13 +29,17 @@ public function __construct(private FileTypeMapper $fileTypeMapper)
2729
2830 public function getNodeType (): string
2931 {
30- return Node \Stmt ::class;
32+ return NodeAbstract ::class;
3133 }
3234
3335 public function processNode (Node $ node , Scope $ scope ): array
3436 {
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 [];
3743 }
3844
3945 $ docComment = $ node ->getDocComment ();
Original file line number Diff line number Diff line change 99use PHPStan \Testing \RuleTestCase ;
1010use PHPStan \Type \FileTypeMapper ;
1111use PHPStan \Type \VerbosityLevel ;
12+ use const PHP_VERSION_ID ;
1213
1314/**
1415 * @extends RuleTestCase<InvalidThrowsPhpDocValueRule>
@@ -137,4 +138,18 @@ public function testMergeInheritedPhpDocs(
137138 $ this ->assertSame ($ expectedType , $ throwsType ->describe (VerbosityLevel::precise ()));
138139 }
139140
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+
140155}
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