-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
[11.x] Add multiple method signatures for where in PHPDoc block #54304
base: 11.x
Are you sure you want to change the base?
[11.x] Add multiple method signatures for where in PHPDoc block #54304
Conversation
Since function overloading isn't a thing in PHP, I don't think this is the right thing to do. It messes with the IDE's ability to work with named parameters and the position of those parameters. If I see my IDE suggesting 4 different kinds of |
Well, otherwise, it's impossible to know what can be passed to Because, only looking at /**
* Add a basic where clause to the query.
*
* @param \Closure|string|array|\Illuminate\Contracts\Database\Query\Expression $column
* @param mixed $operator
* @param mixed $value
* @param string $boolean
* @return $this
*/
public function where($column, $operator = null, $value = null, $boolean = 'and') the only thing with some certainty is Furthermore, yes, PHP doesn't natively support method overloading, but Laravel clearly does a custom implementation of exactly that, yet, it isn't well documented as such. |
…d types as PHPStan takes the last method signature for checking
We actually do have documentation for it. Its on the laravel website under the database query builder documentation and the syntax is very similar to the collection where method which also has its own documentation. As mentioned earlier, overloading methods isn't possible in PHP unless you do something like what laravel is doing. Because of that, I don't think we should add this. I wouldn't mind a When I'm working and I don't understand a laravel method from the argument names, I open the method code to look at it, and if I still don't understand, I pull up the laravel documentation and search for the method using Cmd + K. I think adding further phpdoc blocks will take away from the simplicity of having one singular place to look up documentation. And if the documentation is out of date, we can just make a pull request to update it: laravel/docs. |
Can you post screenshots of this with Intellisense hover and VSCode hover? If it doesn't work well in both of these, this could make things worse for a large pool of Laravel developers, not better. |
/** | ||
* @method self where(string $column, $value) | ||
* @method self where(string $column, string $operator, $value) | ||
* @method self where(string $column, string $operator, $value, 'and'|'or' $boolean) | ||
* @method self where(\Closure(): mixed) | ||
* @method self where(array<string, mixed> $column) | ||
* @method self where((array{string, 'and'|'or', mixed}|array{string, mixed}|array{column: string, operator?: 'and'|'or', value: mixed})[] $column) | ||
* @method self where(\Closure|string|array|\Illuminate\Contracts\Database\Query\Expression $column, mixed $operator null, mixed $value = null, string $boolean = 'and') | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Last time I checked, which was around 6 months ago, a lot of tooling did not support literals / generics in @method
docblocks.
/** | |
* @method self where(string $column, $value) | |
* @method self where(string $column, string $operator, $value) | |
* @method self where(string $column, string $operator, $value, 'and'|'or' $boolean) | |
* @method self where(\Closure(): mixed) | |
* @method self where(array<string, mixed> $column) | |
* @method self where((array{string, 'and'|'or', mixed}|array{string, mixed}|array{column: string, operator?: 'and'|'or', value: mixed})[] $column) | |
* @method self where(\Closure|string|array|\Illuminate\Contracts\Database\Query\Expression $column, mixed $operator null, mixed $value = null, string $boolean = 'and') | |
*/ | |
/** | |
* @method self where(string $column, $value) | |
* @method self where(string $column, string $operator, $value) | |
* @method self where(string $column, string $operator, $value, string $boolean) | |
* @method self where(\Closure(): mixed) | |
* @method self where(array $column) | |
* @method self where(\Closure|string|array|\Illuminate\Contracts\Database\Query\Expression $column, mixed $operator = null, mixed $value = null, string $boolean = 'and') | |
*/ |
Looks something like this in the IDE: