@@ -537,34 +537,30 @@ static public String getArrayKeyValueInsideSignature(PsiElement psiElementInside
537
537
}
538
538
539
539
@ Nullable
540
- static public PsiElement getArrayKeyValueInsideSignaturePsi (Project project , String signature , String methodName , String keyName ) {
541
-
540
+ static private PsiElement getArrayKeyValueInsideSignaturePsi (Project project , String signature , String methodName , String keyName ) {
542
541
PsiElement psiElement = PhpElementsUtil .getPsiElementsBySignatureSingle (project , signature );
542
+
543
543
if (psiElement == null ) {
544
544
return null ;
545
545
}
546
546
547
547
for (MethodReference methodReference : PsiTreeUtil .findChildrenOfType (psiElement , MethodReference .class )) {
548
-
549
548
if (PhpElementsUtil .isEqualMethodReferenceName (methodReference , methodName )) {
550
549
PsiElement [] parameters = methodReference .getParameters ();
551
550
if (parameters .length > 0 && parameters [0 ] instanceof ArrayCreationExpression ) {
552
551
return PhpElementsUtil .getArrayValue ((ArrayCreationExpression ) parameters [0 ], keyName );
553
552
}
554
-
555
553
}
556
554
}
557
555
558
556
return null ;
559
557
}
560
558
561
-
562
559
public static Method [] getImplementedMethods (@ NotNull Method method ) {
563
560
ArrayList <Method > items = getImplementedMethods (method .getContainingClass (), method , new ArrayList <>());
564
561
return items .toArray (new Method [items .size ()]);
565
562
}
566
563
567
-
568
564
private static ArrayList <Method > getImplementedMethods (@ Nullable PhpClass phpClass , @ NotNull Method method , ArrayList <Method > implementedMethods ) {
569
565
if (phpClass == null ) {
570
566
return implementedMethods ;
@@ -1057,33 +1053,6 @@ public static String getMethodParameterTypeHint(@NotNull Method method) {
1057
1053
return classReference .getFQN ();
1058
1054
}
1059
1055
1060
- /**
1061
- * "DateTime", DateTime::class
1062
- */
1063
- @ Nullable
1064
- public static PhpClass resolvePhpClassOnPsiElement (@ NotNull PsiElement psiElement ) {
1065
-
1066
- String dataClass = null ;
1067
- if (psiElement instanceof ClassConstantReference ) {
1068
- PsiElement lastChild = psiElement .getLastChild ();
1069
- // @TODO: FOO::class find PhpElementTyp: toString provides "class"
1070
- if ("class" .equals (lastChild .getText ())) {
1071
- PhpExpression classReference = ((ClassConstantReference ) psiElement ).getClassReference ();
1072
- if (classReference instanceof PhpReference ) {
1073
- dataClass = ((PhpReference ) classReference ).getFQN ();
1074
- }
1075
- }
1076
- } else {
1077
- dataClass = getStringValue (psiElement );
1078
- }
1079
-
1080
- if (dataClass == null ) {
1081
- return null ;
1082
- }
1083
-
1084
- return getClassInterface (psiElement .getProject (), dataClass );
1085
- }
1086
-
1087
1056
/**
1088
1057
* Find first variable declaration in parent scope of a given variable:
1089
1058
*
@@ -1473,18 +1442,37 @@ public static Method[] getMultiResolvedMethod(@NotNull PsiReference psiReference
1473
1442
return new Method [0 ];
1474
1443
}
1475
1444
1445
+ /**
1446
+ * Get first string value of MethodReference; Not index access allowed!
1447
+ * see getMethodReferenceStringValueParameter for resolving value in detail
1448
+ */
1476
1449
@ Nullable
1477
- public static String getFirstArgumentStringValue (@ NotNull MethodReference e ) {
1450
+ public static String getFirstArgumentStringValue (@ NotNull MethodReference methodReference ) {
1478
1451
String stringValue = null ;
1479
1452
1480
- PsiElement [] parameters = e .getParameters ();
1453
+ PsiElement [] parameters = methodReference .getParameters ();
1481
1454
if (parameters .length > 0 && parameters [0 ] instanceof StringLiteralExpression ) {
1482
1455
stringValue = ((StringLiteralExpression ) parameters [0 ]).getContents ();
1483
1456
}
1484
1457
1485
1458
return stringValue ;
1486
1459
}
1487
1460
1461
+ /**
1462
+ * Get resolved string value
1463
+ *
1464
+ * $f->foo('index_0', 'index_1');
1465
+ */
1466
+ @ Nullable
1467
+ public static String getMethodReferenceStringValueParameter (@ NotNull MethodReference methodReference , int parameter ) {
1468
+ PsiElement [] parameters = methodReference .getParameters ();
1469
+ if (parameters .length > parameter ) {
1470
+ return getStringValue (parameters [parameter ]);
1471
+ }
1472
+
1473
+ return null ;
1474
+ }
1475
+
1488
1476
/**
1489
1477
* Visit and collect all variables in given scope
1490
1478
*/
0 commit comments