I use Laravel ORM in my php project and I use a lot of dynamic where in my code. E.g.
UserModel::whereName('Foo')->whereGender(1)->first();
When I use PhpStorm 2016.1 (I think) I can add PHPDoc string to class UserModel
to have the code completion with whereName
and the following whereGender
by doing the following:
/**
* class UserModel
* @method static $this whereName($val)
* @method static $this whereGender($val)
*/
class UserModel {
.......
}
But after I upgrade to the newest version of PhpStorm 2016.2.2. the second method whereGender
will not appear in the code completion list. On JetBrains website I found the 2016.2's new feature
static methods are filtered out from completion lists.
My question is: is there a way to make PhpStorm give the completion whereGender
after the whereName
call?
update:
Completion has to be invoked twice to get static methods. https://youtrack.jetbrains.com/issue/WI-9403#comment=27-1490430
tl;dr:
To see the completion, after you type ->
, you have to press CTRL + SPACE
to see the complete completion list with the static methods. If you are on a mac and it conflicts with your language toggle, change the key combo at:
Preferences->Keymap:
Main Menu->Code->Completion->Basic
While there is a real use case for this, calling a method static/non-static is not common, hence phpstorm dropped it, as mentioned it here: https://blog.jetbrains.com/phpstorm/2016/07/completion-changes-in-phpstorm/
The next completion change was to remove static methods from the completion list when completion is invoked in the context of
$this->
. This change happened as a result of a ticket opened by a user a few years ago. Calling static methods using$this->
is an entirely valid use case but is not that widely used in PHP. While this seemed like a good idea at the time, it’s had the unintended consequences of making writing assertions in PHPUnit a little more painful.
So regardless how you write the phpdoc, phpstorm will not show the static methods as instance methods on the "first invocation". You will need to manually invoke it again (using CTRL+Space) to see it. So this is what the "second invocation" means.
Sources:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With