mirror of
https://github.com/danog/psalm.git
synced 2024-12-12 01:09:38 +01:00
redundant variable check
This commit is contained in:
parent
998f91aa65
commit
c11b32d414
@ -250,7 +250,7 @@ class ForeachAnalyzer
|
||||
$foreach_context->branch_point ?: (int) $stmt->getAttribute('startFilePos');
|
||||
}
|
||||
|
||||
if ($stmt->keyVar && $stmt->keyVar instanceof PhpParser\Node\Expr\Variable && is_string($stmt->keyVar->name)) {
|
||||
if ($stmt->keyVar instanceof PhpParser\Node\Expr\Variable && is_string($stmt->keyVar->name)) {
|
||||
$key_type = $key_type ?: Type::getMixed();
|
||||
|
||||
AssignmentAnalyzer::analyze(
|
||||
|
@ -21,10 +21,7 @@ class BreakAnalyzer
|
||||
if ($loop_scope) {
|
||||
if ($context->break_types
|
||||
&& \end($context->break_types) === 'switch'
|
||||
&& (!$stmt->num
|
||||
|| !$stmt->num instanceof PhpParser\Node\Scalar\LNumber
|
||||
|| $stmt->num->value < 2
|
||||
)
|
||||
&& (!$stmt->num instanceof PhpParser\Node\Scalar\LNumber || $stmt->num->value < 2)
|
||||
) {
|
||||
$loop_scope->final_actions[] = ScopeAnalyzer::ACTION_LEAVE_SWITCH;
|
||||
} else {
|
||||
|
@ -17,10 +17,7 @@ class ContinueAnalyzer
|
||||
PhpParser\Node\Stmt\Continue_ $stmt,
|
||||
Context $context
|
||||
): void {
|
||||
$count = $stmt->num
|
||||
&& $stmt->num instanceof PhpParser\Node\Scalar\LNumber
|
||||
? $stmt->num->value
|
||||
: 1;
|
||||
$count = $stmt->num instanceof PhpParser\Node\Scalar\LNumber? $stmt->num->value : 1;
|
||||
|
||||
$loop_scope = $context->loop_scope;
|
||||
|
||||
|
@ -1349,9 +1349,8 @@ class AssignmentAnalyzer
|
||||
|
||||
$can_be_empty = !$assign_value_atomic_type instanceof Type\Atomic\TNonEmptyList;
|
||||
} elseif ($assign_value_atomic_type instanceof Type\Atomic\TKeyedArray) {
|
||||
if ($assign_var_item->key
|
||||
&& ($assign_var_item->key instanceof PhpParser\Node\Scalar\String_
|
||||
|| $assign_var_item->key instanceof PhpParser\Node\Scalar\LNumber)
|
||||
if (($assign_var_item->key instanceof PhpParser\Node\Scalar\String_
|
||||
|| $assign_var_item->key instanceof PhpParser\Node\Scalar\LNumber)
|
||||
&& isset($assign_value_atomic_type->properties[$assign_var_item->key->value])
|
||||
) {
|
||||
$new_assign_type =
|
||||
|
@ -70,8 +70,7 @@ class ArgumentsAnalyzer
|
||||
: null;
|
||||
|
||||
// if this modifies the array type based on further args
|
||||
if ($method_id
|
||||
&& in_array($method_id, ['array_push', 'array_unshift'], true)
|
||||
if (in_array($method_id, ['array_push', 'array_unshift'], true)
|
||||
&& $function_params
|
||||
&& isset($args[0])
|
||||
&& isset($args[1])
|
||||
@ -89,7 +88,7 @@ class ArgumentsAnalyzer
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($method_id && $method_id === 'array_splice' && $function_params && count($args) > 1) {
|
||||
if ($method_id === 'array_splice' && $function_params && count($args) > 1) {
|
||||
if (ArrayFunctionArgumentsAnalyzer::handleSplice($statements_analyzer, $args, $context) === false) {
|
||||
return false;
|
||||
}
|
||||
|
@ -223,9 +223,7 @@ class NamedFunctionCallHandler
|
||||
if ($function_id === 'func_get_args') {
|
||||
$source = $statements_analyzer->getSource();
|
||||
|
||||
if ($statements_analyzer->data_flow_graph
|
||||
&& $source instanceof \Psalm\Internal\Analyzer\FunctionLikeAnalyzer
|
||||
) {
|
||||
if ($source instanceof \Psalm\Internal\Analyzer\FunctionLikeAnalyzer) {
|
||||
if ($statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph) {
|
||||
foreach ($source->param_nodes as $param_node) {
|
||||
$statements_analyzer->data_flow_graph->addPath(
|
||||
|
@ -66,8 +66,7 @@ class CastAnalyzer
|
||||
new Type\Atomic\TLiteralInt(1),
|
||||
]);
|
||||
|
||||
if ($statements_analyzer->data_flow_graph
|
||||
&& $statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph
|
||||
if ($statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph
|
||||
) {
|
||||
$type->parent_nodes = $maybe_type->parent_nodes;
|
||||
}
|
||||
@ -79,8 +78,7 @@ class CastAnalyzer
|
||||
if ($as_int) {
|
||||
$type = $valid_int_type ?? Type::getInt();
|
||||
|
||||
if ($statements_analyzer->data_flow_graph
|
||||
&& $statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph
|
||||
if ($statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph
|
||||
) {
|
||||
$type->parent_nodes = $maybe_type ? $maybe_type->parent_nodes : [];
|
||||
}
|
||||
@ -106,8 +104,7 @@ class CastAnalyzer
|
||||
|
||||
$type = Type::getFloat();
|
||||
|
||||
if ($statements_analyzer->data_flow_graph
|
||||
&& $statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph
|
||||
if ($statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph
|
||||
) {
|
||||
$type->parent_nodes = $maybe_type ? $maybe_type->parent_nodes : [];
|
||||
}
|
||||
@ -132,8 +129,7 @@ class CastAnalyzer
|
||||
|
||||
$type = Type::getBool();
|
||||
|
||||
if ($statements_analyzer->data_flow_graph
|
||||
&& $statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph
|
||||
if ($statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph
|
||||
) {
|
||||
$type->parent_nodes = $maybe_type ? $maybe_type->parent_nodes : [];
|
||||
}
|
||||
@ -183,8 +179,7 @@ class CastAnalyzer
|
||||
|
||||
$maybe_type = $statements_analyzer->node_data->getType($stmt->expr);
|
||||
|
||||
if ($statements_analyzer->data_flow_graph
|
||||
&& $statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph
|
||||
if ($statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph
|
||||
) {
|
||||
$type->parent_nodes = $maybe_type ? $maybe_type->parent_nodes : [];
|
||||
}
|
||||
@ -237,8 +232,7 @@ class CastAnalyzer
|
||||
$type = Type::getArray();
|
||||
}
|
||||
|
||||
if ($statements_analyzer->data_flow_graph
|
||||
&& $statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph
|
||||
if ($statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph
|
||||
) {
|
||||
$type->parent_nodes = $stmt_expr_type ? $stmt_expr_type->parent_nodes : [];
|
||||
}
|
||||
|
@ -450,7 +450,7 @@ class ParseTreeCreator
|
||||
return;
|
||||
}
|
||||
|
||||
if ($current_parent && $current_parent instanceof ParseTree\KeyedArrayPropertyTree) {
|
||||
if ($current_parent instanceof ParseTree\KeyedArrayPropertyTree) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -462,7 +462,7 @@ class ParseTreeCreator
|
||||
$current_parent = $this->current_leaf->parent;
|
||||
}
|
||||
|
||||
if ($current_parent && $current_parent instanceof ParseTree\ConditionalTree) {
|
||||
if ($current_parent instanceof ParseTree\ConditionalTree) {
|
||||
if (count($current_parent->children) > 1) {
|
||||
throw new TypeParseTreeException('Cannot process colon in conditional twice');
|
||||
}
|
||||
@ -608,12 +608,12 @@ class ParseTreeCreator
|
||||
throw new TypeParseTreeException('Unexpected token |');
|
||||
}
|
||||
|
||||
if ($current_parent && $current_parent instanceof ParseTree\UnionTree) {
|
||||
if ($current_parent instanceof ParseTree\UnionTree) {
|
||||
$this->current_leaf = $current_parent;
|
||||
return;
|
||||
}
|
||||
|
||||
if ($current_parent && $current_parent instanceof ParseTree\IntersectionTree) {
|
||||
if ($current_parent instanceof ParseTree\IntersectionTree) {
|
||||
$this->current_leaf = $current_parent;
|
||||
$current_parent = $this->current_leaf->parent;
|
||||
}
|
||||
@ -649,12 +649,12 @@ class ParseTreeCreator
|
||||
|
||||
$current_parent = $this->current_leaf->parent;
|
||||
|
||||
if ($current_parent && $current_parent instanceof ParseTree\MethodTree) {
|
||||
if ($current_parent instanceof ParseTree\MethodTree) {
|
||||
$this->createMethodParam($this->type_tokens[$this->t], $current_parent);
|
||||
return;
|
||||
}
|
||||
|
||||
if ($current_parent && $current_parent instanceof ParseTree\IntersectionTree) {
|
||||
if ($current_parent instanceof ParseTree\IntersectionTree) {
|
||||
$this->current_leaf = $current_parent;
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user