Code completion using phpdoc
I am currently evaluating your product and I have to say that I am very pleased with it so far. I am having a problem though with auto completion. I am currently using cakephp and I have a class PostsController that has a property Auth that references the class AuthComponent so before my class declaration I put:
/**
* @property AuthComponent $Auth
*/
so then when in my PostsController I type $this->A the autocomplete will have in the list Auth with AuthComponent as its class. So far so good. Then when I select Auth from the list : $this->Auth-> at this point I do not get any autocomplete options for the methods of the AuthComponent. The authComponent has a method startup that requires 1 paramater, when I type $this->Auth->startup(); with the paramater missing, phpstorm correctly gives me an error "required paramater ... missing". So obviously the IDE knows the methods for the AuthComponent but refuses to autocomplete for me. Looking online I saw that other people who did the same thing as me it worked fine for them so I was wondering if this is some kind of setting I need to fix for this to work.
Please sign in to leave a comment.
I'm having the exact same issue. I'm using PhpStorm 4.0.1
I have the same issue as well, and was wondering if this is considered a bug.. (I hope so). Could a JetBrains moderator please look into this and give a reply?
This issue realy slows down development, as I often have to jumpt to documentation or the class definition to see how the function/var was exactly called again. What is maybe even more enoying is the fact that when I try to access a objects method/property by invoking the basic completion dropdown (Ctrl+Space) the whole program stops responding for a few secconds!
I'm pretty sure I've setup my PHPdocs correctly, but any hints of work arounds are welcome.
Here is some (pseudo) code to illustrate the problem:
/Controller/PagesController.php:
/Model/Page.php
line, and when jumping from that Page to definition I go to the proper file (/Model/Page.php).I'm using CakePHP as well (v2.1.2), but I'm note sure if that does matter in this case.
I also checked if every class name down the chain is unique and find-able by the IDE, this seems to be the case. If I put the cursor at $this->Page and jump to definition (Ctrl+B) I first go to the
Windows 7 x64, PhpSortm 4.0.1
Can anyone provide some standalone test project (very simple one, but it should include all required files) that can be used as a test subject?
You see -- if I just grab the aforementioned 2 classes and remove "extends" part (since I do not have that framework here), it all works fine. Of course -- it is extremely simple, that's why more complex/real project/example is required.
Sure, I'll setup a simple demo project and put it on GitHub. Will that work out for you?
I've put together a simple CakePHP project that illustrates/triggers the code completion issues talked about here.
https://github.com/Maff-/cakephpstorm
In one of the /app/Controller/PagesController.php 's methods try accessing $this->Page.
Other issue is within the View files (e.g. /app/View/Pages/index.ctp)
Hope this helps.
Hi Ruud,
Many thanks for your code example.
1) Apparently it worked OK for me. I mean -- no "unknown method" in /app/Controller/PagesController.php. But, I have faced the issue that code completion will not finish loading (on line 30, when trying to see list of available methods for $this->Page-> )
Apparently, the issue (at least for me) was in the core class Object . That's a bad name to be used in current (well, all) versions of PhpStorm -- it is used internally (see http://youtrack.jetbrains.com/issue/WI-7943 ). When I renamed it to Object222 (some random name) it started to work just fine (code completion popup). In any case -- I saw no errors in that /app/Controller/PagesController.php file.
2) Back to /app/View/Pages/index.ctp -- use different order or parameters -- instead of "@var $this View" use "@var View $this" -- after making this change all warnings were gone.
Thanks about the pointer to PhpStorm's object class. Do you mean I can rename PhpStorm's internal object, or the one used by CakePHP? Because the later would obviously be a pain in the ***, as I would have to modify a lot of core files. Even with proper Refactoring tools, I would have to do this again and again when updating CakePHP. Also all projects I use have CakePHP included as a Git Submodule, this would not have any benefit at all in that case.
is the proper syntaxFor the view files, if I change the order of parameters in the @var line as you suggested the errors wil indeed dissapear, but so will the (partial) auto complete. (Or is this also due to the issue above ?) Altough I can't realy find any resources on this right now, I do believe
So basically it is something that the team is already aware of. I see that there is a will for it to get fixed but not a priority. Maybe all we can do is vote for it to get fixed. I am assuming more people would like this fixed they just don't know that code complete doesnt work because of it. Anyway thanks for taking a look at it. At least you found the problem so thank you for that.
CakePHP one. I doubt that renaming PhpStorm's one will help (may break everything, actually).
Not really. If you look at @param, it has TYPE $NAME Description. But in any case -- both variants work in PhpStorm. I think the problem is that you are trying to re-declare $this as it works fine with normal variables. I believe in v3 or even 2 it worked somehow better than it is now (although I cannot confirm anything for sure as I'm not using this approach myself). There is definitely a ticket (even more than one, I would say) regarding this issue .. but it still was not addressed. If I'll find it I will update this comment.
Vote & comment. Otherwise I think it may get dragged until v5 (or maybe even later).
Few related tickets:
Thanks for all the issue links. I've upvoted the open ones.
It's too bad these issues don't really get that much attention though, instead it seems most user care more/only about the 'Support for framework xxx' feature requests. (at least when looking at the number of votes).
Done and done sir!
i have the same problem with Cakephp, missing the autocomplete, and errors that are not existent, i mean, if i type somthing, and then i corect what i type, the red lines are not dispear, and also phpdoc error is not gone after i make a phpdoc for a method, even if that method has a phpdoc.
this strange things appears after i update from ver 3 to version 4 of phpstorm
Is there a solution for the Model autocomplete and disabling warning for Models?
This solution also doesn't help: http://blog.hwarf.com/2011/08/configure-phpstorm-to-auto-complete.html
And creating this:
class MyController extends AppController {
* @property Mymodel $Mymodel
*/
var $Mymodel;
...
$this->Mymodel->getAll(...)
}
Gives this:
Fatal error: Call to a member function getAll() on a non-object in/example.com/MyController.php on line 124
Anybody knows how to disable these warnings in phpStorm 4 ?
I'm not completely sure what you are trying to do, that causes this PHP error. But it seems not really related to PhpStorm code completion tweaks (correct me if I'm wrong).
You could take a look at an example CakePHP project that I set up for illustrating the issues with code completion in PhpStorm. Please note that at this time with current stable version (4.0.3) these problems are non existing (I should update the readme to reflect that).
https://github.com/Maff-/cakephpstorm
The most important thing to do when setting up your project is to make sure no conflicting class definitions exist.
Excluding the cakephp\app, cakephp\lib\Cake\Test\test_app, cakephp\lib\Cake\Console\Templates\skel folders from your project should do the trick.
Btw, I'm using CakePHP 2.x, I'm not sure if this also aplies for the 1.2/1.3 branches
Ruud Thank you for interest.
I'm trying to solve Model warnings inside Controllers.
I checked pagescontroller inside your github project but I couldn't make it.
I have Signin controller and Signins table.
I need to use this model inside my AdminsController.
Adding property tags doesn't solve my issue
From the "save data" line I get, "Field Signin not found in class AdminsController"
After removing Test folders from project, can you write me steps for model uage warnings?
Sounds like a CakePHP related problem. I think this is what you're trying to do:
http://book.cakephp.org/2.0/en/controllers.html#Controller::$uses
Code is of the top of my head, so it might have some typos or just don't work.
Anyway as this is not related to PhpStorm I suggest that you would continue this discussion in a more appropriate place, like the CakePHP Google Group or Q&A Section
Yes, you code snippet was what I tried.
It seems like I will get this warning more and more :)