mirror of
https://github.com/danog/psalm.git
synced 2025-01-23 06:11:25 +01:00
Simplify some methods to keep Psalm happy
This commit is contained in:
parent
238b54abf8
commit
7444ea8e2d
@ -1254,26 +1254,13 @@ class InstancePropertyAssignmentAnalyzer
|
||||
false
|
||||
);
|
||||
|
||||
if ($codebase->properties_to_rename) {
|
||||
$declaring_property_id = strtolower($declaring_property_class) . '::$' . $prop_name;
|
||||
|
||||
foreach ($codebase->properties_to_rename as $original_property_id => $new_property_name) {
|
||||
if ($declaring_property_id === $original_property_id) {
|
||||
$file_manipulations = [
|
||||
new FileManipulation(
|
||||
(int)$stmt->name->getAttribute('startFilePos'),
|
||||
(int)$stmt->name->getAttribute('endFilePos') + 1,
|
||||
$new_property_name
|
||||
)
|
||||
];
|
||||
|
||||
FileManipulationBuffer::add(
|
||||
$statements_analyzer->getFilePath(),
|
||||
$file_manipulations
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
self::handlePropertyRenames(
|
||||
$codebase,
|
||||
$declaring_property_class,
|
||||
$prop_name,
|
||||
$stmt,
|
||||
$statements_analyzer->getFilePath()
|
||||
);
|
||||
|
||||
$declaring_class_storage = $codebase->classlike_storage_provider->get($declaring_property_class);
|
||||
|
||||
@ -1446,6 +1433,37 @@ class InstancePropertyAssignmentAnalyzer
|
||||
);
|
||||
}
|
||||
|
||||
private static function handlePropertyRenames(
|
||||
Codebase $codebase,
|
||||
string $declaring_property_class,
|
||||
string $prop_name,
|
||||
PropertyFetch $stmt,
|
||||
string $file_path
|
||||
): void {
|
||||
if (!$codebase->properties_to_rename) {
|
||||
return;
|
||||
}
|
||||
|
||||
$declaring_property_id = strtolower($declaring_property_class) . '::$' . $prop_name;
|
||||
|
||||
foreach ($codebase->properties_to_rename as $original_property_id => $new_property_name) {
|
||||
if ($declaring_property_id === $original_property_id) {
|
||||
$file_manipulations = [
|
||||
new FileManipulation(
|
||||
(int)$stmt->name->getAttribute('startFilePos'),
|
||||
(int)$stmt->name->getAttribute('endFilePos') + 1,
|
||||
$new_property_name
|
||||
)
|
||||
];
|
||||
|
||||
FileManipulationBuffer::add(
|
||||
$file_path,
|
||||
$file_manipulations
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function getExpandedPropertyType(
|
||||
Codebase $codebase,
|
||||
string $fq_class_name,
|
||||
|
@ -70,6 +70,7 @@ use Psalm\Node\Expr\BinaryOp\VirtualShiftRight;
|
||||
use Psalm\Node\Expr\VirtualAssign;
|
||||
use Psalm\Plugin\EventHandler\Event\AddRemoveTaintsEvent;
|
||||
use Psalm\Storage\Assertion\Falsy;
|
||||
use Psalm\Storage\FileStorage;
|
||||
use Psalm\Type;
|
||||
use Psalm\Type\Atomic\TArray;
|
||||
use Psalm\Type\Atomic\TFalse;
|
||||
@ -491,71 +492,21 @@ class AssignmentAnalyzer
|
||||
);
|
||||
}
|
||||
|
||||
if ($assign_var instanceof PhpParser\Node\Expr\Variable) {
|
||||
self::analyzeAssignmentToVariable(
|
||||
if (self::analyzeAssignment(
|
||||
$assign_var,
|
||||
$statements_analyzer,
|
||||
$codebase,
|
||||
$assign_var,
|
||||
$assign_value,
|
||||
$assign_value_type,
|
||||
$var_id,
|
||||
$context
|
||||
);
|
||||
} elseif ($assign_var instanceof PhpParser\Node\Expr\List_
|
||||
|| $assign_var instanceof PhpParser\Node\Expr\Array_
|
||||
) {
|
||||
self::analyzeDestructuringAssignment(
|
||||
$statements_analyzer,
|
||||
$codebase,
|
||||
$assign_var,
|
||||
$assign_value,
|
||||
$assign_value_type,
|
||||
$context,
|
||||
$doc_comment,
|
||||
$extended_var_id,
|
||||
$var_comments,
|
||||
$removed_taints
|
||||
);
|
||||
} elseif ($assign_var instanceof PhpParser\Node\Expr\ArrayDimFetch) {
|
||||
ArrayAssignmentAnalyzer::analyze(
|
||||
$statements_analyzer,
|
||||
$assign_var,
|
||||
$context,
|
||||
$assign_value,
|
||||
$assign_value_type
|
||||
);
|
||||
} elseif ($assign_var instanceof PhpParser\Node\Expr\PropertyFetch) {
|
||||
self::analyzePropertyAssignment(
|
||||
$statements_analyzer,
|
||||
$codebase,
|
||||
$assign_var,
|
||||
$context,
|
||||
$assign_value,
|
||||
$assign_value_type,
|
||||
$var_id
|
||||
);
|
||||
} elseif ($assign_var instanceof PhpParser\Node\Expr\StaticPropertyFetch &&
|
||||
$assign_var->class instanceof PhpParser\Node\Name
|
||||
) === false
|
||||
) {
|
||||
if (ExpressionAnalyzer::analyze($statements_analyzer, $assign_var, $context) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($context->check_classes) {
|
||||
if (StaticPropertyAssignmentAnalyzer::analyze(
|
||||
$statements_analyzer,
|
||||
$assign_var,
|
||||
$assign_value,
|
||||
$assign_value_type,
|
||||
$context
|
||||
) === false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($var_id) {
|
||||
$context->vars_possibly_in_scope[$var_id] = true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($var_id && isset($context->vars_in_scope[$var_id])) {
|
||||
@ -652,6 +603,93 @@ class AssignmentAnalyzer
|
||||
return $assign_value_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<VarDocblockComment> $var_comments
|
||||
* @param list<string> $removed_taints
|
||||
* @return null|false
|
||||
*/
|
||||
private static function analyzeAssignment(
|
||||
\PhpParser\Node\Expr $assign_var,
|
||||
StatementsAnalyzer $statements_analyzer,
|
||||
Codebase $codebase,
|
||||
?\PhpParser\Node\Expr $assign_value,
|
||||
Union $assign_value_type,
|
||||
?string $var_id,
|
||||
Context $context,
|
||||
?\PhpParser\Comment\Doc $doc_comment,
|
||||
?string $extended_var_id,
|
||||
array $var_comments,
|
||||
array $removed_taints
|
||||
): ?bool {
|
||||
if ($assign_var instanceof PhpParser\Node\Expr\Variable) {
|
||||
self::analyzeAssignmentToVariable(
|
||||
$statements_analyzer,
|
||||
$codebase,
|
||||
$assign_var,
|
||||
$assign_value,
|
||||
$assign_value_type,
|
||||
$var_id,
|
||||
$context
|
||||
);
|
||||
} elseif ($assign_var instanceof PhpParser\Node\Expr\List_
|
||||
|| $assign_var instanceof PhpParser\Node\Expr\Array_
|
||||
) {
|
||||
self::analyzeDestructuringAssignment(
|
||||
$statements_analyzer,
|
||||
$codebase,
|
||||
$assign_var,
|
||||
$assign_value,
|
||||
$assign_value_type,
|
||||
$context,
|
||||
$doc_comment,
|
||||
$extended_var_id,
|
||||
$var_comments,
|
||||
$removed_taints
|
||||
);
|
||||
} elseif ($assign_var instanceof PhpParser\Node\Expr\ArrayDimFetch) {
|
||||
ArrayAssignmentAnalyzer::analyze(
|
||||
$statements_analyzer,
|
||||
$assign_var,
|
||||
$context,
|
||||
$assign_value,
|
||||
$assign_value_type
|
||||
);
|
||||
} elseif ($assign_var instanceof PhpParser\Node\Expr\PropertyFetch) {
|
||||
self::analyzePropertyAssignment(
|
||||
$statements_analyzer,
|
||||
$codebase,
|
||||
$assign_var,
|
||||
$context,
|
||||
$assign_value,
|
||||
$assign_value_type,
|
||||
$var_id
|
||||
);
|
||||
} elseif ($assign_var instanceof PhpParser\Node\Expr\StaticPropertyFetch &&
|
||||
$assign_var->class instanceof PhpParser\Node\Name
|
||||
) {
|
||||
if (ExpressionAnalyzer::analyze($statements_analyzer, $assign_var, $context) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($context->check_classes) {
|
||||
if (StaticPropertyAssignmentAnalyzer::analyze(
|
||||
$statements_analyzer,
|
||||
$assign_var,
|
||||
$assign_value,
|
||||
$assign_value_type,
|
||||
$context
|
||||
) === false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($var_id) {
|
||||
$context->vars_possibly_in_scope[$var_id] = true;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function assignTypeFromVarDocblock(
|
||||
StatementsAnalyzer $statements_analyzer,
|
||||
PhpParser\Node $stmt,
|
||||
|
Loading…
x
Reference in New Issue
Block a user