plugin
plugin copied to clipboard
[Bug]: Model properties in model event listener closures are not detected properly
Bug description
When using model event listener closures, model properties are not detected properly. Code navigation is not working.
Plugin version
11.0.0.251
Operating system
Windows
Steps to reproduce
- Make sure that the helper code is up-to-date by running "Generate Helper Code"
- Add the following code (model event listener closure) to any model, e.g.
\App\Models\User:protected static function boot(): void { parent::boot(); static::updated(function (User $user) { echo $user->email; echo $user->wasChanged('email'); }); } - Try to use code navigation ("Go To" → "Declaration or Usages") for the
emailproperty on$user->email
Result
PhpStorm displays "Cannot find declaration to go to"
Notes
- Model type and property type are detected correctly (see screenshots below)
- Model property suggestion does list the
emailproperty (see screen recording below) - Code navigation is working for the
emailstring on$user->wasChanged('email')(see screen recording below) - The actual implementation of a model event listener closure does not make a difference (e.g. using
static):
instead ofself::updated(static function (User $user) { /* ... */ }static::updated(function (User $user) { /* ... */ }
Screenshots
Screen recording
https://github.com/user-attachments/assets/422ed168-94b7-40d3-9f1b-3aaddd193c41
Relevant log output
It's a known issue. PhpStorm doesn't try to find any other User class implementation if it is already in this file. This code will work correctly in any other file.
We make it working for $this-> calls. I'll try to find a workaround for this case also.
Oh, that makes sense. I'm looking forward to a possible workaround!