Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

factory method not recognized when using ide-helper:models -M #1589

Open
lk77 opened this issue Sep 25, 2024 · 4 comments
Open

factory method not recognized when using ide-helper:models -M #1589

lk77 opened this issue Sep 25, 2024 · 4 comments
Labels

Comments

@lk77
Copy link

lk77 commented Sep 25, 2024

Versions:

  • ide-helper Version: 3.1.0
  • Laravel Version: 10.48.20
  • PHP Version: 8.1.29

Question:

When i'm using ide-helper:models -M,
the HasFactory::factory() method is not recognized properly,
it works fine without the -M,
somehow, using a mixin cause this line :

 * @method static \Database\Factories\MyFactory factory($count = null, $state = [])

to not be recognized by phpstorm, which cause "polymorphic calls" warnings, because phpstorm expect a generic Factory instance, and not the real factory for the model,

do you have any idea why that is ?

thanks.

@lk77 lk77 added the question label Sep 25, 2024
@khaled-sadek
Copy link
Contributor

khaled-sadek commented Oct 3, 2024

@lk77 Could you let me know if you tried to define your factory implementation? like the following :

/** @use HasFactory<YourModelFactory> */
use HasFactory;

note: don't forget to replace YourModelFactory with the real factory class for this model.

@lk77
Copy link
Author

lk77 commented Oct 14, 2024

I tried that solution, and it does not work,
the only solution i have is to copy paste the "@method static" line from _ide_helper_models.php to the actual model

and it seems it's the same with all static methods like query(), they do not work with the -M option

i guess there is some sort of "precedence" calculation between ide-helper annotations, and laravel annotations, or type inference of some sort

edit :

i removed all annotations from laravel manually in vendor, just to test, and now i can't ctrl+click anymore, but it still does not find the annotations in _ide_helper_models.php

@madebycaliper
Copy link

@khaled-sadek I'm having the same problem and the suggested fix didn't work. I tried the comment hint with the full path to the factory class and just the class alone (e.g. WorkSiteFactory and Database\Factories\WorkSiteFactory).

I just refactored to use mixins and really prefer it, but this makes writing tests incredibly annoying. Might switch back if there's not fix for this. Thanks!

@lk77
Copy link
Author

lk77 commented Nov 8, 2024

@madebycaliper

i have something like that :

/**
 * @method static \Database\Factories\User\UserFactory factory($count = null, $state = [])
 *
 * @mixin IdeHelperUser
 */
class User extends Authenticatable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants