Skip to content

Error when running PHPstan on a Model using QueriesFlaggedEnums trait #273

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

Closed
pacoorozco opened this issue Jul 6, 2022 · 3 comments
Closed

Comments

@pacoorozco
Copy link

pacoorozco commented Jul 6, 2022

I'm using the QueriesFlaggedEnums trait in the Badge model. I've defined a local scope which use the hasAnyFlags(). PHPstan raises an error like:

------ ---------------------------------------------------------------------------------- 
  Line   app/Models/Badge.php                                                              
 ------ ---------------------------------------------------------------------------------- 
  109    Call to an undefined method Illuminate\Database\Eloquent\Builder::hasAnyFlags().  
 ------ ---------------------------------------------------------------------------------- 

This is the Laravel code:

107:    public function scopeWithActuatorsIn(Builder $query, array $actuators): Builder
107:    {
109:        return $query
110:            ->where('active', true)
111:            ->hasAnyFlags('actuators', $actuators);
112:    }

Someone was suggesting the use of PHP generics in order to avoid the problem. I've tried this approach using an stub file but nothing has changed.

The code could be find here: https://github.com/pacoorozco/gamify-laravel

Related to: larastan/larastan#1307

@spawnia
Copy link
Collaborator

spawnia commented Jul 6, 2022

Have you tried adding generics to your own code? I think we should try and add them to this library too, but without having them in your code there is nothing to work with. This library cannot magically conjure up a connection from any Builder object to one where the generic TModel is provided.

@pacoorozco
Copy link
Author

You have shared a very good point. I didn't think about it, let me try it. 🧑‍🏭

@spawnia
Copy link
Collaborator

spawnia commented Feb 14, 2024

Closing, as I no longer plan to develop this library further - see #332.

@spawnia spawnia closed this as not planned Won't fix, can't repro, duplicate, stale Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants