From 083b8e26db201d8a527958f7bc667904629a7c4a Mon Sep 17 00:00:00 2001 From: Ivan Sidorov Date: Tue, 6 Feb 2024 07:41:57 +0000 Subject: [PATCH] Add issue message for magic methods --- .../Internal/Analyzer/MethodAnalyzer.php | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/MethodAnalyzer.php b/src/Psalm/Internal/Analyzer/MethodAnalyzer.php index bc4219249..05773590b 100644 --- a/src/Psalm/Internal/Analyzer/MethodAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/MethodAnalyzer.php @@ -13,6 +13,7 @@ use Psalm\Issue\InvalidEnumMethod; use Psalm\Issue\InvalidStaticInvocation; use Psalm\Issue\MethodSignatureMustOmitReturnType; use Psalm\Issue\NonStaticSelfCall; +use Psalm\Issue\UndefinedMagicMethod; use Psalm\Issue\UndefinedMethod; use Psalm\IssueBuffer; use Psalm\StatementsSource; @@ -165,7 +166,8 @@ final class MethodAnalyzer extends FunctionLikeAnalyzer MethodIdentifier $method_id, CodeLocation $code_location, array $suppressed_issues, - ?string $calling_method_id = null + ?string $calling_method_id = null, + bool $with_pseudo = false ): ?bool { if ($codebase->methods->methodExists( $method_id, @@ -176,15 +178,31 @@ final class MethodAnalyzer extends FunctionLikeAnalyzer : null, null, $code_location->file_path, + true, + false, + $with_pseudo, )) { return true; } - if (IssueBuffer::accepts( - new UndefinedMethod('Method ' . $method_id . ' does not exist', $code_location, (string) $method_id), - $suppressed_issues, - )) { - return false; + if ($with_pseudo) { + if (IssueBuffer::accepts( + new UndefinedMagicMethod( + 'Magic method ' . $method_id . ' does not exist', + $code_location, + (string) $method_id, + ), + $suppressed_issues, + )) { + return false; + } + } else { + if (IssueBuffer::accepts( + new UndefinedMethod('Method ' . $method_id . ' does not exist', $code_location, (string) $method_id), + $suppressed_issues, + )) { + return false; + } } return null;