Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Property visibility is not relevant for virtuality #1470

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading