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

[11.x] Add multiple method signatures for where in PHPDoc block #54304

Draft
wants to merge 3 commits into
base: 11.x
Choose a base branch
from

Conversation

shaedrich
Copy link
Contributor

Looks something like this in the IDE:
grafik

@shaedrich shaedrich changed the title Add multiple method signatures for where in PHPDoc block [11.x] Add multiple method signatures for where in PHPDoc block Jan 22, 2025
@hn-seoai
Copy link
Contributor

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 where methods, I'd think someone messed up with duplicate names across traits.

@shaedrich
Copy link
Contributor Author

shaedrich commented Jan 22, 2025

Well, otherwise, it's impossible to know what can be passed to where() and how unless from experience, since the method signature is incredibly complex. How would you achieve that instead?

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 $column. Everything else can be literally everything. There's no way to tell unless you try it out.

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.

@taylorotwell taylorotwell marked this pull request as draft January 22, 2025 16:39
@AndrewMast
Copy link

Laravel clearly does a custom implementation of exactly that, yet, it isn't well documented as such.

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 @see or something similar, but it would be hard to be consistent, since there are so many methods and since documentation changes often, I think its better to leave it out.

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.

@timacdonald
Copy link
Member

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.

Comment on lines +34 to +42
/**
* @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')
*/
Copy link
Member

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.

Suggested change
/**
* @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')
*/

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

Successfully merging this pull request may close these issues.

4 participants