laravel-idea / plugin

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

[Feature Request]: Support higher order collection proxies #952

Open caendesilva opened 3 months ago

caendesilva commented 3 months ago

Feature Description

Abstract

Essentially reviving https://github.com/Haehnchen/idea-php-laravel-plugin/issues/149: I think it would be great if the plugin could give IDE support, or at least lessen warnings, when using higher order collection/tap proxies.

Here is what it looks like now:

image

Here is what I would like it to look like image

Implementation idea

I feel like the implementation should not be that hard to at least get rid of the magic property warning? Essentially, if it is known that a symbol contains a collection, and ->map is called directly on that instance, any property directly after the map should assume that the property is accessible (and should not produce a warning, bonus points if it can use generics to lead to the actual property when clicked), and any method called directly after the property called on the map method should be assumed is called back on the original collection.

Here is an illustration breaking it down:

$collection                                 ->map                                    ->name                                                                                                                          ->all();
| This is obviously a collection instance | This initiates a higher order map call | We now (due to it being right after the `map` call) know that this part is forwarded to the collection instance and is valid | Since this is called directly after the property after the `map` call we know that we have returned to the collection instance and can call any method on it |
adelf commented 3 months ago

Hello. Have you tried main menu > Laravel > Helper code parameters > Turn on Collection proxies?

I'm not sure about all cases, but basic ones work.

caendesilva commented 3 months ago

Hello. Have you tried main menu > Laravel > Helper code parameters > Turn on Collection proxies?

I'm not sure about all cases, but basic ones work.

Hey! As I noticed this in a HydePHP project (Which is based on Laravel Zero, and thus does not have access to Eloquent), I am unable to generate helper code as it crashes without Eloquent.

melvinotieno commented 1 month ago

Hello. Have you tried main menu > Laravel > Helper code parameters > Turn on Collection proxies?

I'm not sure about all cases, but basic ones work.

Is this option also available on PHPStorm? I am unable to find that setting

adelf commented 1 month ago

The first checkbox in the dialog window.

Screenshot 2024-05-27 at 18 09 59
melvinotieno commented 1 month ago

Aaah, thanks. I was looking for it under the IDE settings.

On Mon, May 27, 2024 at 5:12 PM Adel @.***> wrote:

The first checkbox in the dialog window. Screenshot.2024-05-27.at.18.09.59.png (view on web) https://github.com/laravel-idea/plugin/assets/2818394/ff6be7ef-3c56-47c5-b9a2-4347ebb0c4bb

— Reply to this email directly, view it on GitHub https://github.com/laravel-idea/plugin/issues/952#issuecomment-2133568978, or unsubscribe https://github.com/notifications/unsubscribe-auth/AK7YA3CHVVPZYOXQYQS4HALZEM5MDAVCNFSM6AAAAABE2E3LBCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMZTGU3DQOJXHA . You are receiving this because you commented.Message ID: @.***>