Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Rules/Properties/GetNonVirtualPropertyHookReadRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public function processNode(Node $node, Scope $scope): array
continue;
}

if ($propertyReflection->isAbstract()->yes()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this is a wrong fix. Instead, the foreach over the hooks above should check if the get hook has a body or not.

continue;
}

$errors[] = RuleErrorBuilder::message(sprintf(
'Get hook for non-virtual property %s::$%s does not read its value.',
$classReflection->getDisplayName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,13 @@ public function testRule(): void
]);
}

public function testAbstractProperty(): void
{
if (PHP_VERSION_ID < 80400) {
$this->markTestSkipped('Test requires PHP 8.4.');
}

$this->analyse([__DIR__ . '/data/get-abstract-property-hook-read.php'], []);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php // lint >= 8.4

namespace GetAbstractPropertyHook;

class NonFinalClass
{
public string $publicProperty;
}

abstract class Foo extends NonFinalClass
{
abstract public string $publicProperty {
get;
}
}
Loading