[Bug]: It does not resolve multiple columns to eloquent model select() correctly
Bug description
Nothing major, but it does not resolve the format when you pass multple columns to select method.
I know I can send the columns as array, but the method accepts both.
Plugin version
2024.1
Operating system
MacOS
Steps to reproduce
No response
Relevant log output
No response
Reproduced. As a workaround, I can recommend the Model::query()->select() variant. I'll try to find a way to fix this, but can't promise anything. It's a PhpStorm inspection.
The actual method in Laravel's Query Builder \Illuminate\Database\Query\Builder::select() looks like this:
public function select($columns = ['*'])
{
$this->columns = [];
$this->bindings['select'] = [];
$columns = is_array($columns) ? $columns : func_get_args();
// ...
}
→ see framework/src/Illuminate/Database/Query/Builder.php at 11.x · laravel/framework
If one were to call this method directly, PhpStorm is "smart" enough to notice the call to func_get_args(). PhpStorm will not report a parameter mismatch for these functions (enabled by default in the inspection settings):
You can see this behavior in action in the following example:
Possible Solution
When it comes to solving this issue in Laravel Idea, I guess there could be two options:
- Change the signature of the
select()method in the generated_ide_helper_model_builders_[...].phpfile(s) to:/** * ... * @see \Illuminate\Database\Query\Builder::select * @method $this select(array|mixed $columns = ['*'], ...$arguments) * ... */ - Add an actual dummy implementation for the
select()method. This method could either callfunc_get_args()itself or callparent::select($columns).
Personally, I am in favor of option 1, since it wouldn't require any actual method implementations.
Thank you. We will try option 1.
Thanks for looking into this!
One additional note: The function func_get_args() is used a total of three times in Builder.php:
If the suggested solution works as expected, it would be great to have it implemented for all three instances.
Further thoughts
If multiple @method entries for the same method is a valid thing to do, the following solution could be even better ("more correct"):
/**
* @method $this select(array $columns = ['*'])
* @method $this select(string|mixed $column, string|mixed ...$columns)
*/
Thanks for the fix, everything works as expected! I think this ticket can be closed.