mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 22:01:48 +01:00
Don’t forget control actions
This commit is contained in:
parent
0856354b48
commit
81626eee0f
@ -9,6 +9,7 @@ use function strtolower;
|
|||||||
use function array_merge;
|
use function array_merge;
|
||||||
use function array_intersect;
|
use function array_intersect;
|
||||||
use function array_unique;
|
use function array_unique;
|
||||||
|
use function array_filter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
@ -96,7 +97,7 @@ class ScopeAnalyzer
|
|||||||
($stmt instanceof PhpParser\Node\Stmt\Expression && $stmt->expr instanceof PhpParser\Node\Expr\Exit_)
|
($stmt instanceof PhpParser\Node\Stmt\Expression && $stmt->expr instanceof PhpParser\Node\Expr\Exit_)
|
||||||
) {
|
) {
|
||||||
if (!$return_is_exit && $stmt instanceof PhpParser\Node\Stmt\Return_) {
|
if (!$return_is_exit && $stmt instanceof PhpParser\Node\Stmt\Return_) {
|
||||||
return [self::ACTION_RETURN];
|
return array_merge($control_actions, [self::ACTION_RETURN]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [self::ACTION_END];
|
return [self::ACTION_END];
|
||||||
@ -158,10 +159,10 @@ class ScopeAnalyzer
|
|||||||
&& end($break_types) === 'switch'
|
&& end($break_types) === 'switch'
|
||||||
&& (!$stmt->num || !$stmt->num instanceof PhpParser\Node\Scalar\LNumber || $stmt->num->value < 2)
|
&& (!$stmt->num || !$stmt->num instanceof PhpParser\Node\Scalar\LNumber || $stmt->num->value < 2)
|
||||||
) {
|
) {
|
||||||
return [self::ACTION_LEAVE_SWITCH];
|
return array_merge($control_actions, [self::ACTION_LEAVE_SWITCH]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [self::ACTION_CONTINUE];
|
return array_unique(array_merge($control_actions, [self::ACTION_CONTINUE]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($stmt instanceof PhpParser\Node\Stmt\Break_) {
|
if ($stmt instanceof PhpParser\Node\Stmt\Break_) {
|
||||||
@ -172,7 +173,7 @@ class ScopeAnalyzer
|
|||||||
return [self::ACTION_LEAVE_SWITCH];
|
return [self::ACTION_LEAVE_SWITCH];
|
||||||
}
|
}
|
||||||
|
|
||||||
return [self::ACTION_BREAK];
|
return array_unique(array_merge($control_actions, [self::ACTION_BREAK]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($stmt instanceof PhpParser\Node\Stmt\If_) {
|
if ($stmt instanceof PhpParser\Node\Stmt\If_) {
|
||||||
@ -214,11 +215,16 @@ class ScopeAnalyzer
|
|||||||
return $if_statement_actions;
|
return $if_statement_actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
$control_actions = array_merge(
|
$control_actions = array_filter(
|
||||||
$control_actions,
|
array_merge(
|
||||||
$if_statement_actions,
|
$control_actions,
|
||||||
$else_statement_actions,
|
$if_statement_actions,
|
||||||
$all_elseif_actions
|
$else_statement_actions,
|
||||||
|
$all_elseif_actions
|
||||||
|
),
|
||||||
|
function ($action) {
|
||||||
|
return $action !== self::ACTION_NONE;
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -262,7 +268,7 @@ class ScopeAnalyzer
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($has_default_terminator || isset($stmt->allMatched)) {
|
if ($has_default_terminator || isset($stmt->allMatched)) {
|
||||||
return [self::ACTION_END];
|
return array_merge($control_actions, [self::ACTION_END]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,7 +284,12 @@ class ScopeAnalyzer
|
|||||||
array_merge($break_types, ['loop'])
|
array_merge($break_types, ['loop'])
|
||||||
);
|
);
|
||||||
|
|
||||||
$control_actions = array_merge($control_actions, $do_actions);
|
$control_actions = array_filter(
|
||||||
|
array_merge($control_actions, $do_actions),
|
||||||
|
function ($action) {
|
||||||
|
return $action !== self::ACTION_NONE;
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($stmt instanceof PhpParser\Node\Stmt\TryCatch) {
|
if ($stmt instanceof PhpParser\Node\Stmt\TryCatch) {
|
||||||
@ -322,16 +333,37 @@ class ScopeAnalyzer
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!in_array(self::ACTION_NONE, $finally_statement_actions, true)) {
|
if (!in_array(self::ACTION_NONE, $finally_statement_actions, true)) {
|
||||||
return $finally_statement_actions;
|
return array_merge(
|
||||||
|
array_filter(
|
||||||
|
$control_actions,
|
||||||
|
function ($action) {
|
||||||
|
return $action !== self::ACTION_NONE;
|
||||||
|
}
|
||||||
|
),
|
||||||
|
$finally_statement_actions
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$stmt->catches && !in_array(self::ACTION_NONE, $try_statement_actions, true)) {
|
if (!$stmt->catches && !in_array(self::ACTION_NONE, $try_statement_actions, true)) {
|
||||||
return $try_statement_actions;
|
return array_merge(
|
||||||
|
array_filter(
|
||||||
|
$control_actions,
|
||||||
|
function ($action) {
|
||||||
|
return $action !== self::ACTION_NONE;
|
||||||
|
}
|
||||||
|
),
|
||||||
|
$try_statement_actions
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$control_actions = \array_merge($control_actions, $try_statement_actions);
|
$control_actions = array_filter(
|
||||||
|
\array_merge($control_actions, $try_statement_actions),
|
||||||
|
function ($action) {
|
||||||
|
return $action !== self::ACTION_NONE;
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user