1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Add support for callable checks

This commit is contained in:
Matthew Brown 2016-08-31 15:10:11 -04:00
parent bad1271744
commit 330199c9a3

View File

@ -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
*