Skip to content

Commit

Permalink
Process do-while loop condition even if the loop always terminates
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Sep 20, 2021
1 parent 11c888c commit 0837be4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Analyser/NodeScopeResolver.php
Expand Up @@ -983,6 +983,8 @@ private function processStmtNode(
$hasYield = $condResult->hasYield();
$throwPoints = $condResult->getThrowPoints();
$finalScope = $condResult->getFalseyScope();
} else {
$this->processExprNode($stmt->cond, $bodyScope, $nodeCallback, ExpressionContext::createDeep());
}
foreach ($bodyScopeResult->getExitPointsByType(Break_::class) as $breakExitPoint) {
$finalScope = $breakExitPoint->getScope()->mergeWith($finalScope);
Expand Down
22 changes: 22 additions & 0 deletions tests/PHPStan/Rules/DeadCode/data/unused-private-constant.php
Expand Up @@ -22,3 +22,25 @@ class TestExtension

private const UNUSED = 2;
}


final class P
{

private const JSON_OBJECT_START = 17;
private const JSON_OBJECT_END = 18;

public function ignoreObjectBlock(): void
{
do {
$code = doFoo();

// recursively ignore nested objects
if ($code !== self::JSON_OBJECT_START) {
continue;
}

$this->ignoreObjectBlock();
} while ($code !== self::JSON_OBJECT_END);
}
}

0 comments on commit 0837be4

Please sign in to comment.