1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Search in while & try/catch

This commit is contained in:
Matthew Brown 2016-06-20 18:10:24 -04:00
parent 2b8c95a19d
commit 162a8a2c2b

View File

@ -24,6 +24,7 @@ class ScopeChecker
if ($stmt instanceof PhpParser\Node\Stmt\Return_ ||
$stmt instanceof PhpParser\Node\Stmt\Throw_ ||
$stmt instanceof PhpParser\Node\Expr\Exit_ ||
($check_continue && $stmt instanceof PhpParser\Node\Stmt\Continue_) ||
($check_break && $stmt instanceof PhpParser\Node\Stmt\Break_)) {
@ -131,7 +132,10 @@ class ScopeChecker
for ($i = count($stmts) - 1; $i >= 0; $i--) {
$stmt = $stmts[$i];
if ($stmt instanceof PhpParser\Node\Stmt\Return_ || $stmt instanceof PhpParser\Node\Stmt\Throw_) {
if ($stmt instanceof PhpParser\Node\Stmt\Return_ ||
$stmt instanceof PhpParser\Node\Stmt\Throw_ ||
$stmt instanceof PhpParser\Node\Expr\Exit_
) {
return true;
}
@ -176,6 +180,24 @@ class ScopeChecker
return true;
}
if ($stmt instanceof PhpParser\Node\Stmt\While_) {
if (self::doesReturnOrThrow($stmt->stmts)) {
return true;
}
}
if ($stmt instanceof PhpParser\Node\Stmt\TryCatch) {
if (self::doesReturnOrThrow($stmt->stmts)) {
foreach ($stmt->catches as $catch) {
if (!self::doesReturnOrThrow($catch->stmts)) {
return false;
}
}
return true;
}
}
if ($stmt instanceof PhpParser\Node\Stmt\Nop) {
continue;
}