Skip to content

Commit 68f481b

Browse files
committed
fix support resolving controller methods ending with "Action"
1 parent 0f079f7 commit 68f481b

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/main/java/fr/adrienbrault/idea/symfony2plugin/routing/RouteHelper.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,20 @@ public static PsiElement[] getMethodsOnControllerShortcut(@NotNull Project proje
168168
String methodName = controllerName.substring(controllerName.lastIndexOf("::") + 2);
169169

170170
Method method = PhpElementsUtil.getClassMethod(project, className, methodName);
171-
return method != null ? new PsiElement[] {method} : new PsiElement[0];
171+
172+
Collection<Method> methods = new HashSet<>();
173+
if (method != null) {
174+
methods.add(method);
175+
}
176+
177+
if (!methodName.toLowerCase().endsWith("action")) {
178+
Method methodAction = PhpElementsUtil.getClassMethod(project, className, methodName + "Action");
179+
if (methodAction != null) {
180+
methods.add(methodAction);
181+
}
182+
}
183+
184+
return methods.toArray(new PsiElement[0]);
172185

173186
} else if(controllerName.contains(":")) {
174187
// AcmeDemoBundle:Demo:hello

src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/routing/RouteHelperTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ public void testGetMethodsOnControllerShortcutForControllerAsInvokeAction() {
447447
"{\n" +
448448
" public function __invoke() {}\n" +
449449
" public function barAction() {}\n" +
450+
" public function fooAction() {}\n" +
450451
"}\n"
451452
);
452453

@@ -458,6 +459,9 @@ public void testGetMethodsOnControllerShortcutForControllerAsInvokeAction() {
458459

459460
targets = RouteHelper.getMethodsOnControllerShortcut(getProject(), "Foobar\\Bar::barAction");
460461
assertEquals("barAction", ((Method) targets[0]).getName());
462+
463+
targets = RouteHelper.getMethodsOnControllerShortcut(getProject(), "Foobar\\Bar::foo");
464+
assertEquals("fooAction", ((Method) targets[0]).getName());
461465
}
462466

463467
/**

0 commit comments

Comments
 (0)