@@ -80,28 +80,45 @@ public void resolve(Collection<TwigTypeContainer> targets, Collection<TwigTypeCo
8080 }
8181
8282 private static void attachFormFields (@ Nullable MethodReference methodReference , @ NotNull Collection <TwigTypeContainer > targets ) {
83- if (methodReference != null && PhpElementsUtil .isMethodReferenceInstanceOf (
83+ if (methodReference == null ) {
84+ return ;
85+ }
86+
87+ int index = -1 ;
88+
89+ if (PhpElementsUtil .isMethodReferenceInstanceOf (
8490 methodReference ,
8591 new MethodMatcher .CallToSignature ("\\ Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ Controller" , "createForm" ),
8692 new MethodMatcher .CallToSignature ("\\ Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ ControllerTrait" , "createForm" ),
8793 new MethodMatcher .CallToSignature ("\\ Symfony\\ Bundle\\ FrameworkBundle\\ Controller\\ AbstractController" , "createForm" ),
8894 new MethodMatcher .CallToSignature ("\\ Symfony\\ Component\\ Form\\ FormFactoryInterface" , "create" )
8995 )) {
90- PsiElement formType = PsiElementUtils .getMethodParameterPsiElementAt (methodReference , 0 );
91- if (formType != null ) {
92- PhpClass phpClass = FormUtil .getFormTypeClassOnParameter (formType );
96+ index = 0 ;
97+ } else if (PhpElementsUtil .isMethodReferenceInstanceOf (
98+ methodReference ,
99+ new MethodMatcher .CallToSignature ("\\ Symfony\\ Component\\ Form\\ FormFactoryInterface" , "createNamed" )
100+ )) {
101+ index = 1 ;
102+ }
93103
94- if ( phpClass == null ) {
95- return ;
96- }
104+ if ( index < 0 ) {
105+ return ;
106+ }
97107
98- Method method = phpClass .findMethodByName ("buildForm" );
99- if (method == null ) {
100- return ;
101- }
108+ PsiElement formType = PsiElementUtils .getMethodParameterPsiElementAt (methodReference , index );
109+ if (formType != null ) {
110+ PhpClass phpClass = FormUtil .getFormTypeClassOnParameter (formType );
102111
103- targets .addAll (getTwigTypeContainer (method , phpClass ));
112+ if (phpClass == null ) {
113+ return ;
104114 }
115+
116+ Method method = phpClass .findMethodByName ("buildForm" );
117+ if (method == null ) {
118+ return ;
119+ }
120+
121+ targets .addAll (getTwigTypeContainer (method , phpClass ));
105122 }
106123 }
107124
0 commit comments