phptools-docs
phptools-docs copied to clipboard
Wrong type with Laravel factories
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:
But when we call some method of this factory and we have another factory with a method with the same name:
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:
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();
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?
Yes, I think is a nice addition. Thanks!