From ee53c5795265f46e6cc37dc49d3dd077da5e94b8 Mon Sep 17 00:00:00 2001 From: orklah Date: Tue, 17 Aug 2021 23:11:28 +0200 Subject: [PATCH] add back alter blocks but remove renaming the $stmt->class part when it's a variable --- .../Fetch/ClassConstFetchAnalyzer.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ClassConstFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ClassConstFetchAnalyzer.php index 4b8b8c2f5..13e5be4f8 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ClassConstFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ClassConstFetchAnalyzer.php @@ -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