added fluent interfaces support
parent
dae3f2576c
commit
3d196ede54
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
class Parent1 {
|
||||
/** @return $this */
|
||||
public function foo() {
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
class Child extends Parent1 {
|
||||
public function bar() {
|
||||
$this->foo()->q
|
||||
}
|
||||
public function qux() {
|
||||
|
||||
}
|
||||
}
|
|
@ -574,7 +574,6 @@ class DefinitionResolver
|
|||
// $this -> Type\this
|
||||
// $myVariable -> type of corresponding assignment expression
|
||||
if ($expr instanceof Node\Expression\Variable || $expr instanceof Node\UseVariableName) {
|
||||
// TODO: this will need to change when fluent interfaces are supported
|
||||
if ($expr->getName() === 'this') {
|
||||
return new Types\Object_(new Fqsen('\\' . $this->getContainingClassFqn($expr)));
|
||||
}
|
||||
|
@ -667,13 +666,27 @@ class DefinitionResolver
|
|||
} else {
|
||||
$classFqn = substr((string)$t->getFqsen(), 1);
|
||||
}
|
||||
$fqn = $classFqn . '->' . $expr->memberName->getText($expr->getFileContents());
|
||||
$add = '->' . $expr->memberName->getText($expr->getFileContents());
|
||||
if ($expr->parent instanceof Node\Expression\CallExpression) {
|
||||
$fqn .= '()';
|
||||
$add .= '()';
|
||||
}
|
||||
$fqn = $classFqn . $add;
|
||||
$def = $this->index->getDefinition($fqn);
|
||||
if ($def !== null) {
|
||||
return $def->type;
|
||||
} else {
|
||||
$classDef = $this->index->getDefinition($classFqn);
|
||||
if ($classDef !== null && is_array($classDef->extends)) {
|
||||
foreach ($classDef->extends as $parent) {
|
||||
$def = $this->index->getDefinition($parent . $add);
|
||||
if ($def !== null) {
|
||||
if ($def->type instanceof Types\This) {
|
||||
return new Types\Object_(new Fqsen('\\' . $classFqn));
|
||||
}
|
||||
return $def->type;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -653,4 +653,31 @@ class CompletionTest extends TestCase
|
|||
)
|
||||
], true), $items);
|
||||
}
|
||||
|
||||
public function testThisReturnValue()
|
||||
{
|
||||
$completionUri = pathToUri(__DIR__ . '/../../../fixtures/completion/this_return_value.php');
|
||||
$this->loader->open($completionUri, file_get_contents($completionUri));
|
||||
$items = $this->textDocument->completion(
|
||||
new TextDocumentIdentifier($completionUri),
|
||||
new Position(10, 19)
|
||||
)->wait();
|
||||
$this->assertEquals(new CompletionList([
|
||||
new CompletionItem(
|
||||
'foo',
|
||||
CompletionItemKind::METHOD,
|
||||
'$this' // Return type of the method
|
||||
),
|
||||
new CompletionItem(
|
||||
'bar',
|
||||
CompletionItemKind::METHOD,
|
||||
'mixed' // Return type of the method
|
||||
),
|
||||
new CompletionItem(
|
||||
'qux',
|
||||
CompletionItemKind::METHOD,
|
||||
'mixed' // Return type of the method
|
||||
)
|
||||
], true), $items);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue