Skip to content

Commit

Permalink
Property is also read for ??= and other assign ops
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Aug 12, 2020
1 parent 19fab3f commit efb11ec
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,10 @@ private function processStmtNode(
if (!$node instanceof Expr) {
return;
}
if ($node instanceof Expr\AssignOp) {
$customCallback($node->var, $scope);
return;
}
if ($node instanceof Node\Scalar\EncapsedStringPart) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,11 @@ public function testTrait(): void
$this->analyse([__DIR__ . '/data/private-property-trait.php'], []);
}

public function testBug3636(): void
{
$this->alwaysWrittenTags = [];
$this->alwaysReadTags = [];
$this->analyse([__DIR__ . '/data/bug-3636.php'], []);
}

}
16 changes: 16 additions & 0 deletions tests/PHPStan/Rules/DeadCode/data/bug-3636.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Bug3636;

class Foo
{

/** @var \DateTimeImmutable */
private $date;

public function getDate(): \DateTimeImmutable
{
return $this->date ??= new \DateTimeImmutable();
}

}

0 comments on commit efb11ec

Please sign in to comment.