File tree Expand file tree Collapse file tree 3 files changed +59
-7
lines changed
src/fr/adrienbrault/idea/symfony2plugin
tests/fr/adrienbrault/idea/symfony2plugin/tests/form/util Expand file tree Collapse file tree 3 files changed +59
-7
lines changed Original file line number Diff line number Diff line change @@ -188,13 +188,7 @@ public static PhpClass getFormTypeClassOnParameter(@NotNull PsiElement psiElemen
188
188
}
189
189
190
190
if (psiElement instanceof ClassConstantReference ) {
191
- PhpExpression classReference = ((ClassConstantReference ) psiElement ).getClassReference ();
192
- if (classReference instanceof PhpReference ) {
193
- String typeName = ((PhpReference ) classReference ).getFQN ();
194
- if (typeName != null && StringUtils .isNotBlank (typeName )) {
195
- return PhpElementsUtil .getClassInterface (psiElement .getProject (), typeName );
196
- }
197
- }
191
+ return PhpElementsUtil .getClassConstantPhpClass ((ClassConstantReference ) psiElement );
198
192
}
199
193
200
194
return null ;
@@ -506,6 +500,11 @@ public static String getFormParentOfPhpClass(@NotNull PhpClass phpClass) {
506
500
continue ;
507
501
}
508
502
503
+ // Foo::class
504
+ if (firstPsiChild instanceof ClassConstantReference ) {
505
+ return PhpElementsUtil .getClassConstantPhpFqn ((ClassConstantReference ) firstPsiChild );
506
+ }
507
+
509
508
if (!(firstPsiChild instanceof BinaryExpression ) || !PsiElementAssertUtil .isNotNullAndIsElementType (firstPsiChild , PhpElementTypes .CONCATENATION_EXPRESSION )) {
510
509
continue ;
511
510
}
@@ -531,4 +530,22 @@ public static String getFormParentOfPhpClass(@NotNull PhpClass phpClass) {
531
530
532
531
return null ;
533
532
}
533
+
534
+ /**
535
+ * Finds form name by "getName" method
536
+ *
537
+ * Symfony < 2.8
538
+ * 'foo_bar'
539
+ *
540
+ * Symfony 2.8
541
+ * "$this->getName()" -> "$this->getBlockPrefix()" -> return 'datetime';
542
+ *
543
+ * Symfony 3.0
544
+ * "UserProfileType" => "user_profile"
545
+ *
546
+ */
547
+ @ Nullable
548
+ public static String getFormNameOfPhpClass (@ NotNull PhpClass phpClass ) {
549
+ return null ;
550
+ }
534
551
}
Original file line number Diff line number Diff line change @@ -1318,4 +1318,25 @@ public static MethodReference findMethodReferenceOnClassConstant(PsiElement psiE
1318
1318
1319
1319
return null ;
1320
1320
}
1321
+
1322
+ /**
1323
+ * Foo::class to its PhpClass
1324
+ */
1325
+ public static PhpClass getClassConstantPhpClass (@ NotNull ClassConstantReference classConstant ) {
1326
+ String typeName = getClassConstantPhpFqn (classConstant );
1327
+ return typeName != null ? PhpElementsUtil .getClassInterface (classConstant .getProject (), typeName ) : null ;
1328
+ }
1329
+
1330
+ /**
1331
+ * Foo::class to its class fqn include namespace
1332
+ */
1333
+ public static String getClassConstantPhpFqn (@ NotNull ClassConstantReference classConstant ) {
1334
+ PhpExpression classReference = classConstant .getClassReference ();
1335
+ if (!(classReference instanceof PhpReference )) {
1336
+ return null ;
1337
+ }
1338
+
1339
+ String typeName = ((PhpReference ) classReference ).getFQN ();
1340
+ return typeName != null && StringUtils .isNotBlank (typeName ) ? StringUtils .stripStart (typeName , "\\ " ) : null ;
1341
+ }
1321
1342
}
Original file line number Diff line number Diff line change @@ -109,6 +109,20 @@ public void testGetFormParentOfPhpClass() {
109
109
);
110
110
111
111
assertEquals ("My\\ Bar\\ Foo" , FormUtil .getFormParentOfPhpClass (phpClass ));
112
+
113
+ phpClass = PhpPsiElementFactory .createPhpPsiFromText (getProject (), PhpClass .class , "<?php\n " +
114
+ "namespace My\\ Bar {\n " +
115
+ " class Bar() {}\n " +
116
+ " class Foo {\n " +
117
+ " public function getParent()" +
118
+ " {\n " +
119
+ " return Bar::class';\n " +
120
+ " }\n " +
121
+ " }\n " +
122
+ "}"
123
+ );
124
+
125
+ assertEquals ("My\\ Bar\\ Bar" , FormUtil .getFormParentOfPhpClass (phpClass ));
112
126
}
113
127
114
128
public void testGetFormParentOfPhpClassShouldOnlyUseOwnMethod () {
You can’t perform that action at this time.
0 commit comments