Skip to content

Commit e7840fa

Browse files
committedJul 21, 2019
improve completion support for FQCN::method routes #1231 #1159
1 parent 960d652 commit e7840fa

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed
 

‎src/main/java/fr/adrienbrault/idea/symfony2plugin/util/controller/ControllerIndex.java

+19-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import fr.adrienbrault.idea.symfony2plugin.util.SymfonyBundleUtil;
1414
import fr.adrienbrault.idea.symfony2plugin.util.dict.ServiceUtil;
1515
import fr.adrienbrault.idea.symfony2plugin.util.dict.SymfonyBundle;
16+
import org.apache.commons.lang.StringUtils;
1617
import org.jetbrains.annotations.NotNull;
1718
import org.jetbrains.annotations.Nullable;
1819

@@ -31,6 +32,7 @@ public ControllerIndex(@NotNull Project project) {
3132
this.project = project;
3233
}
3334

35+
@NotNull
3436
public Collection<ControllerAction> getActions() {
3537
Collection<ControllerAction> actions = new ArrayList<>();
3638

@@ -65,8 +67,8 @@ public ControllerAction getControllerActionOnService(String shortcutName) {
6567
return new ControllerAction(serviceId, method);
6668
}
6769

68-
private List<ControllerAction> getActionMethods(SymfonyBundle symfonyBundle) {
69-
70+
@NotNull
71+
private Collection<ControllerAction> getActionMethods(@NotNull SymfonyBundle symfonyBundle) {
7072
String namespaceName = symfonyBundle.getNamespaceName();
7173
if(!namespaceName.startsWith("\\")) {
7274
namespaceName = "\\" + namespaceName;
@@ -81,12 +83,15 @@ private List<ControllerAction> getActionMethods(SymfonyBundle symfonyBundle) {
8183
List<ControllerAction> actions = new ArrayList<>();
8284

8385
for (PhpClass phpClass : PhpIndexUtil.getPhpClassInsideNamespace(this.project, namespaceName)) {
84-
8586
if(!phpClass.getName().endsWith("Controller")) {
8687
continue;
8788
}
8889

8990
String presentableFQN = phpClass.getPresentableFQN();
91+
if(presentableFQN.contains("\\Test\\") || presentableFQN.contains("\\Tests\\") || presentableFQN.startsWith("Test\\") || presentableFQN.startsWith("\\Test\\")) {
92+
continue;
93+
}
94+
9095
if(!presentableFQN.startsWith("\\")) {
9196
presentableFQN = "\\" + presentableFQN;
9297
}
@@ -100,13 +105,22 @@ private List<ControllerAction> getActionMethods(SymfonyBundle symfonyBundle) {
100105

101106
for(Method method : phpClass.getMethods()) {
102107
String methodName = method.getName();
103-
if(methodName.endsWith("Action") && method.getAccess().isPublic()) {
108+
if(!method.getAccess().isPublic() || (method.getName().startsWith("__") && !method.getName().equals("__invoke"))) {
109+
continue;
110+
}
111+
112+
if(methodName.endsWith("Action")) {
104113
String shortcutName = symfonyBundle.getName() + ":" + ns.replace("/", "\\") + ':' + methodName.substring(0, methodName.length() - 6);
105114
actions.add(new ControllerAction(shortcutName, method));
106115
}
107116

117+
String shortcutName = StringUtils.stripStart(phpClass.getPresentableFQN(), "\\");
118+
if(methodName.equals("__invoke")) {
119+
actions.add(new ControllerAction(shortcutName, method));
120+
} else {
121+
actions.add(new ControllerAction(shortcutName + "::" + method.getName(), method));
122+
}
108123
}
109-
110124
}
111125

112126
return actions;

‎src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/config/yaml/YamlCompletionContributorTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public void testRouteControllerActionCompletion() {
8787
"foo:\n" +
8888
" pattern: /hello/{name}\n" +
8989
" defaults: { _controller: <caret> }",
90-
"FooBundle:Foo:foo"
90+
"FooBundle:Foo:foo", "FooBundle\\Controller\\FooController::fooAction", "FooBundle\\Controller\\FooBarController"
9191
);
9292
}
9393

‎src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/config/yaml/fixtures/YamlCompletionContributor.php

+4
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,8 @@ class FooBundle implements \Symfony\Component\HttpKernel\Bundle\Bundle {}
1212
class FooController {
1313
public function fooAction() {}
1414
}
15+
16+
class FooBarController {
17+
public function __invoke() {}
18+
}
1519
}

0 commit comments

Comments
 (0)