Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/Contexts/AbstractContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ public function addPropertyToNearestClassDefinition(string $name, $types = [])
}
}

public function nearestClassDefinition()
{
if ($this instanceof ClassDefinition) {
return $this;
}

return $this->parent?->nearestClassDefinition() ?? null;
}

public function searchForProperty(string $name)
{
if ($this instanceof ClassDefinition) {
Expand Down
12 changes: 12 additions & 0 deletions app/Parsers/MemberAccessExpressionParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Contexts\AbstractContext;
use App\Contexts\AssignmentValue;
use App\Contexts\MethodCall;
use Microsoft\PhpParser\Node\Expression\CallExpression;
use Microsoft\PhpParser\Node\Expression\MemberAccessExpression;
use Microsoft\PhpParser\Node\Expression\Variable;
use Microsoft\PhpParser\Node\QualifiedName;
Expand All @@ -29,6 +30,17 @@ public function parse(MemberAccessExpression $node)

if ($child instanceof Variable) {
if ($child->getName() === 'this') {
if ($child->getParent()->getParent() instanceof CallExpression) {
// They are calling a method on the current class
$result = $this->context->nearestClassDefinition();

if ($result) {
$this->context->className = $result->className;
}

continue;
}

$propName = $child->getParent()->memberName->getFullText($node->getRoot()->getFullText());

$result = $this->context->searchForProperty($propName);
Expand Down