From 766effb0db58e7a6e5ec5be2381598fea4a4a4c3 Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Fri, 6 Mar 2020 13:48:59 -0500 Subject: [PATCH] Improve accuracy of diff generation --- .../Expression/Call/MethodCallAnalyzer.php | 5 +++- .../Expression/Call/StaticCallAnalyzer.php | 5 +++- src/Psalm/Internal/Codebase/Methods.php | 23 +++++++++++++------ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/MethodCallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/MethodCallAnalyzer.php index cd06d74e9fb..500483b27e3 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/MethodCallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/MethodCallAnalyzer.php @@ -730,7 +730,10 @@ private static function analyzeAtomicCall( $method_id, $context->calling_function_id, $codebase->collect_references ? new CodeLocation($source, $stmt->name) : null, - $statements_analyzer, + !$context->collect_initializations + && !$context->collect_mutations + ? $statements_analyzer + : null, $statements_analyzer->getFilePath() ) || !MethodAnalyzer::isMethodVisible( diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php index bebb751f6b1..61cb8ed40e1 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php @@ -443,7 +443,10 @@ public static function analyze( $callstatic_id, $context->calling_function_id, $codebase->collect_references ? new CodeLocation($source, $stmt->name) : null, - $statements_analyzer, + !$context->collect_initializations + && !$context->collect_mutations + ? $statements_analyzer + : null, $statements_analyzer->getFilePath() )) { if (isset($class_storage->pseudo_static_methods[$method_name_lc])) { diff --git a/src/Psalm/Internal/Codebase/Methods.php b/src/Psalm/Internal/Codebase/Methods.php index 6f856db6950..58cb4f93390 100644 --- a/src/Psalm/Internal/Codebase/Methods.php +++ b/src/Psalm/Internal/Codebase/Methods.php @@ -126,13 +126,6 @@ public function methodExists( return false; } - if ($source && $fq_class_name !== strtolower((string) $source->getFQCLN())) { - $this->file_reference_provider->addFileReferenceToClass( - $source->getFilePath(), - $fq_class_name - ); - } - if (isset($class_storage->declaring_method_ids[$method_name])) { $declaring_method_id = $class_storage->declaring_method_ids[$method_name]; @@ -140,6 +133,15 @@ public function methodExists( return true; } + $declaring_fq_class_name = strtolower($declaring_method_id->fq_class_name); + + if ($source && $declaring_fq_class_name !== strtolower((string) $source->getFQCLN())) { + $this->file_reference_provider->addFileReferenceToClass( + $source->getFilePath(), + $declaring_fq_class_name + ); + } + if ((string) $method_id !== (string) $declaring_method_id && $class_storage->user_defined && isset($class_storage->potential_declaring_method_ids[$method_name]) @@ -235,6 +237,13 @@ public function methodExists( return true; } + if ($source && $fq_class_name !== strtolower((string) $source->getFQCLN())) { + $this->file_reference_provider->addFileReferenceToClass( + $source->getFilePath(), + $fq_class_name + ); + } + if ($class_storage->abstract && isset($class_storage->overridden_method_ids[$method_name])) { return true; }