Skip to content

Commit d95074f

Browse files
committed
Property hook cannot be both abstract and final
1 parent 944f86c commit d95074f

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

src/Rules/Properties/PropertiesInInterfaceRule.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@ public function processNode(Node $node, Scope $scope): array
8484
];
8585
}
8686

87+
foreach ($node->getHooks() as $hook) {
88+
if (!$hook->isFinal()) {
89+
continue;
90+
}
91+
92+
return [
93+
RuleErrorBuilder::message('Property hook cannot be both abstract and final.')
94+
->nonIgnorable()
95+
->identifier('property.abstractFinal')
96+
->build(),
97+
];
98+
}
99+
87100
if ($this->hasAnyHookBody($node)) {
88101
return [
89102
RuleErrorBuilder::message('Interfaces cannot include property hooks with bodies.')

tests/PHPStan/Rules/Properties/PropertiesInInterfaceRuleTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ public function testPhp84AndFinalPropertyHooksInInterface(): void
167167
'Interfaces cannot include final properties.',
168168
11,
169169
],
170+
[
171+
'Property hook cannot be both abstract and final.',
172+
13,
173+
],
174+
[
175+
'Property hook cannot be both abstract and final.',
176+
17,
177+
],
170178
]);
171179
}
172180

tests/PHPStan/Rules/Properties/data/final-property-hooks-in-interface.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,12 @@ interface HelloWorld
99
public final string $middleName { get; }
1010

1111
public final string $lastName { set; }
12+
13+
public string $finalGetHook {
14+
final get;
15+
}
16+
17+
public string $finalSetHook {
18+
final set;
19+
}
1220
}

0 commit comments

Comments
 (0)