1313import fr .adrienbrault .idea .symfony2plugin .util .SymfonyBundleUtil ;
1414import fr .adrienbrault .idea .symfony2plugin .util .dict .ServiceUtil ;
1515import fr .adrienbrault .idea .symfony2plugin .util .dict .SymfonyBundle ;
16+ import org .apache .commons .lang .StringUtils ;
1617import org .jetbrains .annotations .NotNull ;
1718import 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 ;
0 commit comments