From d7ae4656e7957c792291581353ac2b6ec43c3213 Mon Sep 17 00:00:00 2001 From: Brown Date: Sun, 30 Aug 2020 16:30:43 -0400 Subject: [PATCH] Fix Psalm errors --- .../Statements/Expression/MatchAnalyzer.php | 22 +++++++------------ src/Psalm/Internal/PropertyMap.php | 3 +++ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/MatchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/MatchAnalyzer.php index 3f26aff3c..21b5352f0 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/MatchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/MatchAnalyzer.php @@ -39,8 +39,6 @@ class MatchAnalyzer $match_condition = $stmt->cond; - $fake_match_condition = false; - if (!$switch_var_id && ($stmt->cond instanceof PhpParser\Node\Expr\FuncCall || $stmt->cond instanceof PhpParser\Node\Expr\MethodCall @@ -53,14 +51,10 @@ class MatchAnalyzer $context->vars_in_scope[$switch_var_id] = $condition_type; - if ($switch_var_id && substr($switch_var_id, 0, 15) === '$__tmp_switch__') { - $match_condition = new PhpParser\Node\Expr\Variable( - substr($switch_var_id, 1), - $stmt->cond->getAttributes() - ); - - $fake_match_condition = true; - } + $match_condition = new PhpParser\Node\Expr\Variable( + substr($switch_var_id, 1), + $stmt->cond->getAttributes() + ); } $arms = $stmt->arms; @@ -81,7 +75,7 @@ class MatchAnalyzer $statements_analyzer->node_data = clone $statements_analyzer->node_data; - if ($last_arm->conds === null) { + if (!$last_arm->conds) { $ternary = $last_arm->body; } else { $ternary = new PhpParser\Node\Expr\Ternary( @@ -132,9 +126,9 @@ class MatchAnalyzer $statements_analyzer->removeSuppressedIssues(['RedundantConditionGivenDocblockType']); } - if ($stmt_expr_type = $statements_analyzer->node_data->getType($ternary)) { - $old_node_data->setType($stmt, $stmt_expr_type ?: Type::getMixed()); - } + $stmt_expr_type = $statements_analyzer->node_data->getType($ternary); + + $old_node_data->setType($stmt, $stmt_expr_type ?: Type::getMixed()); $statements_analyzer->node_data = $old_node_data; diff --git a/src/Psalm/Internal/PropertyMap.php b/src/Psalm/Internal/PropertyMap.php index 348df7daf..e3ea9afd0 100644 --- a/src/Psalm/Internal/PropertyMap.php +++ b/src/Psalm/Internal/PropertyMap.php @@ -508,6 +508,9 @@ return [ 'phpparser\\node\\stmt\\interface_' => [ 'stmts' => 'array', ], + 'phpparser\\node\\matcharm' => [ + 'conds' => 'null|non-empty-list', + ], 'rdkafka\\message' => [ 'err' => 'int', 'topic_name' => 'string',