1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Add issue message for magic methods

This commit is contained in:
Ivan Sidorov 2024-02-06 07:41:57 +00:00
parent 29b4c38a94
commit 083b8e26db

View File

@ -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;