From a36d2fcb8414d154fefbd7e5d86ea93c76cf9302 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sat, 21 Oct 2023 14:45:30 +0200 Subject: [PATCH] cs-fixes --- .../Analyzer/FunctionLikeAnalyzer.php | 10 ++++++++-- .../Analyzer/Statements/Block/DoAnalyzer.php | 5 ++++- .../Statements/Block/ForeachAnalyzer.php | 5 ++++- .../Statements/Block/IfElse/ElseAnalyzer.php | 15 +++++++++++--- .../Block/IfElse/ElseIfAnalyzer.php | 15 +++++++++++--- .../Statements/Block/IfElse/IfAnalyzer.php | 10 ++++++++-- .../Statements/Block/IfElseAnalyzer.php | 10 ++++++++-- .../Statements/Block/LoopAnalyzer.php | 15 +++++++++++--- .../Statements/Block/SwitchAnalyzer.php | 5 ++++- .../Statements/Block/WhileAnalyzer.php | 5 ++++- .../Expression/BinaryOp/AndAnalyzer.php | 20 +++++++++++++++---- .../Expression/BinaryOp/OrAnalyzer.php | 10 ++++++++-- .../Statements/Expression/TernaryAnalyzer.php | 16 ++++++++++++--- 13 files changed, 113 insertions(+), 28 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php b/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php index 217d7c5eb..a06bb0423 100644 --- a/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php @@ -799,7 +799,10 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer } if ($this->return_vars_possibly_in_scope !== null) { - $context->vars_possibly_in_scope = [...$context->vars_possibly_in_scope, ...$this->return_vars_possibly_in_scope]; + $context->vars_possibly_in_scope = [ + ...$context->vars_possibly_in_scope, + ...$this->return_vars_possibly_in_scope, + ]; } foreach ($context->vars_in_scope as $var => $_) { @@ -1537,7 +1540,10 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer } if ($this->return_vars_possibly_in_scope !== null) { - $this->return_vars_possibly_in_scope = [...$context->vars_possibly_in_scope, ...$this->return_vars_possibly_in_scope]; + $this->return_vars_possibly_in_scope = [ + ...$context->vars_possibly_in_scope, + ...$this->return_vars_possibly_in_scope, + ]; } else { $this->return_vars_possibly_in_scope = $context->vars_possibly_in_scope; } diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/DoAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/DoAnalyzer.php index d23b31785..3fc0b4f35 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/DoAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/DoAnalyzer.php @@ -157,7 +157,10 @@ final class DoAnalyzer $do_context->loop_scope = null; - $context->vars_possibly_in_scope = [...$context->vars_possibly_in_scope, ...$do_context->vars_possibly_in_scope]; + $context->vars_possibly_in_scope = [ + ...$context->vars_possibly_in_scope, + ...$do_context->vars_possibly_in_scope, + ]; if ($context->collect_exceptions) { $context->mergeExceptions($inner_loop_context); diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php index 5843cb1c3..f5e6c26d6 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php @@ -385,7 +385,10 @@ final class ForeachAnalyzer $foreach_context->loop_scope = null; - $context->vars_possibly_in_scope = [...$foreach_context->vars_possibly_in_scope, ...$context->vars_possibly_in_scope]; + $context->vars_possibly_in_scope = [ + ...$foreach_context->vars_possibly_in_scope, + ...$context->vars_possibly_in_scope, + ]; if ($context->collect_exceptions) { $context->mergeExceptions($foreach_context); diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseAnalyzer.php index 538fba9af..568a19e1a 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseAnalyzer.php @@ -200,13 +200,22 @@ final class ElseAnalyzer if ($has_leaving_statements) { if ($else_context->loop_scope) { if (!$has_continue_statement && !$has_break_statement) { - $if_scope->new_vars_possibly_in_scope = [...$vars_possibly_in_scope, ...$if_scope->new_vars_possibly_in_scope]; + $if_scope->new_vars_possibly_in_scope = [ + ...$vars_possibly_in_scope, + ...$if_scope->new_vars_possibly_in_scope, + ]; } - $else_context->loop_scope->vars_possibly_in_scope = [...$vars_possibly_in_scope, ...$else_context->loop_scope->vars_possibly_in_scope]; + $else_context->loop_scope->vars_possibly_in_scope = [ + ...$vars_possibly_in_scope, + ...$else_context->loop_scope->vars_possibly_in_scope, + ]; } } else { - $if_scope->new_vars_possibly_in_scope = [...$vars_possibly_in_scope, ...$if_scope->new_vars_possibly_in_scope]; + $if_scope->new_vars_possibly_in_scope = [ + ...$vars_possibly_in_scope, + ...$if_scope->new_vars_possibly_in_scope, + ]; $if_scope->possibly_assigned_var_ids = array_merge( $possibly_assigned_var_ids, diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseIfAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseIfAnalyzer.php index da72058bf..f4aa30a19 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseIfAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseIfAnalyzer.php @@ -373,16 +373,25 @@ final class ElseIfAnalyzer if ($has_leaving_statements && $elseif_context->loop_scope) { if (!$has_continue_statement && !$has_break_statement) { - $if_scope->new_vars_possibly_in_scope = [...$vars_possibly_in_scope, ...$if_scope->new_vars_possibly_in_scope]; + $if_scope->new_vars_possibly_in_scope = [ + ...$vars_possibly_in_scope, + ...$if_scope->new_vars_possibly_in_scope, + ]; $if_scope->possibly_assigned_var_ids = array_merge( $possibly_assigned_var_ids, $if_scope->possibly_assigned_var_ids, ); } - $elseif_context->loop_scope->vars_possibly_in_scope = [...$vars_possibly_in_scope, ...$elseif_context->loop_scope->vars_possibly_in_scope]; + $elseif_context->loop_scope->vars_possibly_in_scope = [ + ...$vars_possibly_in_scope, + ...$elseif_context->loop_scope->vars_possibly_in_scope, + ]; } elseif (!$has_leaving_statements) { - $if_scope->new_vars_possibly_in_scope = [...$vars_possibly_in_scope, ...$if_scope->new_vars_possibly_in_scope]; + $if_scope->new_vars_possibly_in_scope = [ + ...$vars_possibly_in_scope, + ...$if_scope->new_vars_possibly_in_scope, + ]; $if_scope->possibly_assigned_var_ids = array_merge( $possibly_assigned_var_ids, $if_scope->possibly_assigned_var_ids, diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/IfAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/IfAnalyzer.php index 45cc25980..f33c93d86 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/IfAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/IfAnalyzer.php @@ -146,7 +146,10 @@ final class IfAnalyzer $if_context->reconciled_expression_clauses = []; - $outer_context->vars_possibly_in_scope = [...$if_context->vars_possibly_in_scope, ...$outer_context->vars_possibly_in_scope]; + $outer_context->vars_possibly_in_scope = [ + ...$if_context->vars_possibly_in_scope, + ...$outer_context->vars_possibly_in_scope, + ]; $old_if_context = clone $if_context; @@ -305,7 +308,10 @@ final class IfAnalyzer $if_scope->new_vars_possibly_in_scope = $vars_possibly_in_scope; } - $if_context->loop_scope->vars_possibly_in_scope = [...$vars_possibly_in_scope, ...$if_context->loop_scope->vars_possibly_in_scope]; + $if_context->loop_scope->vars_possibly_in_scope = [ + ...$vars_possibly_in_scope, + ...$if_context->loop_scope->vars_possibly_in_scope, + ]; } elseif (!$has_leaving_statements) { $if_scope->new_vars_possibly_in_scope = $vars_possibly_in_scope; } diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/IfElseAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/IfElseAnalyzer.php index cfbe2a692..b14891ce0 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/IfElseAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/IfElseAnalyzer.php @@ -363,9 +363,15 @@ final class IfElseAnalyzer ); } - $context->vars_possibly_in_scope = [...$context->vars_possibly_in_scope, ...$if_scope->new_vars_possibly_in_scope]; + $context->vars_possibly_in_scope = [ + ...$context->vars_possibly_in_scope, + ...$if_scope->new_vars_possibly_in_scope, + ]; - $context->possibly_assigned_var_ids = [...$context->possibly_assigned_var_ids, ...$if_scope->possibly_assigned_var_ids ?: []]; + $context->possibly_assigned_var_ids = [ + ...$context->possibly_assigned_var_ids, + ...$if_scope->possibly_assigned_var_ids ?: [], + ]; // vars can only be defined/redefined if there was an else (defined in every block) $context->assigned_var_ids = array_merge( diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/LoopAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/LoopAnalyzer.php index e0705a0ca..9fb909fd8 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/LoopAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/LoopAnalyzer.php @@ -139,7 +139,10 @@ final class LoopAnalyzer } } - $loop_parent_context->vars_possibly_in_scope = [...$continue_context->vars_possibly_in_scope, ...$loop_parent_context->vars_possibly_in_scope]; + $loop_parent_context->vars_possibly_in_scope = [ + ...$continue_context->vars_possibly_in_scope, + ...$loop_parent_context->vars_possibly_in_scope, + ]; } else { $original_parent_context = clone $loop_parent_context; @@ -267,7 +270,10 @@ final class LoopAnalyzer $continue_context->has_returned = false; - $loop_parent_context->vars_possibly_in_scope = [...$continue_context->vars_possibly_in_scope, ...$loop_parent_context->vars_possibly_in_scope]; + $loop_parent_context->vars_possibly_in_scope = [ + ...$continue_context->vars_possibly_in_scope, + ...$loop_parent_context->vars_possibly_in_scope, + ]; // if there are no changes to the types, no need to re-examine if (!$has_changes) { @@ -547,7 +553,10 @@ final class LoopAnalyzer } // merge vars possibly in scope at the end of each loop - $loop_context->vars_possibly_in_scope = [...$loop_context->vars_possibly_in_scope, ...$loop_scope->vars_possibly_in_scope]; + $loop_context->vars_possibly_in_scope = [ + ...$loop_context->vars_possibly_in_scope, + ...$loop_scope->vars_possibly_in_scope, + ]; } /** diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/SwitchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/SwitchAnalyzer.php index c3f5bc4f9..ee9d7cb18 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/SwitchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/SwitchAnalyzer.php @@ -219,7 +219,10 @@ final class SwitchAnalyzer $context->assigned_var_ids += $switch_scope->new_assigned_var_ids; } - $context->vars_possibly_in_scope = [...$context->vars_possibly_in_scope, ...$switch_scope->new_vars_possibly_in_scope]; + $context->vars_possibly_in_scope = [ + ...$context->vars_possibly_in_scope, + ...$switch_scope->new_vars_possibly_in_scope, + ]; //a switch can't return in all options without a default $context->has_returned = $all_options_returned && $has_default; diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/WhileAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/WhileAnalyzer.php index 694515eb9..fa2fd99e6 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/WhileAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/WhileAnalyzer.php @@ -103,7 +103,10 @@ final class WhileAnalyzer $while_context->loop_scope = null; if ($can_leave_loop) { - $context->vars_possibly_in_scope = [...$context->vars_possibly_in_scope, ...$while_context->vars_possibly_in_scope]; + $context->vars_possibly_in_scope = [ + ...$context->vars_possibly_in_scope, + ...$while_context->vars_possibly_in_scope, + ]; } elseif ($pre_context) { $context->vars_possibly_in_scope = $pre_context->vars_possibly_in_scope; } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/AndAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/AndAnalyzer.php index ec0967aee..5356280bd 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/AndAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/AndAnalyzer.php @@ -188,11 +188,20 @@ final class AndAnalyzer if ($context->if_body_context && !$context->inside_negation) { $if_body_context = $context->if_body_context; $context->vars_in_scope = $right_context->vars_in_scope; - $if_body_context->vars_in_scope = [...$if_body_context->vars_in_scope, ...$context->vars_in_scope]; + $if_body_context->vars_in_scope = [ + ...$if_body_context->vars_in_scope, + ...$context->vars_in_scope, + ]; - $if_body_context->cond_referenced_var_ids = [...$if_body_context->cond_referenced_var_ids, ...$context->cond_referenced_var_ids]; + $if_body_context->cond_referenced_var_ids = [ + ...$if_body_context->cond_referenced_var_ids, + ...$context->cond_referenced_var_ids, + ]; - $if_body_context->assigned_var_ids = [...$if_body_context->assigned_var_ids, ...$context->assigned_var_ids]; + $if_body_context->assigned_var_ids = [ + ...$if_body_context->assigned_var_ids, + ...$context->assigned_var_ids, + ]; $if_body_context->reconciled_expression_clauses = [ ...$if_body_context->reconciled_expression_clauses, @@ -203,7 +212,10 @@ final class AndAnalyzer ), ]; - $if_body_context->vars_possibly_in_scope = [...$if_body_context->vars_possibly_in_scope, ...$context->vars_possibly_in_scope]; + $if_body_context->vars_possibly_in_scope = [ + ...$if_body_context->vars_possibly_in_scope, + ...$context->vars_possibly_in_scope, + ]; $if_body_context->updateChecks($context); } else { diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/OrAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/OrAnalyzer.php index d43c33936..e7134d074 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/OrAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/BinaryOp/OrAnalyzer.php @@ -132,10 +132,16 @@ final class OrAnalyzer } $left_referenced_var_ids = $left_context->cond_referenced_var_ids; - $left_context->cond_referenced_var_ids = [...$pre_referenced_var_ids, ...$left_referenced_var_ids]; + $left_context->cond_referenced_var_ids = [ + ...$pre_referenced_var_ids, + ...$left_referenced_var_ids, + ]; $left_assigned_var_ids = array_diff_key($left_context->assigned_var_ids, $pre_assigned_var_ids); - $left_context->assigned_var_ids = [...$pre_assigned_var_ids, ...$left_context->assigned_var_ids]; + $left_context->assigned_var_ids = [ + ...$pre_assigned_var_ids, + ...$left_context->assigned_var_ids, + ]; $left_referenced_var_ids = array_diff_key($left_referenced_var_ids, $left_assigned_var_ids); } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/TernaryAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/TernaryAnalyzer.php index 671b15165..9c574e7a0 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/TernaryAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/TernaryAnalyzer.php @@ -210,7 +210,10 @@ final class TernaryAnalyzer return false; } - $context->cond_referenced_var_ids = [...$context->cond_referenced_var_ids, ...$if_context->cond_referenced_var_ids]; + $context->cond_referenced_var_ids = [ + ...$context->cond_referenced_var_ids, + ...$if_context->cond_referenced_var_ids, + ]; } $t_else_context->clauses = Algebra::simplifyCNF( @@ -286,9 +289,16 @@ final class TernaryAnalyzer } } - $context->vars_possibly_in_scope = [...$context->vars_possibly_in_scope, ...$if_context->vars_possibly_in_scope, ...$t_else_context->vars_possibly_in_scope]; + $context->vars_possibly_in_scope = [ + ...$context->vars_possibly_in_scope, + ...$if_context->vars_possibly_in_scope, + ...$t_else_context->vars_possibly_in_scope, + ]; - $context->cond_referenced_var_ids = [...$context->cond_referenced_var_ids, ...$t_else_context->cond_referenced_var_ids]; + $context->cond_referenced_var_ids = [ + ...$context->cond_referenced_var_ids, + ...$t_else_context->cond_referenced_var_ids, + ]; $lhs_type = null; $stmt_cond_type = $statements_analyzer->node_data->getType($stmt->cond);