Skip to content

Commit 861a6c0

Browse files
committed
Fix GetNonVirtualPropertyHookReadRule on abstract property
1 parent 6b0d8c3 commit 861a6c0

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/Rules/Properties/GetNonVirtualPropertyHookReadRule.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ public function processNode(Node $node, Scope $scope): array
9393
continue;
9494
}
9595

96+
if ($propertyReflection->isAbstract()->yes()) {
97+
continue;
98+
}
99+
96100
$errors[] = RuleErrorBuilder::message(sprintf(
97101
'Get hook for non-virtual property %s::$%s does not read its value.',
98102
$classReflection->getDisplayName(),

tests/PHPStan/Rules/Properties/GetNonVirtualPropertyHookReadRuleTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,13 @@ public function testRule(): void
3535
]);
3636
}
3737

38+
public function testAbstractProperty(): void
39+
{
40+
if (PHP_VERSION_ID < 80400) {
41+
$this->markTestSkipped('Test requires PHP 8.4.');
42+
}
43+
44+
$this->analyse([__DIR__ . '/data/get-abstract-property-hook-read.php'], []);
45+
}
46+
3847
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php // lint >= 8.4
2+
3+
namespace GetAbstractPropertyHook;
4+
5+
class NonFinalClass
6+
{
7+
public string $publicProperty;
8+
}
9+
10+
abstract class Foo extends NonFinalClass
11+
{
12+
abstract public string $publicProperty {
13+
get;
14+
}
15+
}

0 commit comments

Comments
 (0)