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

[Bug]: PHPStan invalid return type: Laravel\Scout\Builder #4062

Closed
1 task done
joelharkes opened this issue Jan 2, 2024 · 5 comments
Closed
1 task done

[Bug]: PHPStan invalid return type: Laravel\Scout\Builder #4062

joelharkes opened this issue Jan 2, 2024 · 5 comments
Labels

Comments

@joelharkes
Copy link
Contributor

Is the bug applicable and reproducable to the latest version of the package and hasn't it been reported before?

  • Yes, it's still reproducable

What version of Laravel Excel are you using?

3.1.51

What version of Laravel are you using?

latest

What version of PHP are you using?

8.2.0

Describe your issue

When upgrading to 3.1.51 we get the following PHPStan error:

 ------ ------------------------------------------------------------------------- 
  Line   Domains/PayrollExport/Reports/Transaction/TransactionSheet.php           
 ------ ------------------------------------------------------------------------- 
  61     Method                                                                   
         App\Domains\PayrollExport\Reports\Transaction\TransactionSheet::query()  
         has invalid return type Laravel\Scout\Builder.           

How can the issue be reproduced?

Use PHP Stan + Laravel Excel without laravel Scout.

What should be the expected behaviour?

Not strictly use this type. instead use the laravel Builder interface: Illuminate\Contracts\Database\Query\Builder

@joelharkes joelharkes added the bug label Jan 2, 2024
@joelharkes
Copy link
Contributor Author

Sadly scout doesnt implement the Builder interface :(
https://github.com/guiwoda/laravel-scout/blob/master/src/Builder.php

@joelharkes
Copy link
Contributor Author

joelharkes commented Jan 2, 2024

It would be better to revert Scout Query and instead just call the underlying query builder with ->query in code

@patrickbrouwers
Copy link
Member

patrickbrouwers commented Jan 2, 2024

As far as I understood that wouldn't be the same. I don't see any reason to revert the Scout feature.

Not strictly use this type.

Nothing is "strictly" using this type, it's completly opt in. It's just on the doclbock, which Phpstan sees. Nothing breaks functionally.

I don't see your class in your issue, so I'm just guessing. But it sounds like you don't have a return type in your own code, so PHPstan will probably fallback onto the interface doclbock. If you just add \Illuminate\Contracts\Database\Query\Builder as docblock or return type to your own code (like is intended), Phpstan will pass.

@joelharkes
Copy link
Contributor Author

joelharkes commented Jan 3, 2024

@patrickbrouwers but there is an instance of Scout/Builder in code. how Does your code run if the Scout/Builder class is not available in your vendor packages?

at least laravel scout should be added in composer json as dependency

@patrickbrouwers
Copy link
Member

Instanceof checks don't care about the class actually existing. The rest of the logic only runs if the class exists

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

No branches or pull requests

2 participants