Skip to content

Commit 006eb25

Browse files
committed
method/property renaming
1 parent ee236e0 commit 006eb25

File tree

5 files changed

+17
-25
lines changed

5 files changed

+17
-25
lines changed

app/Contexts/AbstractContext.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ abstract class AbstractContext
99
{
1010
public array $children = [];
1111

12-
/**
13-
* Whether this context can be found as last result
14-
* in findAutocompleting method
15-
*/
16-
public bool $findable = false;
12+
public bool $isAbleToAutocomplete = false;
1713

1814
public bool $autocompleting = false;
1915

@@ -67,7 +63,7 @@ public function findAutocompleting(?AbstractContext $context = null)
6763

6864
protected function searchForAutocompleting(AbstractContext $context, $checkCurrent = false)
6965
{
70-
if ($checkCurrent && $context->autocompleting && $context->findable) {
66+
if ($checkCurrent && $context->autocompleting && $context->isAbleToAutocomplete) {
7167
return $context;
7268
}
7369

app/Contexts/MethodCall.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class MethodCall extends AbstractContext
66
{
7-
public bool $findable = true;
7+
public bool $isAbleToAutocomplete = true;
88

99
public ?string $methodName = null;
1010

app/Contexts/ObjectValue.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class ObjectValue extends AbstractContext
66
{
7-
public bool $findable = true;
7+
public bool $isAbleToAutocomplete = true;
88

99
public ?string $className = null;
1010

app/Parsers/AbstractParser.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,14 @@ public function debug(...$messages)
5555
echo $this->indent($message) . PHP_EOL;
5656
}
5757
}
58+
59+
protected function parentNodeIs(Node $node, array $nodeClasses): bool
60+
{
61+
if ($node->getParent() === null) {
62+
return false;
63+
}
64+
65+
return in_array(get_class($node->getParent()), $nodeClasses)
66+
|| $this->parentNodeIs($node->getParent(), $nodeClasses);
67+
}
5868
}

app/Parsers/ArrayCreationExpressionParser.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use App\Contexts\AbstractContext;
66
use App\Contexts\ArrayValue;
77
use Microsoft\PhpParser\MissingToken;
8-
use Microsoft\PhpParser\Node;
98
use Microsoft\PhpParser\Node\Expression\ArrayCreationExpression;
109
use Microsoft\PhpParser\Node\Expression\CallExpression;
1110
use Microsoft\PhpParser\Node\Expression\ObjectCreationExpression;
@@ -17,26 +16,13 @@ class ArrayCreationExpressionParser extends AbstractParser
1716
*/
1817
protected AbstractContext $context;
1918

20-
private function isParentNode(Node $node, array $nodeClasses): bool
21-
{
22-
if ($node->getParent() !== null) {
23-
if (in_array(get_class($node->getParent()), $nodeClasses)) {
24-
return true;
25-
}
26-
27-
return $this->isParentNode($node->getParent(), $nodeClasses);
28-
}
29-
30-
return false;
31-
}
32-
3319
public function parse(ArrayCreationExpression $node)
3420
{
3521
// If array is inside a method, for example Validator::validate(['
36-
// then we need to ignore findable for ArrayValue because
22+
// then we need to ignore isAbleToAutocomplete for ArrayValue because
3723
// priority is given to App\Contexts\MethodCall or App\Contexts\ObjectValue
38-
if (!$this->isParentNode($node, [CallExpression::class, ObjectCreationExpression::class])) {
39-
$this->context->findable = true;
24+
if (!$this->parentNodeIs($node, [CallExpression::class, ObjectCreationExpression::class])) {
25+
$this->context->isAbleToAutocomplete = true;
4026
}
4127

4228
$this->context->autocompleting = $node->closeParenOrBracket instanceof MissingToken;

0 commit comments

Comments
 (0)