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

Allow assertions on mixed vars

This commit is contained in:
Matthew Brown 2018-01-08 00:14:02 -05:00
parent 8e4f8fabe3
commit 8ababf1537
2 changed files with 4 additions and 9 deletions

View File

@ -28,15 +28,10 @@ class FunctionChecker extends FunctionLikeChecker
public static $stubbed_functions = [];
/**
* @param mixed $function
* @param StatementsSource $source
*/
public function __construct($function, StatementsSource $source)
public function __construct(PhpParser\Node\Stmt\Function_ $function, StatementsSource $source)
{
if (!$function instanceof PhpParser\Node\Stmt\Function_) {
throw new \InvalidArgumentException('Bad');
}
parent::__construct($function, $source);
}
@ -370,7 +365,7 @@ class FunctionChecker extends FunctionLikeChecker
return new Type\Union([new Type\Atomic\TString, new Type\Atomic\TFalse]);
}
return new Type\Union([new Type\Atomic\TArray([new Type\Atomic\TMixed, new Type\Atomic\TString])]);
return new Type\Union([new Type\Atomic\TArray([Type::getMixed(), Type::getString()])]);
}
if ($call_args) {

View File

@ -162,7 +162,7 @@ class IfChecker
foreach ($keys as $key) {
foreach ($mixed_var_ids as $mixed_var_id) {
if (preg_match('/^' . preg_quote($mixed_var_id) . '(\[|-|$)/', $key)) {
if (preg_match('/^' . preg_quote($mixed_var_id) . '(\[|-)/', $key)) {
return false;
}
}
@ -702,7 +702,7 @@ class IfChecker
foreach ($keys as $key) {
foreach ($mixed_var_ids as $mixed_var_id) {
if (preg_match('/^' . preg_quote($mixed_var_id) . '(\[|-|$)/', $key)) {
if (preg_match('/^' . preg_quote($mixed_var_id) . '(\[|-)/', $key)) {
return false;
}
}