From 1589b2a01e865a026328cc85a38264d478d5d7bf Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Fri, 13 Jul 2018 18:36:25 -0400 Subject: [PATCH] Fix #269 - allow trigger_error to count as exit statement --- src/Psalm/Checker/ScopeChecker.php | 13 +++++++++++++ tests/FunctionCallTest.php | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/Psalm/Checker/ScopeChecker.php b/src/Psalm/Checker/ScopeChecker.php index 5854f4d4d..574727d49 100644 --- a/src/Psalm/Checker/ScopeChecker.php +++ b/src/Psalm/Checker/ScopeChecker.php @@ -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 diff --git a/tests/FunctionCallTest.php b/tests/FunctionCallTest.php index 2884bf0f4..69b06cb61 100644 --- a/tests/FunctionCallTest.php +++ b/tests/FunctionCallTest.php @@ -884,6 +884,16 @@ class FunctionCallTest extends TestCase return ""; }', ], + 'triggerUserError' => [ + '