Skip to content

Commit

Permalink
Merge pull request #1470 from kukulich/hooks
Browse files Browse the repository at this point in the history
Property visibility is not relevant for virtuality
  • Loading branch information
Ocramius authored Dec 18, 2024
2 parents a8b1cd7 + f39caf1 commit 9733d52
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 17 deletions.
1 change: 0 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@
<code><![CDATA[isProtected]]></code>
<code><![CDATA[isProtectedSet]]></code>
<code><![CDATA[isPublic]]></code>
<code><![CDATA[isPublic]]></code>
<code><![CDATA[isReadonly]]></code>
<code><![CDATA[isStatic]]></code>
<code><![CDATA[traitExists]]></code>
Expand Down
8 changes: 2 additions & 6 deletions src/Reflection/ReflectionProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -707,10 +707,10 @@ private function computeImmediateVirtual(PropertyNode $node): bool
return true;
}

return $this->computeImmediateVirtualBasedOnGetHook($node, $getHook);
return $this->computeImmediateVirtualBasedOnGetHook($getHook);
}

private function computeImmediateVirtualBasedOnGetHook(PropertyNode $node, Node\PropertyHook $getHook): bool
private function computeImmediateVirtualBasedOnGetHook(Node\PropertyHook $getHook): bool
{
$getHookBody = $getHook->getStmts();

Expand All @@ -719,10 +719,6 @@ private function computeImmediateVirtualBasedOnGetHook(PropertyNode $node, Node\
return true;
}

if (! $node->isPublic()) {
return true;
}

return ! $this->isHookUsingThisProperty($getHook);
}

Expand Down
10 changes: 2 additions & 8 deletions test/unit/Fixture/PropertyHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,9 @@ abstract class ToBeVirtualOrNotToBeVirtualThatIsTheQuestion
{
public string $notVirtualBecauseNoHooks = 'string';

public string $notVirtualBecauseOfPublicVisibilityAndThePropertyIsUsedInGet {
public string $notVirtualBecauseThePropertyIsUsedInGet {
get {
return strtoupper($this->notVirtualBecauseOfPublicVisibilityAndThePropertyIsUsedInGet);
}
}

protected string $virtualBecauseOfNotPublicVisibilityAndNoSet {
get {
return strtoupper($this->virtualBecauseOfNotPublicVisibilityAndNoSet);
return strtoupper($this->notVirtualBecauseThePropertyIsUsedInGet);
}
}

Expand Down
3 changes: 1 addition & 2 deletions test/unit/Reflection/ReflectionPropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1094,8 +1094,7 @@ public static function virtualProvider(): array
{
return [
['notVirtualBecauseNoHooks', false],
['notVirtualBecauseOfPublicVisibilityAndThePropertyIsUsedInGet', false],
['virtualBecauseOfNotPublicVisibilityAndNoSet', true],
['notVirtualBecauseThePropertyIsUsedInGet', false],
['notVirtualBecauseOfShortSyntax', false],
['virtualBecauseThePropertyIsNotUsedInGet', true],
['virtualBecauseSetWorksWithDifferentProperty', true],
Expand Down

0 comments on commit 9733d52

Please sign in to comment.