Skip to content

Commit c14412b

Browse files
committed
final hook in abstract class
1 parent 2115861 commit c14412b

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

src/Rules/Properties/PropertyInClassRule.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,21 @@ public function processNode(Node $node, Scope $scope): array
117117
}
118118
}
119119

120+
if ($classReflection->isAbstract() && $node->isAbstract()) {
121+
foreach ($node->getHooks() as $hook) {
122+
if (!$hook->isFinal()) {
123+
continue;
124+
}
125+
126+
return [
127+
RuleErrorBuilder::message('Property cannot be both abstract and final.')
128+
->nonIgnorable()
129+
->identifier('property.finalPrivate')
130+
->build(),
131+
];
132+
}
133+
}
134+
120135
if ($node->isReadOnly()) {
121136
if ($node->hasHooks()) {
122137
return [

tests/PHPStan/Rules/Properties/PropertyInClassRuleTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,20 @@ public function testPhp84AndPrivateFinalHookedProperties(): void
231231
]);
232232
}
233233

234+
public function testPhp84AndAbstractFinalHookedProperties(): void
235+
{
236+
if (PHP_VERSION_ID < 80400) {
237+
$this->markTestSkipped('Test requires PHP 8.4 or later.');
238+
}
239+
240+
$this->analyse([__DIR__ . '/data/abstract-final-property-hook.php'], [
241+
[
242+
'Property cannot be both abstract and final.',
243+
7,
244+
],
245+
]);
246+
}
247+
234248
public function testPhp84FinalProperties(): void
235249
{
236250
if (PHP_VERSION_ID < 80400) {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php // lint >= 8.4
2+
3+
namespace AbstractFinalHook;
4+
5+
abstract class User
6+
{
7+
abstract public string $foo {
8+
final get;
9+
}
10+
}

0 commit comments

Comments
 (0)