laravel-idea / plugin

Laravel Idea plugin for PhpStorm
https://laravel-idea.com/
165 stars 7 forks source link

Improvements - type hinting on relation scopes :) #66

Open BoyeMagnus opened 4 years ago

BoyeMagnus commented 4 years ago

Hi I've been testing the plugin out for some time now, and have an idea for a nice improvement: There is missing hinting on scopes for relationships. Here I've got a user with a hasMany relation (shifts). The onGoingOrGreaterThanNow scope (on the shift) is not type hinted. (the whereNull value is hintable by the plugin 🥇 ) image

The user model: (no php doc blocks) image

The shift scope: image

Hope it makes sense, and is something that is durable to fix :)

BoyeMagnus commented 4 years ago

The same applies for hinting within scopes. (Can't type hint a scope method within a scope (even if in the same model)) image

(scopeWhereInInterval exists on the same model, as that scope is being declared in)

BoyeMagnus commented 4 years ago

Just found out, that this is related to https://github.com/laravel-idea/plugin/issues/45 However could this not be done without doc blocks?

adelf commented 4 years ago

Hi, Magnus. Have you generated helper code by "Generate Eloquent Helper Code" code generation? It should at least help in the first case. About completing inside scopes... It's possible. I'll try.

BoyeMagnus commented 4 years ago

I've just been using the "barryvdh/laravel-ide-helper" package for generating the annotations.

The reason why it's not finding it on the first, is because I didn't write return annotations. (The IDE think it's a hasMany model, and can't typehint).

Both of the typehinting is available if dirty typehinting is used. The hasmany followed by a scope: image image

The nested scope: image However this wont work, if another where is used before it (the where returns a builder instance, which the IDE will try to typehint) image

Hope this helps :)

Would be nice, if we could skip the Builder|MODELNAME annotation at all! Because some of the places you're not able to really edit the annotation (such as the nested scope)

adelf commented 4 years ago

Would be nice, if we could skip the Builder|MODELNAME annotation at all!

"Generate Eloquent Helper Code" fixes this problem. Also, it generates some pseudo-classes, like "_ShiftQueryBuilder" and I can only programmatically add this "type" to $query variable. This should add all these scope and other methods to completion.

BoyeMagnus commented 4 years ago

"Generate Eloquent Helper Code" fixed the problem 💯 image Would it be possible to link to the correct method (on cmd+click), instead of the helper file?

The nested scope still has problems: (as you mentioned) image

adelf commented 4 years ago

Would it be possible to link to the correct method (on cmd+click), instead of the helper file?

It should be already fixed in PhpStorm 2020.2.

The nested scope still has problems: (as you mentioned)

I'll try to fix that.