Skip to content

Commit

Permalink
Use more descriptive names for properties & variables of if/else hand…
Browse files Browse the repository at this point in the history
…ling
  • Loading branch information
muglug committed Apr 18, 2021
1 parent ee778e9 commit 0acc02e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function (Clause $c) use ($changed_var_ids): bool {

// 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
Expand Down Expand Up @@ -275,7 +275,7 @@ function (Type\Union $_): bool {

return new \Psalm\Internal\Scope\IfConditionalScope(
$if_context,
$original_context,
$post_if_context,
$cond_referenced_var_ids,
$assigned_in_conditional_var_ids,
$entry_clauses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,12 @@ private static function handleMicDrop(
) : 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
);
Expand Down Expand Up @@ -340,7 +340,7 @@ private static function handleMicDrop(
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 {
Expand Down Expand Up @@ -381,15 +381,15 @@ public static function addConditionallyAssignedVarsToContext(
$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();
Expand All @@ -398,8 +398,8 @@ public static function addConditionallyAssignedVarsToContext(
$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];
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public static function analyze(
|| (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;
}
}

Expand All @@ -100,7 +100,7 @@ public static function analyze(

$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) {
Expand Down Expand Up @@ -319,7 +319,7 @@ function (array $carry, Clause $clause): array {
$context->referenced_var_ids
);

$temp_else_context = clone $original_context;
$temp_else_context = clone $post_if_context;

$changed_var_ids = [];

Expand Down Expand Up @@ -368,7 +368,7 @@ function (array $carry, Clause $clause): array {
}

// check the else
$else_context = clone $original_context;
$else_context = clone $post_if_context;

// check the elseifs
foreach ($stmt->elseifs as $elseif) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static function analyze(

$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
Expand All @@ -77,7 +77,7 @@ public static function analyze(
$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;
Expand All @@ -88,7 +88,7 @@ public static function analyze(

$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;
Expand Down Expand Up @@ -193,12 +193,12 @@ function ($c) use ($reconciled_expression_clauses): bool {

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
);
Expand Down
6 changes: 3 additions & 3 deletions src/Psalm/Internal/Scope/IfConditionalScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class IfConditionalScope
{
public $if_context;

public $original_context;
public $post_if_context;

/**
* @var array<string, bool>
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Scope/IfScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,5 @@ class IfScope
/**
* @var ?\Psalm\Context
*/
public $mic_drop_context;
public $post_leaving_if_context;
}

0 comments on commit 0acc02e

Please sign in to comment.