From 10b807b4f6a8e6c288d67554fb90e49bc5eea005 Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Fri, 6 Mar 2020 13:02:34 -0500 Subject: [PATCH] Fix reference generation from methods in --diff mode --- .../Expression/Call/MethodCallAnalyzer.php | 2 +- .../Expression/Call/NewAnalyzer.php | 2 +- .../Expression/Call/StaticCallAnalyzer.php | 4 +-- src/Psalm/Internal/Codebase/Methods.php | 28 +++++++++---------- .../Provider/FileReferenceProvider.php | 1 + 5 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/MethodCallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/MethodCallAnalyzer.php index 4f35d785a3f..cd06d74e9fb 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/MethodCallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/MethodCallAnalyzer.php @@ -730,7 +730,7 @@ private static function analyzeAtomicCall( $method_id, $context->calling_function_id, $codebase->collect_references ? new CodeLocation($source, $stmt->name) : null, - null, + $statements_analyzer, $statements_analyzer->getFilePath() ) || !MethodAnalyzer::isMethodVisible( diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NewAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NewAnalyzer.php index 29064528e2f..60ada719bc1 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NewAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NewAnalyzer.php @@ -395,7 +395,7 @@ public static function analyze( $method_id, $context->calling_function_id, $context->collect_references ? new CodeLocation($statements_analyzer->getSource(), $stmt) : null, - null, + $statements_analyzer, $statements_analyzer->getFilePath() )) { if ($codebase->store_node_types diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php index 1f4065bba80..bebb751f6b1 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/StaticCallAnalyzer.php @@ -424,7 +424,7 @@ public static function analyze( $method_id, $context->calling_function_id, $codebase->collect_references ? new CodeLocation($source, $stmt->name) : null, - null, + $statements_analyzer, $statements_analyzer->getFilePath() ) || !MethodAnalyzer::isMethodVisible( @@ -443,7 +443,7 @@ public static function analyze( $callstatic_id, $context->calling_function_id, $codebase->collect_references ? new CodeLocation($source, $stmt->name) : null, - null, + $statements_analyzer, $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 a9373900376..1b8e5f28fae 100644 --- a/src/Psalm/Internal/Codebase/Methods.php +++ b/src/Psalm/Internal/Codebase/Methods.php @@ -94,7 +94,7 @@ public function methodExists( $calling_function_id = null, CodeLocation $code_location = null, StatementsSource $source = null, - string $file_path = null + string $source_file_path = null ) { $fq_class_name = $method_id->fq_class_name; $method_name = $method_id->method_name; @@ -126,7 +126,7 @@ public function methodExists( return false; } - if ($source && $fq_class_name !== $source->getFQCLN()) { + if ($source && $fq_class_name !== strtolower($source->getFQCLN())) { $this->file_reference_provider->addFileReferenceToClass( $source->getFilePath(), $fq_class_name @@ -150,9 +150,9 @@ public function methodExists( $calling_function_id, $potential_id ); - } elseif ($file_path) { + } elseif ($source_file_path) { $this->file_reference_provider->addFileReferenceToClassMember( - $file_path, + $source_file_path, $potential_id ); } @@ -163,9 +163,9 @@ public function methodExists( $calling_function_id, strtolower((string) $declaring_method_id) ); - } elseif ($file_path) { + } elseif ($source_file_path) { $this->file_reference_provider->addFileReferenceToClassMember( - $file_path, + $source_file_path, strtolower((string) $declaring_method_id) ); } @@ -193,9 +193,9 @@ public function methodExists( $calling_function_id, $interface_method_id_lc ); - } elseif ($file_path) { + } elseif ($source_file_path) { $this->file_reference_provider->addFileReferenceToClassMember( - $file_path, + $source_file_path, $interface_method_id_lc ); } @@ -223,9 +223,9 @@ public function methodExists( $calling_function_id, strtolower((string) $overridden_method_id) ); - } elseif ($file_path) { + } elseif ($source_file_path) { $this->file_reference_provider->addFileReferenceToClassMember( - $file_path, + $source_file_path, strtolower((string) $overridden_method_id) ); } @@ -261,9 +261,9 @@ public function methodExists( $calling_function_id, $potential_id ); - } elseif ($file_path) { + } elseif ($source_file_path) { $this->file_reference_provider->addFileReferenceToMissingClassMember( - $file_path, + $source_file_path, $potential_id ); } @@ -275,9 +275,9 @@ public function methodExists( $calling_function_id, strtolower((string) $method_id) ); - } elseif ($file_path) { + } elseif ($source_file_path) { $this->file_reference_provider->addFileReferenceToMissingClassMember( - $file_path, + $source_file_path, strtolower((string) $method_id) ); } diff --git a/src/Psalm/Internal/Provider/FileReferenceProvider.php b/src/Psalm/Internal/Provider/FileReferenceProvider.php index 66ff5d71114..7d79a8c59ad 100644 --- a/src/Psalm/Internal/Provider/FileReferenceProvider.php +++ b/src/Psalm/Internal/Provider/FileReferenceProvider.php @@ -160,6 +160,7 @@ function ($file_name) { } /** + * @param lowercase-string $fq_class_name_lc * @return void */ public function addFileReferenceToClass(string $source_file, string $fq_class_name_lc)