mirror of
https://github.com/danog/psalm.git
synced 2024-11-27 04:45:20 +01:00
Use more descriptive names for properties & variables of if/else handling
This commit is contained in:
parent
ee778e9246
commit
0acc02e184
@ -149,7 +149,7 @@ class IfConditionalAnalyzer
|
||||
|
||||
// we need to clone the current context so our ongoing updates
|
||||
// to $outer_context don't mess with elseif/else blocks
|
||||
$original_context = clone $outer_context;
|
||||
$post_if_context = clone $outer_context;
|
||||
|
||||
if ($internally_applied_if_cond_expr !== $cond
|
||||
|| $externally_applied_if_cond_expr !== $cond
|
||||
@ -275,7 +275,7 @@ class IfConditionalAnalyzer
|
||||
|
||||
return new \Psalm\Internal\Scope\IfConditionalScope(
|
||||
$if_context,
|
||||
$original_context,
|
||||
$post_if_context,
|
||||
$cond_referenced_var_ids,
|
||||
$assigned_in_conditional_var_ids,
|
||||
$entry_clauses
|
||||
|
@ -252,12 +252,12 @@ class IfAnalyzer
|
||||
) : bool {
|
||||
// If we're assigning inside
|
||||
if ($if_conditional_scope->assigned_in_conditional_var_ids
|
||||
&& $if_scope->mic_drop_context
|
||||
&& $if_scope->post_leaving_if_context
|
||||
) {
|
||||
self::addConditionallyAssignedVarsToContext(
|
||||
$statements_analyzer,
|
||||
$cond,
|
||||
$if_scope->mic_drop_context,
|
||||
$if_scope->post_leaving_if_context,
|
||||
$outer_context,
|
||||
$if_conditional_scope->assigned_in_conditional_var_ids
|
||||
);
|
||||
@ -340,7 +340,7 @@ class IfAnalyzer
|
||||
public static function addConditionallyAssignedVarsToContext(
|
||||
StatementsAnalyzer $statements_analyzer,
|
||||
PhpParser\Node\Expr $cond,
|
||||
Context $mic_drop_context,
|
||||
Context $post_leaving_if_context,
|
||||
Context $outer_context,
|
||||
array $assigned_in_conditional_var_ids
|
||||
) : void {
|
||||
@ -381,15 +381,15 @@ class IfAnalyzer
|
||||
$expr->getAttributes()
|
||||
);
|
||||
|
||||
$mic_drop_context->inside_negation = !$mic_drop_context->inside_negation;
|
||||
$post_leaving_if_context->inside_negation = !$post_leaving_if_context->inside_negation;
|
||||
|
||||
ExpressionAnalyzer::analyze(
|
||||
$statements_analyzer,
|
||||
$fake_negated_expr,
|
||||
$mic_drop_context
|
||||
$post_leaving_if_context
|
||||
);
|
||||
|
||||
$mic_drop_context->inside_negation = !$mic_drop_context->inside_negation;
|
||||
$post_leaving_if_context->inside_negation = !$post_leaving_if_context->inside_negation;
|
||||
}
|
||||
|
||||
IssueBuffer::clearRecordingLevel();
|
||||
@ -398,8 +398,8 @@ class IfAnalyzer
|
||||
$statements_analyzer->node_data = $old_node_data;
|
||||
|
||||
foreach ($assigned_in_conditional_var_ids as $var_id => $_) {
|
||||
if (isset($mic_drop_context->vars_in_scope[$var_id])) {
|
||||
$outer_context->vars_in_scope[$var_id] = clone $mic_drop_context->vars_in_scope[$var_id];
|
||||
if (isset($post_leaving_if_context->vars_in_scope[$var_id])) {
|
||||
$outer_context->vars_in_scope[$var_id] = clone $post_leaving_if_context->vars_in_scope[$var_id];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ class IfElseAnalyzer
|
||||
|| (count($final_actions) && !in_array(ScopeAnalyzer::ACTION_NONE, $final_actions, true));
|
||||
|
||||
if ($has_leaving_statements) {
|
||||
$if_scope->mic_drop_context = clone $context;
|
||||
$if_scope->post_leaving_if_context = clone $context;
|
||||
}
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ class IfElseAnalyzer
|
||||
|
||||
$if_context = $if_conditional_scope->if_context;
|
||||
|
||||
$original_context = $if_conditional_scope->original_context;
|
||||
$post_if_context = $if_conditional_scope->post_if_context;
|
||||
$cond_referenced_var_ids = $if_conditional_scope->cond_referenced_var_ids;
|
||||
$assigned_in_conditional_var_ids = $if_conditional_scope->assigned_in_conditional_var_ids;
|
||||
} catch (\Psalm\Exception\ScopeAnalysisException $e) {
|
||||
@ -319,7 +319,7 @@ class IfElseAnalyzer
|
||||
$context->referenced_var_ids
|
||||
);
|
||||
|
||||
$temp_else_context = clone $original_context;
|
||||
$temp_else_context = clone $post_if_context;
|
||||
|
||||
$changed_var_ids = [];
|
||||
|
||||
@ -368,7 +368,7 @@ class IfElseAnalyzer
|
||||
}
|
||||
|
||||
// check the else
|
||||
$else_context = clone $original_context;
|
||||
$else_context = clone $post_if_context;
|
||||
|
||||
// check the elseifs
|
||||
foreach ($stmt->elseifs as $elseif) {
|
||||
|
@ -53,7 +53,7 @@ class OrAnalyzer
|
||||
|
||||
$codebase = $statements_analyzer->getCodebase();
|
||||
|
||||
$mic_drop_context = null;
|
||||
$post_leaving_if_context = null;
|
||||
|
||||
if (!$stmt->left instanceof PhpParser\Node\Expr\BinaryOp\BooleanOr
|
||||
|| !$stmt->left->left instanceof PhpParser\Node\Expr\BinaryOp\BooleanOr
|
||||
@ -77,7 +77,7 @@ class OrAnalyzer
|
||||
$left_assigned_var_ids = $if_conditional_scope->assigned_in_conditional_var_ids;
|
||||
|
||||
if ($stmt->left instanceof PhpParser\Node\Expr\BinaryOp\BooleanOr) {
|
||||
$mic_drop_context = clone $context;
|
||||
$post_leaving_if_context = clone $context;
|
||||
}
|
||||
} catch (\Psalm\Exception\ScopeAnalysisException $e) {
|
||||
return false;
|
||||
@ -88,7 +88,7 @@ class OrAnalyzer
|
||||
|
||||
$pre_assigned_var_ids = $context->assigned_var_ids;
|
||||
|
||||
$mic_drop_context = clone $context;
|
||||
$post_leaving_if_context = clone $context;
|
||||
|
||||
$left_context = clone $context;
|
||||
$left_context->parent_context = $context;
|
||||
@ -193,12 +193,12 @@ class OrAnalyzer
|
||||
|
||||
if ($stmt->left instanceof PhpParser\Node\Expr\BinaryOp\BooleanOr
|
||||
&& $left_assigned_var_ids
|
||||
&& $mic_drop_context
|
||||
&& $post_leaving_if_context
|
||||
) {
|
||||
IfAnalyzer::addConditionallyAssignedVarsToContext(
|
||||
$statements_analyzer,
|
||||
$stmt->left,
|
||||
$mic_drop_context,
|
||||
$post_leaving_if_context,
|
||||
$right_context,
|
||||
$left_assigned_var_ids
|
||||
);
|
||||
|
@ -10,7 +10,7 @@ class IfConditionalScope
|
||||
{
|
||||
public $if_context;
|
||||
|
||||
public $original_context;
|
||||
public $post_if_context;
|
||||
|
||||
/**
|
||||
* @var array<string, bool>
|
||||
@ -32,13 +32,13 @@ class IfConditionalScope
|
||||
*/
|
||||
public function __construct(
|
||||
Context $if_context,
|
||||
Context $original_context,
|
||||
Context $post_if_context,
|
||||
array $cond_referenced_var_ids,
|
||||
array $assigned_in_conditional_var_ids,
|
||||
array $entry_clauses
|
||||
) {
|
||||
$this->if_context = $if_context;
|
||||
$this->original_context = $original_context;
|
||||
$this->post_if_context = $post_if_context;
|
||||
$this->cond_referenced_var_ids = $cond_referenced_var_ids;
|
||||
$this->assigned_in_conditional_var_ids = $assigned_in_conditional_var_ids;
|
||||
$this->entry_clauses = $entry_clauses;
|
||||
|
@ -88,5 +88,5 @@ class IfScope
|
||||
/**
|
||||
* @var ?\Psalm\Context
|
||||
*/
|
||||
public $mic_drop_context;
|
||||
public $post_leaving_if_context;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user