phptools-docs icon indicating copy to clipboard operation
phptools-docs copied to clipboard

Wrong type with Laravel factories

Open wfern opened this issue 1 year ago • 2 comments

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();

wfern avatar Feb 21 '24 19:02 wfern

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?

jakubmisek avatar Feb 22 '24 19:02 jakubmisek

Yes, I think is a nice addition. Thanks!

wfern avatar Feb 23 '24 18:02 wfern