Skip to content

Commit 82673cd

Browse files
committed
Continue analyzing classes and functions after exit
1 parent d136a9f commit 82673cd

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,10 @@ public function processStmtNodes(
339339
|| $parentNode instanceof Node\Stmt\ClassMethod
340340
|| $parentNode instanceof Expr\Closure;
341341
foreach ($stmts as $i => $stmt) {
342+
if ($alreadyTerminated && !($stmt instanceof Node\Stmt\Function_ || $stmt instanceof Node\Stmt\ClassLike)) {
343+
continue;
344+
}
345+
342346
$isLast = $i === $stmtCount - 1;
343347
$statementResult = $this->processStmtNode(
344348
$stmt,
@@ -370,16 +374,16 @@ public function processStmtNodes(
370374
$throwPoints = array_merge($throwPoints, $statementResult->getThrowPoints());
371375
$impurePoints = array_merge($impurePoints, $statementResult->getImpurePoints());
372376

373-
if (!$statementResult->isAlwaysTerminating()) {
377+
if ($alreadyTerminated || !$statementResult->isAlwaysTerminating()) {
374378
continue;
375379
}
376380

377381
$alreadyTerminated = true;
378382
$nextStmt = $this->getFirstUnreachableNode(array_slice($stmts, $i + 1), $parentNode instanceof Node\Stmt\Namespace_);
379-
if ($nextStmt !== null) {
380-
$nodeCallback(new UnreachableStatementNode($nextStmt), $scope);
383+
if ($nextStmt === null) {
384+
continue;
381385
}
382-
break;
386+
$nodeCallback(new UnreachableStatementNode($nextStmt), $scope);
383387
}
384388

385389
$statementResult = new StatementResult($scope, $hasYield, $alreadyTerminated, $exitPoints, $throwPoints, $impurePoints);

tests/PHPStan/Rules/Debug/DumpTypeRuleTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,14 @@ public function testBug10377(): void
8282
]);
8383
}
8484

85+
public function testBug11179(): void
86+
{
87+
$this->analyse([__DIR__ . '/../DeadCode/data/bug-11179.php'], [
88+
[
89+
'Dumped type: string',
90+
9,
91+
],
92+
]);
93+
}
94+
8595
}

0 commit comments

Comments
 (0)