diff --git a/src/Psalm/Internal/Codebase/Methods.php b/src/Psalm/Internal/Codebase/Methods.php index ed0c5f5828e..47c8ba1c08d 100644 --- a/src/Psalm/Internal/Codebase/Methods.php +++ b/src/Psalm/Internal/Codebase/Methods.php @@ -119,6 +119,14 @@ public function methodExists( return false; } + $source_file_path = $source ? $source->getFilePath() : $source_file_path; + + $calling_class_name = $source ? $source->getFQCLN() : null; + + if (!$calling_class_name && $calling_method_id) { + $calling_class_name = explode('::', $calling_method_id)[0]; + } + if (isset($class_storage->declaring_method_ids[$method_name])) { $declaring_method_id = $class_storage->declaring_method_ids[$method_name]; @@ -128,15 +136,15 @@ public function methodExists( $declaring_fq_class_name = strtolower($declaring_method_id->fq_class_name); - if ($source && $declaring_fq_class_name !== strtolower((string) $source->getFQCLN())) { + if ($declaring_fq_class_name !== strtolower((string) $calling_class_name)) { if ($calling_method_id) { $this->file_reference_provider->addMethodReferenceToClass( $calling_method_id, $declaring_fq_class_name ); - } else { + } elseif ($source_file_path) { $this->file_reference_provider->addNonMethodReferenceToClass( - $source->getFilePath(), + $source_file_path, $declaring_fq_class_name ); } @@ -237,7 +245,7 @@ public function methodExists( return true; } - if ($source && $fq_class_name !== strtolower((string) $source->getFQCLN())) { + if ($source_file_path && $fq_class_name !== strtolower((string) $calling_class_name)) { if ($calling_method_id) { $this->file_reference_provider->addMethodReferenceToClass( $calling_method_id, @@ -245,7 +253,7 @@ public function methodExists( ); } else { $this->file_reference_provider->addNonMethodReferenceToClass( - $source->getFilePath(), + $source_file_path, $fq_class_name ); }