1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix static method call completion with variable assignment after

This commit is contained in:
Matt Brown 2021-02-15 00:45:39 -05:00
parent bd6efd7cf2
commit b7792ab0b4
2 changed files with 86 additions and 0 deletions

View File

@ -91,6 +91,23 @@ class StaticPropertyAssignmentAnalyzer
$property_id = $fq_class_name . '::$' . $prop_name;
if ($codebase->store_node_types
&& !$context->collect_initializations
&& !$context->collect_mutations
) {
$codebase->analyzer->addNodeReference(
$statements_analyzer->getFilePath(),
$stmt->class,
$fq_class_name
);
$codebase->analyzer->addNodeReference(
$statements_analyzer->getFilePath(),
$stmt->name,
$property_id
);
}
if (!$codebase->properties->propertyExists($property_id, false, $statements_analyzer, $context)) {
if (IssueBuffer::accepts(
new UndefinedPropertyAssignment(

View File

@ -1139,6 +1139,75 @@ class CompletionTest extends \Psalm\Tests\TestCase
$this->assertCount(2, $completion_items);
}
public function testCompletionOnClassInstanceReferenceWithAssignmentAfter(): void
{
$codebase = $this->project_analyzer->getCodebase();
$config = $codebase->config;
$config->throw_exception = false;
$this->addFile(
'somefile.php',
'<?php
namespace Bar;
class Alpha {
public function add() : void {}
}
$alpha = new Alpha;
$alpha->
$a = 5;'
);
$codebase->file_provider->openFile('somefile.php');
$codebase->scanFiles();
$this->analyzeFile('somefile.php', new Context());
$completion_data = $codebase->getCompletionDataAtPosition('somefile.php', new Position(9, 24));
$this->assertSame(['Bar\Alpha', '->', 200], $completion_data);
$completion_items = $codebase->getCompletionItemsForClassishThing($completion_data[0], $completion_data[1]);
$this->assertCount(1, $completion_items);
}
public function testCompletionOnClassStaticReferenceWithAssignmentAfter(): void
{
$codebase = $this->project_analyzer->getCodebase();
$config = $codebase->config;
$config->throw_exception = false;
$this->addFile(
'somefile.php',
'<?php
namespace Bar;
class Alpha {
const FOO = "123";
static function add() : void {}
}
Alpha::
$a = 5;'
);
$codebase->file_provider->openFile('somefile.php');
$codebase->scanFiles();
$this->analyzeFile('somefile.php', new Context());
$completion_data = $codebase->getCompletionDataAtPosition('somefile.php', new Position(8, 23));
$this->assertSame(['Bar\Alpha', '::', 201], $completion_data);
$completion_items = $codebase->getCompletionItemsForClassishThing($completion_data[0], $completion_data[1]);
$this->assertCount(2, $completion_items);
}
public function testNoCrashOnLoopId(): void
{
$codebase = $this->project_analyzer->getCodebase();