Skip to content

Commit

Permalink
Use more accurate variable name
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jun 25, 2021
1 parent 6d4262e commit 67d68a5
Show file tree
Hide file tree
Showing 25 changed files with 87 additions and 87 deletions.
2 changes: 1 addition & 1 deletion src/Psalm/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Context
*
* @var bool
*/
public $inside_use = false;
public $inside_general_use = false;

/**
* Whether or not we're inside a return expression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ public static function analyze(
}
}

$was_inside_use = $context->inside_use;
$context->inside_use = true;
$was_inside_general_use = $context->inside_general_use;
$context->inside_general_use = true;
if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->expr, $context) === false) {
return false;
}
$context->inside_use = $was_inside_use;
$context->inside_general_use = $was_inside_general_use;

$key_type = null;
$value_type = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,12 +282,12 @@ private static function analyzeArrayItem(
$item_is_list_item = false;

if ($item->key) {
$was_inside_use = $context->inside_use;
$context->inside_use = true;
$was_inside_general_use = $context->inside_general_use;
$context->inside_general_use = true;
if (ExpressionAnalyzer::analyze($statements_analyzer, $item->key, $context) === false) {
return;
}
$context->inside_use = $was_inside_use;
$context->inside_general_use = $was_inside_general_use;

if ($item_key_type = $statements_analyzer->node_data->getType($item->key)) {
$key_type = $item_key_type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,8 @@ private static function analyzeNestedArrayAssignment(
$offset_type = null;

if ($child_stmt->dim) {
$was_inside_use = $context->inside_use;
$context->inside_use = true;
$was_inside_general_use = $context->inside_general_use;
$context->inside_general_use = true;

if (ExpressionAnalyzer::analyze(
$statements_analyzer,
Expand All @@ -692,7 +692,7 @@ private static function analyzeNestedArrayAssignment(
return;
}

$context->inside_use = $was_inside_use;
$context->inside_general_use = $was_inside_general_use;

if (!($child_stmt_dim_type = $statements_analyzer->node_data->getType($child_stmt->dim))) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -608,12 +608,12 @@ private static function analyzeRegularAssignment(
string $prop_name,
?string &$var_id
): array {
$was_inside_use = $context->inside_use;
$context->inside_use = true;
$was_inside_general_use = $context->inside_general_use;
$context->inside_general_use = true;

ExpressionAnalyzer::analyze($statements_analyzer, $stmt->var, $context);

$context->inside_use = $was_inside_use;
$context->inside_general_use = $was_inside_general_use;

$lhs_type = $statements_analyzer->node_data->getType($stmt->var);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ public static function analyze(
$fq_class_name = $lhs_atomic_type->value;

if (!$prop_name instanceof PhpParser\Node\Identifier) {
$was_inside_use = $context->inside_use;
$was_inside_general_use = $context->inside_general_use;

$context->inside_use = true;
$context->inside_general_use = true;

if (ExpressionAnalyzer::analyze($statements_analyzer, $prop_name, $context) === false) {
return false;
}

$context->inside_use = $was_inside_use;
$context->inside_general_use = $was_inside_general_use;

if (!$context->ignore_variable_property) {
$codebase->analyzer->addMixedMemberName(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public static function analyze(
}
}

$was_inside_use = $context->inside_use;
$was_inside_general_use = $context->inside_general_use;

$root_expr = $assign_var;

Expand All @@ -211,7 +211,7 @@ public static function analyze(
|| (\is_string($root_expr->name)
&& \in_array('$' . $root_expr->name, VariableFetchAnalyzer::SUPER_GLOBALS, true))
) {
$context->inside_use = true;
$context->inside_general_use = true;
}

if (ExpressionAnalyzer::analyze($statements_analyzer, $assign_value, $context) === false) {
Expand All @@ -227,7 +227,7 @@ public static function analyze(
return false;
}

$context->inside_use = $was_inside_use;
$context->inside_general_use = $was_inside_general_use;
}

if ($comment_type && $comment_type_location) {
Expand Down Expand Up @@ -1501,8 +1501,8 @@ private static function analyzePropertyAssignment(
?string $var_id
): void {
if (!$assign_var->name instanceof PhpParser\Node\Identifier) {
$was_inside_use = $context->inside_use;
$context->inside_use = true;
$was_inside_general_use = $context->inside_general_use;
$context->inside_general_use = true;

// this can happen when the user actually means to type $this-><autocompleted>, but there's
// a variable on the next line
Expand All @@ -1514,7 +1514,7 @@ private static function analyzePropertyAssignment(
return;
}

$context->inside_use = $was_inside_use;
$context->inside_general_use = $was_inside_general_use;
}

if ($assign_var->name instanceof PhpParser\Node\Identifier) {
Expand Down Expand Up @@ -1697,14 +1697,14 @@ private static function analyzeAssignmentToVariable(
}
}
} else {
$was_inside_use = $context->inside_use;
$context->inside_use = true;
$was_inside_general_use = $context->inside_general_use;
$context->inside_general_use = true;

if (ExpressionAnalyzer::analyze($statements_analyzer, $assign_var->name, $context) === false) {
return;
}

$context->inside_use = $was_inside_use;
$context->inside_general_use = $was_inside_general_use;

if ($statements_analyzer->data_flow_graph instanceof VariableUseGraph
&& $assign_value_type->parent_nodes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public static function analyze(
if ($stmt instanceof PhpParser\Node\Expr\BinaryOp\BooleanAnd ||
$stmt instanceof PhpParser\Node\Expr\BinaryOp\LogicalAnd
) {
$was_inside_use = $context->inside_use;
$context->inside_use = true;
$was_inside_general_use = $context->inside_general_use;
$context->inside_general_use = true;

$expr_result = BinaryOp\AndAnalyzer::analyze(
$statements_analyzer,
Expand All @@ -47,7 +47,7 @@ public static function analyze(
$from_stmt
);

$context->inside_use = $was_inside_use;
$context->inside_general_use = $was_inside_general_use;

$statements_analyzer->node_data->setType($stmt, Type::getBool());

Expand All @@ -57,8 +57,8 @@ public static function analyze(
if ($stmt instanceof PhpParser\Node\Expr\BinaryOp\BooleanOr ||
$stmt instanceof PhpParser\Node\Expr\BinaryOp\LogicalOr
) {
$was_inside_use = $context->inside_use;
$context->inside_use = true;
$was_inside_general_use = $context->inside_general_use;
$context->inside_general_use = true;

$expr_result = BinaryOp\OrAnalyzer::analyze(
$statements_analyzer,
Expand All @@ -67,7 +67,7 @@ public static function analyze(
$from_stmt
);

$context->inside_use = $was_inside_use;
$context->inside_general_use = $was_inside_general_use;

$statements_analyzer->node_data->setType($stmt, Type::getBool());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ public static function verifyType(
true,
$context->inside_return
|| $context->inside_call
|| $context->inside_use
|| $context->inside_general_use
|| $context->inside_assignment
|| $context->inside_conditional
|| $context->inside_throw
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ private static function checkFunctionCallPurity(
if (!$context->inside_assignment
&& !$context->inside_call
&& !$context->inside_return
&& !$context->inside_use
&& !$context->inside_general_use
&& !$context->inside_throw
&& !self::callUsesByReferenceArguments($function_call_info, $stmt)
&& !(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public static function analyze(
false,
$context->inside_return
|| $context->inside_call
|| $context->inside_use
|| $context->inside_general_use
|| $context->inside_assignment
|| $context->inside_conditional
|| $context->inside_throw
Expand Down Expand Up @@ -329,7 +329,7 @@ public static function analyze(
true,
$context->inside_return
|| $context->inside_call
|| $context->inside_use
|| $context->inside_general_use
|| $context->inside_assignment
|| $context->inside_conditional
|| $context->inside_throw
Expand Down Expand Up @@ -736,7 +736,7 @@ private static function handleTemplatedMixins(
true,
$context->inside_return
|| $context->inside_call
|| $context->inside_use
|| $context->inside_general_use
|| $context->inside_assignment
|| $context->inside_conditional
|| $context->inside_throw
Expand Down Expand Up @@ -809,7 +809,7 @@ private static function handleRegularMixins(
true,
$context->inside_return
|| $context->inside_call
|| $context->inside_use
|| $context->inside_general_use
|| $context->inside_assignment
|| $context->inside_conditional
|| $context->inside_throw
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static function analyze(

if ($codebase->find_unused_variables
&& !$context->inside_conditional
&& !$context->inside_use
&& !$context->inside_general_use
&& !$context->inside_throw
) {
if (!$context->inside_assignment && !$context->inside_call && !$context->inside_return) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public static function analyze(

$context->inside_call = true;

$was_inside_use = $context->inside_use;
$context->inside_use = true;
$was_inside_general_use = $context->inside_general_use;
$context->inside_general_use = true;

$existing_stmt_var_type = null;

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

$context->inside_call = $was_inside_call;
$context->inside_use = $was_inside_use;
$context->inside_general_use = $was_inside_general_use;

if ($stmt->var instanceof PhpParser\Node\Expr\Variable) {
if (is_string($stmt->var->name) && $stmt->var->name === 'this' && !$statements_analyzer->getFQCLN()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,10 +600,10 @@ private static function analyzeConstructorExpression(
?string &$fq_class_name,
bool &$can_extend
): void {
$was_inside_use = $context->inside_use;
$context->inside_use = true;
$was_inside_general_use = $context->inside_general_use;
$context->inside_general_use = true;
ExpressionAnalyzer::analyze($statements_analyzer, $stmt_class, $context);
$context->inside_use = $was_inside_use;
$context->inside_general_use = $was_inside_general_use;

$stmt_class_type = $statements_analyzer->node_data->getType($stmt_class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ public static function analyze(
$lhs_type = new Type\Union([new TNamedObject($fq_class_name)]);
}
} else {
$was_inside_use = $context->inside_use;
$context->inside_use = true;
$was_inside_general_use = $context->inside_general_use;
$context->inside_general_use = true;
ExpressionAnalyzer::analyze($statements_analyzer, $stmt->class, $context);
$context->inside_use = $was_inside_use;
$context->inside_general_use = $was_inside_general_use;
$lhs_type = $statements_analyzer->node_data->getType($stmt->class) ?: Type::getMixed();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,12 @@ public static function analyze(
);
} else {
if ($stmt->name instanceof PhpParser\Node\Expr) {
$was_inside_use = $context->inside_use;
$context->inside_use = true;
$was_inside_general_use = $context->inside_general_use;
$context->inside_general_use = true;

ExpressionAnalyzer::analyze($statements_analyzer, $stmt->name, $context);

$context->inside_use = $was_inside_use;
$context->inside_general_use = $was_inside_general_use;
}

if (!$context->ignore_variable_method) {
Expand Down Expand Up @@ -303,7 +303,7 @@ private static function handleNamedCall(
false,
$context->inside_return
|| $context->inside_call
|| $context->inside_use
|| $context->inside_general_use
|| $context->inside_assignment
|| $context->inside_conditional
|| $context->inside_throw
Expand Down Expand Up @@ -350,7 +350,7 @@ private static function handleNamedCall(
true,
$context->inside_return
|| $context->inside_call
|| $context->inside_use
|| $context->inside_general_use
|| $context->inside_assignment
|| $context->inside_conditional
|| $context->inside_throw
Expand Down Expand Up @@ -475,7 +475,7 @@ private static function handleNamedCall(
true,
$context->inside_return
|| $context->inside_call
|| $context->inside_use
|| $context->inside_general_use
|| $context->inside_assignment
|| $context->inside_conditional
|| $context->inside_throw
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,12 @@ public static function analyze(
}

if ($stmt instanceof PhpParser\Node\Expr\Cast\Object_) {
$was_inside_use = $context->inside_use;
$context->inside_use = true;
$was_inside_general_use = $context->inside_general_use;
$context->inside_general_use = true;
if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->expr, $context) === false) {
return false;
}
$context->inside_use = $was_inside_use;
$context->inside_general_use = $was_inside_general_use;

$type = new Type\Union([new TNamedObject('stdClass')]);

Expand All @@ -195,12 +195,12 @@ public static function analyze(
}

if ($stmt instanceof PhpParser\Node\Expr\Cast\Array_) {
$was_inside_use = $context->inside_use;
$context->inside_use = true;
$was_inside_general_use = $context->inside_general_use;
$context->inside_general_use = true;
if (ExpressionAnalyzer::analyze($statements_analyzer, $stmt->expr, $context) === false) {
return false;
}
$context->inside_use = $was_inside_use;
$context->inside_general_use = $was_inside_general_use;

$permissible_atomic_types = [];
$all_permissible = false;
Expand Down
Loading

0 comments on commit 67d68a5

Please sign in to comment.