mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
every condition must be true
This commit is contained in:
parent
85668ed255
commit
d5eb471688
@ -362,17 +362,27 @@ class ScopeAnalyzer
|
||||
|
||||
if ($stmt instanceof PhpParser\Node\Stmt\For_
|
||||
&& $nodes
|
||||
&& (!$stmt->cond ||
|
||||
(($stmt_expr_type = $nodes->getType($stmt->cond)) && $stmt_expr_type->isAlwaysTruthy()))
|
||||
) {
|
||||
//infinite while loop that only return don't have an exit path
|
||||
$have_exit_path = (bool)array_diff(
|
||||
$control_actions,
|
||||
[self::ACTION_END, self::ACTION_RETURN]
|
||||
);
|
||||
$is_infinite_loop = true;
|
||||
if ($stmt->cond) {
|
||||
foreach ($stmt->cond as $cond) {
|
||||
$stmt_expr_type = $nodes->getType($cond);
|
||||
if (!$stmt_expr_type || !$stmt_expr_type->isAlwaysTruthy()) {
|
||||
$is_infinite_loop = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$have_exit_path) {
|
||||
return array_values(array_unique($control_actions));
|
||||
if ($is_infinite_loop) {
|
||||
//infinite while loop that only return don't have an exit path
|
||||
$have_exit_path = (bool)array_diff(
|
||||
$control_actions,
|
||||
[self::ACTION_END, self::ACTION_RETURN]
|
||||
);
|
||||
|
||||
if (!$have_exit_path) {
|
||||
return array_values(array_unique($control_actions));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user