1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-12 09:19:40 +01:00

add back alter blocks but remove renaming the $stmt->class part when it's a variable

This commit is contained in:
orklah 2021-08-17 23:11:28 +02:00
parent 1bf7447685
commit ee53c57952

View File

@ -467,6 +467,18 @@ class ClassConstFetchAnalyzer
$fq_class_name = $codebase->classlikes->getUnAliasedName($fq_class_name);
}
$moved_class = false;
if ($codebase->alter_code) {
$moved_class = $codebase->classlikes->handleClassLikeReferenceInMigration(
$codebase,
$statements_analyzer,
$stmt->class,
$fq_class_name,
$context->calling_method_id
);
}
// if we're ignoring that the class doesn't exist, exit anyway
if (!$codebase->classlikes->classOrInterfaceOrEnumExists($fq_class_name)) {
return true;
@ -594,6 +606,26 @@ class ClassConstFetchAnalyzer
);
}
$declaring_const_id = strtolower($fq_class_name) . '::' . $stmt->name->name;
if ($codebase->alter_code && !$moved_class) {
foreach ($codebase->class_constant_transforms as $original_pattern => $transformation) {
if ($declaring_const_id === $original_pattern) {
[, $new_const_name] = explode('::', $transformation);
$file_manipulations = [];
$file_manipulations[] = new \Psalm\FileManipulation(
(int) $stmt->name->getAttribute('startFilePos'),
(int) $stmt->name->getAttribute('endFilePos') + 1,
$new_const_name
);
FileManipulationBuffer::add($statements_analyzer->getFilePath(), $file_manipulations);
}
}
}
if ($context->self
&& !$context->collect_initializations
&& !$context->collect_mutations