Skip to content

Commit 9b19a6f

Browse files
committed
UnusedPrivatePropertyRule - read PHPDocs for promoted properties
1 parent 4b7b27d commit 9b19a6f

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,12 +467,16 @@ private function processStmtNode(
467467
if (!$param->var instanceof Variable || !is_string($param->var->name)) {
468468
throw new \PHPStan\ShouldNotHappenException();
469469
}
470+
$phpDoc = null;
471+
if ($param->getDocComment() !== null) {
472+
$phpDoc = $param->getDocComment()->getText();
473+
}
470474
$nodeCallback(new ClassPropertyNode(
471475
$param->var->name,
472476
$param->flags,
473477
$param->type,
474478
$param->default,
475-
null, // todo
479+
$phpDoc,
476480
true,
477481
$param
478482
), $methodScope);

tests/PHPStan/Rules/DeadCode/UnusedPrivatePropertyRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function testPromotedProperties(): void
162162
}
163163

164164
$this->alwaysWrittenTags = [];
165-
$this->alwaysReadTags = [];
165+
$this->alwaysReadTags = ['@get'];
166166
$this->analyse([__DIR__ . '/data/unused-private-promoted-property.php'], [
167167
[
168168
'Property UnusedPrivatePromotedProperty\Foo::$lorem is never read, only written.',

tests/PHPStan/Rules/DeadCode/data/unused-private-promoted-property.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ public function __construct(
99
public $foo,
1010
protected $bar,
1111
private $baz,
12-
private $lorem
12+
private $lorem,
13+
/** @get */ private $ipsum
1314
) { }
1415

1516
public function getBaz()

0 commit comments

Comments
 (0)