framework icon indicating copy to clipboard operation
framework copied to clipboard

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

Open shaedrich opened this issue 10 months ago • 4 comments

Looks something like this in the IDE: grafik

shaedrich avatar Jan 22 '25 12:01 shaedrich

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.

hn-seoai avatar Jan 22 '25 14:01 hn-seoai

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.

shaedrich avatar Jan 22 '25 15:01 shaedrich

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.

AndrewMast avatar Jan 23 '25 18:01 AndrewMast

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.

timacdonald avatar Jan 23 '25 21:01 timacdonald