Skip to content

Commit a50bbdc

Browse files
committed
abstract final
1 parent 3377080 commit a50bbdc

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/Rules/Properties/PropertyInClassRule.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,15 @@ public function processNode(Node $node, Scope $scope): array
118118
}
119119

120120
if ($classReflection->isAbstract() && $node->isAbstract()) {
121+
if ($node->isFinal()) {
122+
return [
123+
RuleErrorBuilder::message('Property cannot be both abstract and final.')
124+
->nonIgnorable()
125+
->identifier('property.abstractFinal')
126+
->build(),
127+
];
128+
}
129+
121130
foreach ($node->getHooks() as $hook) {
122131
if (!$hook->isFinal()) {
123132
continue;
@@ -126,7 +135,7 @@ public function processNode(Node $node, Scope $scope): array
126135
return [
127136
RuleErrorBuilder::message('Property cannot be both abstract and final.')
128137
->nonIgnorable()
129-
->identifier('property.finalPrivate')
138+
->identifier('property.abstractFinal')
130139
->build(),
131140
];
132141
}

tests/PHPStan/Rules/Properties/PropertyInClassRuleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ public function testPhp84AndAbstractFinalHookedProperties(): void
242242
'Property cannot be both abstract and final.',
243243
7,
244244
],
245+
[
246+
'Property cannot be both abstract and final.',
247+
11,
248+
],
245249
]);
246250
}
247251

tests/PHPStan/Rules/Properties/data/abstract-final-property-hook.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ abstract class User
77
abstract public string $foo {
88
final get;
99
}
10+
11+
final abstract public string $bar {
12+
get;
13+
}
1014
}

0 commit comments

Comments
 (0)