Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f70dde0

Browse filesBrowse files
Merge pull request #11 from laravel/better-method-call-detection
Better method call detection
2 parents eec73fe + f78306a commit f70dde0
Copy full SHA for f70dde0

File tree

2 files changed

+21
-0
lines changed
Filter options

2 files changed

+21
-0
lines changed

‎app/Contexts/AbstractContext.php

Copy file name to clipboardExpand all lines: app/Contexts/AbstractContext.php
+9
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,15 @@ public function addPropertyToNearestClassDefinition(string $name, $types = [])
129129
}
130130
}
131131

132+
public function nearestClassDefinition()
133+
{
134+
if ($this instanceof ClassDefinition) {
135+
return $this;
136+
}
137+
138+
return $this->parent?->nearestClassDefinition() ?? null;
139+
}
140+
132141
public function searchForProperty(string $name)
133142
{
134143
if ($this instanceof ClassDefinition) {

‎app/Parsers/MemberAccessExpressionParser.php

Copy file name to clipboardExpand all lines: app/Parsers/MemberAccessExpressionParser.php
+12
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Contexts\AbstractContext;
66
use App\Contexts\AssignmentValue;
77
use App\Contexts\MethodCall;
8+
use Microsoft\PhpParser\Node\Expression\CallExpression;
89
use Microsoft\PhpParser\Node\Expression\MemberAccessExpression;
910
use Microsoft\PhpParser\Node\Expression\Variable;
1011
use Microsoft\PhpParser\Node\QualifiedName;
@@ -29,6 +30,17 @@ public function parse(MemberAccessExpression $node)
2930

3031
if ($child instanceof Variable) {
3132
if ($child->getName() === 'this') {
33+
if ($child->getParent()->getParent() instanceof CallExpression) {
34+
// They are calling a method on the current class
35+
$result = $this->context->nearestClassDefinition();
36+
37+
if ($result) {
38+
$this->context->className = $result->className;
39+
}
40+
41+
continue;
42+
}
43+
3244
$propName = $child->getParent()->memberName->getFullText($node->getRoot()->getFullText());
3345

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.