[Bug]: Guarded attribute inspectation on tests
Bug description
This "bug" is closely related to #1261 but this time, for tests. We use factories to run feature tests, and this inspection shows up. Factories are a testing feature and, IMO should not contain this kind of inspections.
Plugin version
1.4.1.251
Operating system
MacOS
Steps to reproduce
Create a feature test and, in a test case, just call a factory create model within it:
$user = User::factory()->create(['email_verified_at' => now()]);
where email_verified_at is a guarded attribute
Relevant log output
Factories already should be excluded:
Internally, it checks if factory() method contains \Illuminate\Database\Eloquent\Factories\Factory type in method reference returning type. Maybe you are using different factories library?
Thank you for the response!
I'm using an Eloquent Factory:
And I'm using it in the test like this
I have created a new Laravel project and I don't see this inspection, so it has to be something that I'm using in my project that the plugin doesn't like. It is a fairly new project, so it is weird. If you have any idea I can keep trying things.
I'll keep trying things and let you know if I come up with something.
Just to verify: clicking ->factory() method here brings you to correct factory class, right?
Can you maybe try clearing caches and regenerate helper files, just to check if this is maybe some old index messing things up?
I am having the same problem, and can confirm that having cleared the PHPStorm caches (File > Invalidate Caches > All boxes checked) and regenerating helper code (Laravel > Generate Helper Code) I'm still seeing the warning about guarded attributes:
My plugin version is 1.5.0.252 PHPStorm 2025.2.4
@gorbunov Regarding the information shared about how the plugin makes the decision internally, could this change be the issue?
https://github.com/laravel/framework/commit/2f1f3301bdb4d6ac45f980702e2d2bc544e2d104#diff-c14e536174956829af10331e4333c434b9c4c2722f9e28080aa1e32f0e8ee75a
Specifically, the HasFactory trait now declares @return TFactory in its annotation for the factory() method, not @return \Illuminate\Database\Eloquent\Factories\Factory<static>?
To remove any doubt, the issue in my case isn't being caused by the isVendor() call, which I have removed here:
The IDE understands that the factory() method is returning the correct factory class:
And EloquentProposalFactory is extending the standard Laravel factory:
@gorbunov Regarding the information shared about how the plugin makes the decision internally, could this change be the issue?
Specifically, the
HasFactorytrait now declares@return TFactoryin its annotation for thefactory()method, not@return \Illuminate\Database\Eloquent\Factories\Factory<static>?
Yes, that's possible, phpStorm itself isn't super-good yet in resolving generic types, so maybe we don't get correct type in checks. I'll try to reproduce on fresh Laravel project.