Skip to content

Commit 7eaed3a

Browse files
committed
Fix logic
1 parent 0d3edef commit 7eaed3a

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

src/Rules/Properties/PropertyInClassRule.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,17 @@ public function processNode(Node $node, Scope $scope): array
6464
->build(),
6565
];
6666
}
67+
68+
return [];
6769
}
6870

69-
if (!$node->isAbstract()) {
70-
if ($node->hasHooks()) {
71-
return [
72-
RuleErrorBuilder::message('Abstract classes cannot include non-abstract hooked properties without bodies.')
73-
->nonIgnorable()
74-
->identifier('property.nonAbstractWithAbstractHook')
75-
->build(),
76-
];
77-
}
71+
if (!$this->doAllHooksHaveBody($node)) {
72+
return [
73+
RuleErrorBuilder::message('Non-abstract properties cannot include hooks without bodies.')
74+
->nonIgnorable()
75+
->identifier('property.hookWithoutBody')
76+
->build(),
77+
];
7878
}
7979

8080
return [];

tests/PHPStan/Rules/Properties/PropertyInClassRuleTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,17 @@ public function testPhp84AndNonAbstractHookedPropertiesInAbstractClass(): void
9797

9898
$this->analyse([__DIR__ . '/data/non-abstract-hooked-properties-in-abstract-class.php'], [
9999
[
100-
'Abstract classes cannot include non-abstract hooked properties without bodies.',
100+
'Non-abstract properties cannot include hooks without bodies.',
101101
7,
102102
],
103103
[
104-
'Abstract classes cannot include non-abstract hooked properties without bodies.',
104+
'Non-abstract properties cannot include hooks without bodies.',
105105
9,
106106
],
107+
[
108+
'Non-abstract properties cannot include hooks without bodies.',
109+
25,
110+
],
107111
]);
108112
}
109113

tests/PHPStan/Rules/Properties/data/non-abstract-hooked-properties-in-abstract-class.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,28 @@ abstract class AbstractPerson
88

99
public string $lastName { get; set; }
1010
}
11+
12+
abstract class Foo
13+
{
14+
15+
public string $name {
16+
get {
17+
18+
}
19+
20+
set {
21+
22+
}
23+
}
24+
25+
public string $name2 {
26+
get;
27+
28+
set {
29+
30+
}
31+
}
32+
33+
public string $name3;
34+
35+
}

0 commit comments

Comments
 (0)