Skip to content

Commit b614f70

Browse files
committed
GetNonVirtualPropertyHookReadRule - do not report if get hook is not present at all
1 parent a742e51 commit b614f70

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/Rules/Properties/GetNonVirtualPropertyHookReadRule.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,17 @@ public function processNode(Node $node, Scope $scope): array
7070

7171
$errors = [];
7272
foreach ($node->getProperties() as $propertyNode) {
73-
if (!$propertyNode->hasHooks()) {
73+
$hasGetHook = false;
74+
foreach ($propertyNode->getHooks() as $hook) {
75+
if ($hook->name->toLowerString() !== 'get') {
76+
continue;
77+
}
78+
79+
$hasGetHook = true;
80+
break;
81+
}
82+
83+
if (!$hasGetHook) {
7484
continue;
7585
}
7686

tests/PHPStan/Rules/Properties/data/get-non-virtual-property-hook-read.php

+9
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,12 @@ class Foo
4646
}
4747

4848
}
49+
50+
class GetHookIsNotPresentAtAll
51+
{
52+
public int $i {
53+
set {
54+
$this->i = $value + 10;
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)