Skip to content

Commit d522fdb

Browse files
committed
Fix "Property is never read, only written" false positive, when initialized by ref with static property
1 parent 39ed1e5 commit d522fdb

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

‎tests/PHPStan/Rules/DeadCode/UnusedPrivatePropertyRuleTest.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,4 +533,12 @@ public function testBug15886Promoted(): void
533533
$this->analyse([__DIR__ . '/data/bug-15886-promoted.php'], []);
534534
}
535535

536+
public function testBug15886Static(): void
537+
{
538+
$this->alwaysWrittenTags = [];
539+
$this->alwaysReadTags = [];
540+
541+
$this->analyse([__DIR__ . '/data/bug-15886-static.php'], []);
542+
}
543+
536544
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug15886Static;
4+
5+
class Foo
6+
{
7+
8+
/**
9+
* @var list<string>
10+
*/
11+
private static array $forwarded = [];
12+
13+
/**
14+
* @param list<string> $forwarded
15+
*/
16+
public static function init(array &$forwarded): void
17+
{
18+
self::$forwarded = &$forwarded;
19+
}
20+
21+
public static function notify(): void
22+
{
23+
self::$forwarded[] = 'suite finished';
24+
}
25+
26+
}
27+
28+
class Bar
29+
{
30+
31+
/**
32+
* @var list<string>
33+
*/
34+
private static array $forwarded = [];
35+
36+
/**
37+
* @param list<string> $forwarded
38+
*/
39+
public static function init(array &$forwarded): void
40+
{
41+
static::$forwarded = &$forwarded;
42+
}
43+
44+
public static function notify(): void
45+
{
46+
static::$forwarded[] = 'suite finished';
47+
}
48+
49+
}

0 commit comments

Comments
 (0)