Skip to content

Commit 5196b92

Browse files
committed
Prevent reporting property.inInterface error when PHP version is 8.4 or later
1 parent c0bfae6 commit 5196b92

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/Rules/Properties/PropertiesInInterfaceRule.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
use PHPStan\Node\ClassPropertyNode;
88
use PHPStan\Rules\Rule;
99
use PHPStan\Rules\RuleErrorBuilder;
10+
use const PHP_VERSION_ID;
1011

1112
/**
1213
* @implements Rule<ClassPropertyNode>
1314
*/
1415
final class PropertiesInInterfaceRule implements Rule
1516
{
1617

18+
private const PHP_8_4_VERSION_ID = 80400;
19+
1720
public function getNodeType(): string
1821
{
1922
return ClassPropertyNode::class;
@@ -25,6 +28,10 @@ public function processNode(Node $node, Scope $scope): array
2528
return [];
2629
}
2730

31+
if (PHP_VERSION_ID >= self::PHP_8_4_VERSION_ID) {
32+
return [];
33+
}
34+
2835
return [
2936
RuleErrorBuilder::message('Interfaces may not include properties.')
3037
->nonIgnorable()

tests/PHPStan/Rules/Properties/PropertiesInInterfaceRuleTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,29 @@
44

55
use PHPStan\Rules\Rule;
66
use PHPStan\Testing\RuleTestCase;
7+
use const PHP_VERSION_ID;
78

89
/**
910
* @extends RuleTestCase<PropertiesInInterfaceRule>
1011
*/
1112
class PropertiesInInterfaceRuleTest extends RuleTestCase
1213
{
1314

15+
private const PHP_8_4_VERSION_ID = 80400;
16+
1417
protected function getRule(): Rule
1518
{
1619
return new PropertiesInInterfaceRule();
1720
}
1821

1922
public function testRule(): void
2023
{
24+
if (PHP_VERSION_ID >= self::PHP_8_4_VERSION_ID) {
25+
$this->analyse([__DIR__ . '/data/properties-in-interface.php'], []);
26+
27+
return;
28+
}
29+
2130
$this->analyse([__DIR__ . '/data/properties-in-interface.php'], [
2231
[
2332
'Interfaces may not include properties.',

0 commit comments

Comments
 (0)