Skip to content

Commit e64b6d0

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

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

src/Analyser/NodeScopeResolver.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,24 +292,28 @@ public function processNodes(
292292
callable $nodeCallback,
293293
): void
294294
{
295+
$alreadyTerminated = false;
295296
foreach ($nodes as $i => $node) {
296-
if (!$node instanceof Node\Stmt) {
297+
if (
298+
!$node instanceof Node\Stmt
299+
|| ($alreadyTerminated && !($node instanceof Node\Stmt\Function_ || $node instanceof Node\Stmt\ClassLike))
300+
) {
297301
continue;
298302
}
299303

300304
$statementResult = $this->processStmtNode($node, $scope, $nodeCallback, StatementContext::createTopLevel());
301305
$scope = $statementResult->getScope();
302-
if (!$statementResult->isAlwaysTerminating()) {
306+
if ($alreadyTerminated || !$statementResult->isAlwaysTerminating()) {
303307
continue;
304308
}
305309

310+
$alreadyTerminated = true;
306311
$nextStmt = $this->getFirstUnreachableNode(array_slice($nodes, $i + 1), true);
307312
if (!$nextStmt instanceof Node\Stmt) {
308313
continue;
309314
}
310315

311316
$nodeCallback(new UnreachableStatementNode($nextStmt), $scope);
312-
break;
313317
}
314318
}
315319

tests/PHPStan/Rules/Debug/DumpTypeRuleTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,14 @@ public function testBug11179(): void
9292
]);
9393
}
9494

95+
public function testBug11179NoNamespace(): void
96+
{
97+
$this->analyse([__DIR__ . '/data/bug-11179-no-namespace.php'], [
98+
[
99+
'Dumped type: string',
100+
11,
101+
],
102+
]);
103+
}
104+
95105
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php declare(strict_types = 1);
2+
3+
// no namespace
4+
5+
exit(0);
6+
7+
echo 1;
8+
9+
function bug11179Foo(string $p): string
10+
{
11+
\PHPStan\dumpType($p);
12+
return "";
13+
}

0 commit comments

Comments
 (0)