DEVSENSE / phptools-docs

PHP Tools public content
Apache License 2.0
75 stars 9 forks source link

Wrong type with Laravel factories #500

Open wfern opened 4 months ago

wfern commented 4 months ago

Hello! I don't know if it's pure related to Laravel factories. But if I have two Factories with the same method name the extension get confused and shows the wrong type.

Example: I have a TicketCategory and Event factories with the same method name called: withTickets;

First, get a factory instance of any model and it will show the right type, like: image

But when we call some method of this factory and we have another factory with a method with the same name: image

With "ide-helper" it show the right one but the wrong one too, still causing the error because the methods have the same name but not the same params: image

It's funny because I have other models with the same method name and when i hover the method they keep changing the hint one time show the Event Factory method, other times the Order Factory method, sometimes the RIGHT method, etc...

The complete snippet:

$example = [];

$factory = TicketCategory::factory();

$factory->withTickets($example)->create();
jakubmisek commented 4 months ago

Thank you for the detailed test case.

In this case, the editor is not sure if Factory<TicketCategory> is TicketCategoryFactory or EventFactory (even though it's clear for us, humans). So it gueses.

We can improve it by looking for the @extends Factory<TicketCategory> doc comment tag above class TicketCategoryFactory, if you have that annotation there?

wfern commented 4 months ago

Yes, I think is a nice addition. Thanks!