File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change 5
5
use App \Contexts \AbstractContext ;
6
6
use App \Contexts \ArrayValue ;
7
7
use Microsoft \PhpParser \MissingToken ;
8
+ use Microsoft \PhpParser \Node ;
8
9
use Microsoft \PhpParser \Node \Expression \ArrayCreationExpression ;
10
+ use Microsoft \PhpParser \Node \Expression \CallExpression ;
9
11
10
12
class ArrayCreationExpressionParser extends AbstractParser
11
13
{
@@ -14,9 +16,27 @@ class ArrayCreationExpressionParser extends AbstractParser
14
16
*/
15
17
protected AbstractContext $ context ;
16
18
19
+ private function isParentNode (Node $ node , string $ nodeClass ): bool
20
+ {
21
+ if ($ node ->getParent () !== null ) {
22
+ if ($ node ->getParent () instanceof $ nodeClass ) {
23
+ return true ;
24
+ }
25
+
26
+ return $ this ->isParentNode ($ node ->getParent (), $ nodeClass );
27
+ }
28
+
29
+ return false ;
30
+ }
31
+
17
32
public function parse (ArrayCreationExpression $ node )
18
33
{
19
- $ this ->context ->autocompleting = $ node ->closeParenOrBracket instanceof MissingToken;
34
+ // If array is inside a method, for example Validator::validate(['
35
+ // then we need to ignore autocompleting for ArrayValue because
36
+ // priority is given to App\Contexts\MethodCall
37
+ if (!$ this ->isParentNode ($ node , CallExpression::class)) {
38
+ $ this ->context ->autocompleting = $ node ->closeParenOrBracket instanceof MissingToken;
39
+ }
20
40
21
41
return $ this ->context ;
22
42
}
You can’t perform that action at this time.
0 commit comments