Skip to content

Commit

Permalink
Remove more unused code
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Feb 8, 2022
1 parent 48b702b commit 9d8b6d6
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions src/Psalm/Internal/Analyzer/Statements/Block/LoopAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
use function array_unique;
use function in_array;
use function spl_object_id;
use function strpos;

/**
* @internal
Expand Down Expand Up @@ -152,14 +151,12 @@ public static function analyze(
$loop_parent_context->vars_possibly_in_scope
);
} else {
$pre_outer_context = clone $loop_parent_context;
$original_parent_context = clone $loop_parent_context;

$analyzer = $statements_analyzer->getCodebase()->analyzer;

$original_mixed_counts = $analyzer->getMixedCountsForFile($statements_analyzer->getFilePath());

$pre_condition_vars_in_scope = $loop_context->vars_in_scope;

IssueBuffer::startRecording();

if (!$is_do) {
Expand Down Expand Up @@ -190,7 +187,7 @@ public static function analyze(

$statements_analyzer->analyze($stmts, $continue_context);

self::updateLoopScopeContexts($loop_scope, $loop_context, $continue_context, $pre_outer_context);
self::updateLoopScopeContexts($loop_scope, $loop_context, $continue_context, $original_parent_context);

$continue_context->protected_var_ids = $original_protected_var_ids;

Expand Down Expand Up @@ -241,14 +238,14 @@ public static function analyze(
) {
$has_changes = true;
}
} elseif (isset($pre_outer_context->vars_in_scope[$var_id])) {
if (!$type->equals($pre_outer_context->vars_in_scope[$var_id])) {
} elseif (isset($original_parent_context->vars_in_scope[$var_id])) {
if (!$type->equals($original_parent_context->vars_in_scope[$var_id])) {
$has_changes = true;

// widen the foreach context type with the initial context type
$continue_context->vars_in_scope[$var_id] = Type::combineUnionTypes(
$continue_context->vars_in_scope[$var_id],
$pre_outer_context->vars_in_scope[$var_id]
$original_parent_context->vars_in_scope[$var_id]
);

// if there's a change, invalidate related clauses
Expand Down Expand Up @@ -308,16 +305,6 @@ public static function analyze(
$analyzer->setMixedCountsForFile($statements_analyzer->getFilePath(), $original_mixed_counts);
IssueBuffer::startRecording();

foreach ($pre_loop_context->vars_in_scope as $var_id => $_) {
if (!isset($pre_condition_vars_in_scope[$var_id])
&& isset($continue_context->vars_in_scope[$var_id])
&& strpos($var_id, '->') === false
&& strpos($var_id, '[') === false
) {
$continue_context->vars_in_scope[$var_id]->possibly_undefined = true;
}
}

if (!$is_do) {
foreach ($pre_conditions as $condition_offset => $pre_condition) {
self::applyPreConditionToLoopContext(
Expand Down Expand Up @@ -362,7 +349,7 @@ public static function analyze(

$statements_analyzer->analyze($stmts, $continue_context);

self::updateLoopScopeContexts($loop_scope, $loop_context, $continue_context, $pre_outer_context);
self::updateLoopScopeContexts($loop_scope, $loop_context, $continue_context, $original_parent_context);

$continue_context->protected_var_ids = $original_protected_var_ids;

Expand Down Expand Up @@ -402,6 +389,8 @@ public static function analyze(
IssueBuffer::bubbleUp($recorded_issue);
}
}

$pre_outer_context = $original_parent_context;
}

$does_sometimes_break = in_array(ScopeAnalyzer::ACTION_BREAK, $loop_scope->final_actions, true);
Expand Down

0 comments on commit 9d8b6d6

Please sign in to comment.