File tree Expand file tree Collapse file tree 4 files changed +144
-0
lines changed
tests/PHPStan/Rules/Properties Expand file tree Collapse file tree 4 files changed +144
-0
lines changed Original file line number Diff line number Diff line change @@ -212,6 +212,13 @@ services:
212212 tags :
213213 - phpstan.rules.rule
214214
215+ -
216+ class : PHPStan\Rules\Properties\SetPropertyHookParameterRule
217+ arguments :
218+ checkPhpDocMethodSignatures : %checkPhpDocMethodSignatures%
219+ tags :
220+ - phpstan.rules.rule
221+
215222 -
216223 class : PHPStan\Rules\Properties\UninitializedPropertyRule
217224
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace PHPStan \Rules \Properties ;
4+
5+ use PhpParser \Node ;
6+ use PHPStan \Analyser \Scope ;
7+ use PHPStan \Node \InPropertyHookNode ;
8+ use PHPStan \Rules \Rule ;
9+
10+ /**
11+ * @implements Rule<InPropertyHookNode>
12+ */
13+ class SetPropertyHookParameterRule implements Rule
14+ {
15+
16+ public function __construct (private bool $ checkPhpDocMethodSignatures )
17+ {
18+ }
19+
20+ public function getNodeType (): string
21+ {
22+ return InPropertyHookNode::class;
23+ }
24+
25+ public function processNode (Node $ node , Scope $ scope ): array
26+ {
27+ return [];
28+ }
29+
30+ }
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace PHPStan \Rules \Properties ;
4+
5+ use PHPStan \Rules \Rule as TRule ;
6+ use PHPStan \Testing \RuleTestCase ;
7+ use const PHP_VERSION_ID ;
8+
9+ /**
10+ * @extends RuleTestCase<SetPropertyHookParameterRule>
11+ */
12+ class SetPropertyHookParameterRuleTest extends RuleTestCase
13+ {
14+
15+ protected function getRule (): TRule
16+ {
17+ return new SetPropertyHookParameterRule (true );
18+ }
19+
20+ public function testRule (): void
21+ {
22+ if (PHP_VERSION_ID < 80400 ) {
23+ $ this ->markTestSkipped ('Test requires PHP 8.4. ' );
24+ }
25+
26+ $ this ->analyse ([__DIR__ . '/data/set-property-hook-parameter.php ' ], []);
27+ }
28+
29+ }
Original file line number Diff line number Diff line change 1+ <?php // lint >= 8.4
2+
3+ namespace SetPropertyHookParameter ;
4+
5+ class Foo
6+ {
7+
8+ public int $ ok {
9+ set (int $ v ) {
10+
11+ }
12+ }
13+
14+ /** @var positive-int */
15+ public int $ ok2 {
16+ set (int $ v ) {
17+
18+ }
19+ }
20+
21+ /** @var positive-int */
22+ public int $ ok3 {
23+ /** @param positive-int|array<string> */
24+ set (int |array $ v ) {
25+
26+ }
27+ }
28+
29+ public $ ok4 {
30+ set ($ v ) {
31+
32+ }
33+ }
34+
35+ }
36+
37+ class Bar
38+ {
39+
40+ public $ a {
41+ set (int $ v ) {
42+
43+ }
44+ }
45+
46+ public int $ b {
47+ set ($ v ) {
48+
49+ }
50+ }
51+
52+ public int $ c {
53+ set (string $ v ) {
54+
55+ }
56+ }
57+
58+ public int |string $ d {
59+ set (string $ v ) {
60+
61+ }
62+ }
63+
64+ public int $ e {
65+ /** @param positive-int */
66+ set (int $ v ) {
67+
68+ }
69+ }
70+
71+ public int $ f {
72+ /** @param positive-int|array<string> */
73+ set (int |array $ v ) {
74+
75+ }
76+ }
77+
78+ }
You can’t perform that action at this time.
0 commit comments