Skip to content

Commit

Permalink
Fix static method call completion with variable assignment after
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Feb 15, 2021
1 parent bd6efd7 commit b7792ab
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ public static function analyze(

$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(
Expand Down
69 changes: 69 additions & 0 deletions tests/LanguageServer/CompletionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,75 @@ static function add() : void {
$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();
Expand Down

0 comments on commit b7792ab

Please sign in to comment.