1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Fix #269 - allow trigger_error to count as exit statement

This commit is contained in:
Matthew Brown 2018-07-13 18:36:25 -04:00
parent c1e21fcf5d
commit 1589b2a01e
2 changed files with 23 additions and 0 deletions

View File

@ -84,6 +84,19 @@ class ScopeChecker
}
if ($stmt instanceof PhpParser\Node\Stmt\Expression) {
if ($stmt->expr instanceof PhpParser\Node\Expr\FuncCall
&& $stmt->expr->name instanceof PhpParser\Node\Name
&& $stmt->expr->name->parts === ['trigger_error']
&& isset($stmt->expr->args[1])
&& $stmt->expr->args[1]->value instanceof PhpParser\Node\Expr\ConstFetch
&& in_array(
end($stmt->expr->args[1]->value->name->parts),
['E_ERROR', 'E_PARSE', 'E_CORE_ERROR', 'E_COMPILE_ERROR', 'E_USER_ERROR']
)
) {
return [self::ACTION_END];
}
if ($exit_functions) {
if ($stmt->expr instanceof PhpParser\Node\Expr\FuncCall
|| $stmt->expr instanceof PhpParser\Node\Expr\StaticCall

View File

@ -884,6 +884,16 @@ class FunctionCallTest extends TestCase
return "";
}',
],
'triggerUserError' => [
'<?php
function mightLeave() : string {
if (rand(0, 1)) {
trigger_error("bad", E_USER_ERROR);
} else {
return "here";
}
}',
],
];
}