Skip to content

Commit c659f35

Browse files
committed
Property tag @property-write with private property keeps the property non-readable
1 parent d3c6b62 commit c659f35

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

tests/PHPStan/Rules/Properties/ReadingWriteOnlyPropertiesRuleTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,15 @@ public function testPropertyHooks(): void
105105
]);
106106
}
107107

108+
public function testPrivatePropertyTagWrite(): void
109+
{
110+
$this->checkThisOnly = false;
111+
$this->analyse([__DIR__ . '/data/private-property-tag-write.php'], [
112+
[
113+
'Property PrivatePropertyTagWrite\Foo::$foo is not readable.',
114+
22,
115+
],
116+
]);
117+
}
118+
108119
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace PrivatePropertyTagWrite;
4+
5+
use AllowDynamicProperties;
6+
7+
/**
8+
* @property-write int $foo
9+
* @property-write int $bar
10+
*/
11+
#[AllowDynamicProperties]
12+
class Foo
13+
{
14+
15+
private int $foo;
16+
17+
public int $bar;
18+
19+
}
20+
21+
function (Foo $foo): void {
22+
echo $foo->foo;
23+
echo $foo->bar;
24+
};

0 commit comments

Comments
 (0)