Skip to content
Permalink
Browse files

Add check for only simplest conditionals

  • Loading branch information
muglug committed Jan 4, 2020
1 parent 8cbc26c commit 37fb15250cd9400c41cebdd57cce9ceb1cd4ecc3
Showing with 5 additions and 3 deletions.
  1. +5 −3 src/Psalm/Internal/Analyzer/Statements/Block/ForAnalyzer.php
@@ -41,7 +41,7 @@ public static function analyze(

if ($init instanceof PhpParser\Node\Expr\Assign
&& $init->var instanceof PhpParser\Node\Expr\Variable
&& is_string($init->var->name)
&& \is_string($init->var->name)
&& ($init_var_type = $statements_analyzer->node_data->getType($init->expr))
) {
$init_var_types[$init->var->name] = $init_var_type;
@@ -105,10 +105,12 @@ public static function analyze(
}
}

if ($cond instanceof PhpParser\Node\Expr\BinaryOp
if (count($stmt->init) === 1
&& count($stmt->cond) === 1
&& $cond instanceof PhpParser\Node\Expr\BinaryOp
&& $cond->right instanceof PhpParser\Node\Scalar\LNumber
&& $cond->left instanceof PhpParser\Node\Expr\Variable
&& is_string($cond->left->name)
&& \is_string($cond->left->name)
&& isset($init_var_types[$cond->left->name])
&& $init_var_types[$cond->left->name]->isSingleIntLiteral()
) {

0 comments on commit 37fb152

Please sign in to comment.
You can’t perform that action at this time.