mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix #269 - allow trigger_error to count as exit statement
This commit is contained in:
parent
c1e21fcf5d
commit
1589b2a01e
@ -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
|
||||
|
@ -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";
|
||||
}
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user