Code completion does not recognize elements of the parents of parent class

I'm using cakePHP and there is a very annoying problem. My controllers extend the AppController class which extends the Controller class. But when I want to use the Controller class's methods the code completion does not recognize them in my controllers.
The funny thing is that when I use the IDE's Go To Declaration it finds the Controller class immediately.
Any hint what can I do?

Thanks.

10 comments
Comment actions Permalink

Hi Andrij,

not exactly that is my problem.

Here's my skeleton:

class InvoicesController extends AppController{
     function  blahblah(){
          $this->find() =>Code completion does not work!!!
     }
}

class AppController extends Controller{
     function ...
}

class Controller{
     function find(){
          ...
     }

     function etc(){
          ...
     }
}

In my InvoicesController I can't make the code completion work to use the Controller's methods.

0
Comment actions Permalink

Am I right assuming, that it is a BUG and phpstorm is unable to tackle such a problem?

It's a pitty because it's impossible to use this IDE to develop in cakePHP.

0
Comment actions Permalink

I'm not part of JB Team, just ordinary PhpStorm user, and in my opinion (based on what I was able to figure out) it is NOT a bug.

I have downloaded the latest stable CakePHP (v1.3.7) and did test the code you have provided. I cannot find find() method in any parent class (InvoicesController -> AppController -> Controller -> Object).

I'm not familiar with CakePHP so I may be wrong, but I think that the "find()" functionality is exposed during runtime by injecting methods of one class (possibly Model) into another (Controller or its' descendant) trough so-called "behaviors" (maybe something similar to what Yii framework has). If that is correct then I do not see how PhpStorm can pick it up automatically. You may try and resolve this yourself by using PHPDoc @method functionality, but I'm unsure.

0
Comment actions Permalink

You're partly right, because there's no find method() inside those classes, but there are others (redirect, set etc) , that are not picked up by phpstorm. I don't miss the concrete find() method I miss the complete access to the public methods of the class.

If it doesn't work in phpstorm then it can be called a bug or the users should be warned that phpstorm does not support certain farmeworks only on texteditor level.

Probably the file search can't go below certain level of folders and isn't able to pick up the classes there.

0
Comment actions Permalink

http://youtrack.jetbrains.net/issue/WI-760

By definition, the product does not support anything but what we explicitly say it does.

0
Comment actions Permalink

Now I see which problem you are having.

The problem is that there is more than 1 class named AppController in whole CakePHP framework:
2 are in tests folder (which you do not need in production environment anyway)
1 in CakePHP\cake\console\templates\skel\app_controller.php
1 in CakePHP\cake\libs\controller\app_controller.php

If there are more than one class with the same name within the project PhpStorm most likely will fail with properly resolving available methods/properties (at least at the current moment).

For web app I guess you only need the last one.

If you can exclude the rest 3 from the project, then PhpStorm works fine (redirect() & set() and all other methods of Controller class are available for code completion -- tested myself). You can resolve this in 2 ways:
1) If you connect CakePHP via External Libraries (Settings | PHP), then you have to physically delete tests and CakePHP\cake\console folders
2) If CakePHP is part of the project (which I think is most likely to be the case), then just exclude these folders from the project in Settings | Directories.

0
Comment actions Permalink

@Andriy Your help is very appreciated.

0
Comment actions Permalink

Yes, thank you for the answer. This is a very simple solution to the problem but it definetely works.

But it raises other questions as well. In many other cases you have more than one calss under the same name. Is there a way to configure PHPStorm to differentiate between them or for the code completion to show hints from both classes? Using namespace will bring me closer to this?

0
Comment actions Permalink

I'm not using namespaces myself (still doing just fine with traditional approach), but they definitely should help here as they were designed for such (or similar) scenarios. I just do not see how this may help to solve this particular problem (unless you're having completely different framework/project in mind).

Is there a way to configure PHPStorm to differentiate between them or for the code completion to show hints from both classes?

Currently none. But there is a ticket on Issue Tracker regarding this issue which scheduled for 2.1 IIRC (.. or maybe 2.x) ?:|. I think it is a platform limitation which is not that easy/fast to fix as it (codebase) affects every IDE from JB, not just PhpStorm.

0

Please sign in to leave a comment.