Skip to content

Commit 283c003

Browse files
phpstan-botclaude
andcommitted
Document hasRestrictedWriteAccess: explain difference from private properties and why private(get) is not needed
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 23a0cf7 commit 283c003

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/Rules/Generics/PropertyVarianceRule.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ public function processNode(Node $node, Scope $scope): array
5656
);
5757
}
5858

59+
/**
60+
* Checks whether a non-private property is not publicly writable.
61+
*
62+
* This differs from a fully private property (handled by the early return above):
63+
* a private property is completely inaccessible externally, so variance is irrelevant
64+
* and is skipped entirely. Here, the property IS publicly readable (covariant/output
65+
* position) but write access is restricted — either via private(set) which limits
66+
* writes to the declaring class, or via a get-only hook with no set hook.
67+
* Since the write side is not part of the public API, only the read (covariant)
68+
* position matters, same as readonly.
69+
*
70+
* There is no need for a symmetric private(get) check because PHP 8.4's asymmetric
71+
* visibility only allows restricting set visibility — the set visibility must be
72+
* equal to or more restrictive than the read visibility, so private(get) does not exist.
73+
*/
5974
private function hasRestrictedWriteAccess(ClassPropertyNode $node): bool
6075
{
6176
if ($node->isPrivateSet()) {

0 commit comments

Comments
 (0)