Skip to content

Commit b1310f7

Browse files
committed
Property in interface cannot be explicitly abstract
1 parent 39a6edd commit b1310f7

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

src/Rules/Properties/PropertiesInInterfaceRule.php

+9
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,15 @@ public function processNode(Node $node, Scope $scope): array
7575
];
7676
}
7777

78+
if ($node->isAbstract()) {
79+
return [
80+
RuleErrorBuilder::message('Property in interface cannot be explicitly abstract.')
81+
->nonIgnorable()
82+
->identifier('property.hookedStatic')
83+
->build(),
84+
];
85+
}
86+
7887
if ($node->isFinal()) {
7988
return [
8089
RuleErrorBuilder::message('Interfaces cannot include final properties.')

tests/PHPStan/Rules/Properties/PropertiesInInterfaceRuleTest.php

+14
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,20 @@ public function testPhp84AndFinalPropertyHooksInInterface(): void
178178
]);
179179
}
180180

181+
public function testPhp84AndExplicitAbstractProperty(): void
182+
{
183+
if (PHP_VERSION_ID < 80400) {
184+
$this->markTestSkipped('Test requires PHP 8.4 or later.');
185+
}
186+
187+
$this->analyse([__DIR__ . '/data/property-in-interface-explicit-abstract.php'], [
188+
[
189+
'Property in interface cannot be explicitly abstract.',
190+
8,
191+
],
192+
]);
193+
}
194+
181195
public function testPhp84AndStaticHookedPropertyInInterface(): void
182196
{
183197
if (PHP_VERSION_ID < 80400) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace PropertyInInterfaceExplicitAbstract;
4+
5+
// https://3v4l.org/79QMR#v8.4.4
6+
interface Foo
7+
{
8+
abstract public int $i {
9+
set;
10+
}
11+
12+
public int $y {
13+
set;
14+
}
15+
}

0 commit comments

Comments
 (0)