From 330199c9a3fd9de5e1f27f8d0f2fbb4f46ffb790 Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Wed, 31 Aug 2016 15:10:11 -0400 Subject: [PATCH] Add support for callable checks --- src/Psalm/Checker/TypeChecker.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Psalm/Checker/TypeChecker.php b/src/Psalm/Checker/TypeChecker.php index 8d5af5cc1..0e2c69b9e 100644 --- a/src/Psalm/Checker/TypeChecker.php +++ b/src/Psalm/Checker/TypeChecker.php @@ -318,6 +318,12 @@ class TypeChecker $if_types[$var_name] = '!scalar'; } } + else if (self::hasCallableCheck($conditional->expr)) { + $var_name = StatementsChecker::getVarId($conditional->expr->args[0]->value); + if ($var_name) { + $if_types[$var_name] = '!callable'; + } + } } else if ($conditional->expr instanceof PhpParser\Node\Expr\Isset_) { foreach ($conditional->expr->vars as $isset_var) { @@ -485,6 +491,12 @@ class TypeChecker $if_types[$var_name] = 'scalar'; } } + else if (self::hasCallableCheck($conditional)) { + $var_name = StatementsChecker::getVarId($conditional->args[0]->value); + if ($var_name) { + $if_types[$var_name] = 'callable'; + } + } } else if ($conditional instanceof PhpParser\Node\Expr\Empty_) { $var_name = StatementsChecker::getVarId($conditional->expr); @@ -686,6 +698,18 @@ class TypeChecker return false; } + /** + * @return bool + */ + protected static function hasCallableCheck(PhpParser\Node\Expr\FuncCall $stmt) + { + if ($stmt->name instanceof PhpParser\Node\Name && $stmt->name->parts === ['is_callable']) { + return true; + } + + return false; + } + /** * Takes two arrays and consolidates them, removing null values from existing types where applicable *