1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-02 09:37:59 +01:00

Delete code of replacing variable method_id

The main task for deleting:
```
$method_id = new MethodIdentifier(
    $fq_class_name,
    '__callstatic',
);
```

List of resolved problems:
```
1) Psalm\Tests\MagicMethodAnnotationTest::testNoSealAllMethodsWithStatic
Failed asserting that exception of type "Psalm\Exception\CodeException" is thrown.

2) Psalm\Tests\MagicMethodAnnotationTest::testSealAllMethodsWithoutFooWithStatic
Failed asserting that exception of type "Psalm\Exception\CodeException" is thrown.

3) Psalm\Tests\MagicMethodAnnotationTest::testInvalidCode with data set "inheritSealedMethodsWithStatic"
Failed asserting that exception of type "Psalm\Exception\CodeException" is thrown.
```

Appended problem by that fix:
```
1) MagicMethodAnnotationTest::testSealAllMethodsSetToFalseWithStatic
Psalm\Exception\CodeException: UndefinedMagicMethod - somefile.php:8:15 - Magic method B::foo does not exist
```
This commit is contained in:
Ivan Sidorov 2024-01-31 16:59:28 +00:00
parent df2067dd74
commit 0ba346c5a0
3 changed files with 10 additions and 39 deletions

View File

@ -111,8 +111,9 @@ final class MethodAnalyzer extends FunctionLikeAnalyzer
}
$original_method_id = $method_id;
$with_pseudo = true;
$method_id = $codebase_methods->getDeclaringMethodId($method_id);
$method_id = $codebase_methods->getDeclaringMethodId($method_id, $with_pseudo);
if (!$method_id) {
if (InternalCallMapHandler::inCallMap((string) $original_method_id)) {
@ -122,7 +123,7 @@ final class MethodAnalyzer extends FunctionLikeAnalyzer
throw new LogicException('Declaring method for ' . $original_method_id . ' should not be null');
}
$storage = $codebase_methods->getStorage($method_id);
$storage = $codebase_methods->getStorage($method_id, $with_pseudo);
if (!$storage->is_static) {
if ($self_call) {

View File

@ -40,6 +40,8 @@ final class MethodVisibilityAnalyzer
$fq_classlike_name = $method_id->fq_class_name;
$method_name = $method_id->method_name;
$with_pseudo = true;
if ($codebase_methods->visibility_provider->has($fq_classlike_name)) {
$method_visible = $codebase_methods->visibility_provider->isMethodVisible(
$source,
@ -65,7 +67,7 @@ final class MethodVisibilityAnalyzer
}
}
$declaring_method_id = $codebase_methods->getDeclaringMethodId($method_id);
$declaring_method_id = $codebase_methods->getDeclaringMethodId($method_id, $with_pseudo);
if (!$declaring_method_id) {
if ($method_name === '__construct'
@ -109,7 +111,7 @@ final class MethodVisibilityAnalyzer
return null;
}
$storage = $codebase->methods->getStorage($declaring_method_id);
$storage = $codebase->methods->getStorage($declaring_method_id, $with_pseudo);
$visibility = $storage->visibility;
if ($appearing_method_name

View File

@ -32,12 +32,8 @@ use Psalm\Issue\MixedMethodCall;
use Psalm\Issue\UndefinedClass;
use Psalm\Issue\UndefinedMethod;
use Psalm\IssueBuffer;
use Psalm\Node\Expr\VirtualArray;
use Psalm\Node\Expr\VirtualArrayItem;
use Psalm\Node\Expr\VirtualMethodCall;
use Psalm\Node\Expr\VirtualVariable;
use Psalm\Node\Scalar\VirtualString;
use Psalm\Node\VirtualArg;
use Psalm\Storage\ClassLikeStorage;
use Psalm\Storage\MethodStorage;
use Psalm\Type;
@ -57,7 +53,6 @@ use Psalm\Type\Atomic\TTemplateParam;
use Psalm\Type\Union;
use function array_filter;
use function array_map;
use function array_values;
use function assert;
use function count;
@ -569,6 +564,8 @@ final class AtomicStaticCallAnalyzer
$callstatic_method_exists = $codebase->methods->methodExists($callstatic_id);
$with_pseudo = $callstatic_method_exists;
if (!$naive_method_exists
|| !MethodAnalyzer::isMethodVisible(
$method_id,
@ -680,36 +677,6 @@ final class AtomicStaticCallAnalyzer
return false;
}
}
$array_values = array_map(
static fn(PhpParser\Node\Arg $arg): PhpParser\Node\Expr\ArrayItem => new VirtualArrayItem(
$arg->value,
null,
false,
$arg->getAttributes(),
),
$args,
);
$args = [
new VirtualArg(
new VirtualString((string) $method_id, $stmt_name->getAttributes()),
false,
false,
$stmt_name->getAttributes(),
),
new VirtualArg(
new VirtualArray($array_values, $stmt->getAttributes()),
false,
false,
$stmt->getAttributes(),
),
];
$method_id = new MethodIdentifier(
$fq_class_name,
'__callstatic',
);
} elseif ($found_method_and_class_storage
&& ($config->use_phpdoc_method_without_magic_or_parent || $class_storage->parent_class)
) {
@ -797,6 +764,7 @@ final class AtomicStaticCallAnalyzer
new CodeLocation($statements_analyzer, $stmt),
$statements_analyzer->getSuppressedIssues(),
$context->calling_method_id,
$with_pseudo,
);
if (!$does_method_exist) {