Skip to content

Commit b2c2576

Browse files
committed
PropertyHookReturnStatementsNode is invoked for short body hooks
1 parent cc83891 commit b2c2576

7 files changed

+47
-0
lines changed

tests/PHPStan/Rules/Exceptions/MissingCheckedExceptionInPropertyHookThrowsRuleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ public function testRule(): void
4545
'Get hook for property MissingExceptionPropertyHookThrows\Foo::$m throws checked exception InvalidArgumentException but it\'s missing from the PHPDoc @throws tag.',
4646
38,
4747
],
48+
[
49+
'Get hook for property MissingExceptionPropertyHookThrows\Foo::$n throws checked exception InvalidArgumentException but it\'s missing from the PHPDoc @throws tag.',
50+
43,
51+
],
4852
]);
4953
}
5054

tests/PHPStan/Rules/Exceptions/ThrowsVoidPropertyHookWithExplicitThrowPointRuleTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public function dataRule(): array
4444
'Get hook for property ThrowsVoidPropertyHook\Foo::$i throws exception ThrowsVoidPropertyHook\MyException but the PHPDoc contains @throws void.',
4545
18,
4646
],
47+
[
48+
'Get hook for property ThrowsVoidPropertyHook\Foo::$j throws exception ThrowsVoidPropertyHook\MyException but the PHPDoc contains @throws void.',
49+
26,
50+
],
4751
],
4852
],
4953
[
@@ -59,6 +63,10 @@ public function dataRule(): array
5963
'Get hook for property ThrowsVoidPropertyHook\Foo::$i throws exception ThrowsVoidPropertyHook\MyException but the PHPDoc contains @throws void.',
6064
18,
6165
],
66+
[
67+
'Get hook for property ThrowsVoidPropertyHook\Foo::$j throws exception ThrowsVoidPropertyHook\MyException but the PHPDoc contains @throws void.',
68+
26,
69+
],
6270
],
6371
],
6472
[
@@ -69,6 +77,10 @@ public function dataRule(): array
6977
'Get hook for property ThrowsVoidPropertyHook\Foo::$i throws exception ThrowsVoidPropertyHook\MyException but the PHPDoc contains @throws void.',
7078
18,
7179
],
80+
[
81+
'Get hook for property ThrowsVoidPropertyHook\Foo::$j throws exception ThrowsVoidPropertyHook\MyException but the PHPDoc contains @throws void.',
82+
26,
83+
],
7284
],
7385
],
7486
[
@@ -79,6 +91,10 @@ public function dataRule(): array
7991
'Get hook for property ThrowsVoidPropertyHook\Foo::$i throws exception ThrowsVoidPropertyHook\MyException but the PHPDoc contains @throws void.',
8092
18,
8193
],
94+
[
95+
'Get hook for property ThrowsVoidPropertyHook\Foo::$j throws exception ThrowsVoidPropertyHook\MyException but the PHPDoc contains @throws void.',
96+
26,
97+
],
8298
],
8399
],
84100
];

tests/PHPStan/Rules/Exceptions/TooWidePropertyHookThrowTypeRuleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public function testRule(): void
4343
'Get hook for property TooWideThrowsPropertyHook\Foo::$j has DomainException in PHPDoc @throws tag but it\'s not thrown.',
4444
76,
4545
],
46+
[
47+
'Get hook for property TooWideThrowsPropertyHook\Foo::$k has DomainException in PHPDoc @throws tag but it\'s not thrown.',
48+
83,
49+
],
4650
]);
4751
}
4852

tests/PHPStan/Rules/Exceptions/data/missing-exception-property-hook-throws.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,8 @@ class Foo
3939
}
4040
}
4141

42+
public int $n {
43+
get => throw new \InvalidArgumentException(); // error
44+
}
45+
4246
}

tests/PHPStan/Rules/Exceptions/data/throws-void-property-hook.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,11 @@ class Foo
1919
}
2020
}
2121

22+
public int $j {
23+
/**
24+
* @throws void
25+
*/
26+
get => throw new MyException();
27+
}
28+
2229
}

tests/PHPStan/Rules/Exceptions/data/too-wide-throws-property-hook.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,9 @@ class Foo
7878
}
7979
}
8080

81+
public int $k {
82+
/** @throws \DomainException */
83+
get => 11; // error - DomainException unused
84+
}
85+
8186
}

tests/PHPStan/Rules/Properties/data/set-non-virtual-property-hook-assign.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,11 @@ class Foo
6565
}
6666
}
6767

68+
public int $k5 {
69+
get {
70+
return $this->k4 + 1;
71+
}
72+
set => $value; // short body always assigns
73+
}
74+
6875
}

0 commit comments

Comments
 (0)