-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[Bug]: Incorrect type hint in "FromQuery" interface #3484
Comments
It's also allowed to return a query, not only eloquent queries. So changing the return type would limit half of the use cases |
It is not allowed to return |
It has worked for years (as prove the automated tests). If you have suggestions or improvements please provide them via a PR. |
It works because the return type is only declarated in PHPDoc and thus not actually considered by the interpreter. If I change interface FromQuery
{
/**
* @return Builder
*/
public function query();
} to interface FromQuery
{
public function query(): Builder;
} the tests will fail:
I will open a PR. |
I thought you wanted to add that return type, adding the other two on the docblock is fine. Larastan never complains for me (highest level), because I declare the typehint myself in my exports. Merged |
Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?
What version of Laravel Excel are you using?
3.1.35
What version of Laravel are you using?
8.77.0
What version of PHP are you using?
8.1.1
Describe your issue
In your example the result of
\App\Invoice::query()
is used as return value for the\App\Exports\InvoicesExport::query()
method. I'm assuming\App\Invoice
is a Laravel model, so the return value will be an instance of\Illuminate\Database\Eloquent\Builder
.However, in the FromQuery interface the return value of the
query()
method is set to\Illuminate\Database\Query\Builder
. These are two different classes, none of them is a parent of the other and they're not interchangeable.How can the issue be reproduced?
Take the example from the offical docs. Your IDE will warn you and PHPStan will throw an error.
What should be the expected behaviour?
\Illuminate\Database\Eloquent\Builder
should be the return type ofFromQuery::query()
.The text was updated successfully, but these errors were encountered: