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

PHPStan doesn't know the return type of QueryBuilder #953

Closed
genesiscz opened this issue Jun 30, 2024 · 2 comments
Closed

PHPStan doesn't know the return type of QueryBuilder #953

genesiscz opened this issue Jun 30, 2024 · 2 comments

Comments

@genesiscz
Copy link

genesiscz commented Jun 30, 2024

Hello,

I am not sure if I am missing something but let me explain.

When I do

        $formFields = FormField::query()->where("id", $formField->id);
        $a = $formFields->firstOrFail();
        \PHPStan\dumpType($a);

        $b = QueryBuilder::for(FormField::query()->where('id', $formField->id))
            ->allowedIncludes(['formFieldSelectItems'])
            ->get();

        \PHPStan\dumpType($b);

I recieve

 45     Dumped type: App\Models\Forms\FormField                                                                                                                                                            
  51     Dumped type: Illuminate\Database\Eloquent\Collection<int, Illuminate\Database\Eloquent\Model>       

I feel like the collection should be automatically inferred or somehow working without PHPDocs, shouldn't it?
I have this line in FormField:

@method static Builder<FormField>|FormField query()

Am I missing something or wasn't this thought of ?

Also, I think that the QueryBuilder should be generic in the first place, shouldn't be?

@AlexVanderbist
Copy link
Member

Hey, you're right! I was looking into this issue further and came across this fix that was recently tagged for phpstan and Builder objects. Can you check if this solves your issue? larastan/larastan#2032

@AlexVanderbist
Copy link
Member

Closing this for now. Feel free to open a new issue referencing this one if the issue is still relevant. Thanks!

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

No branches or pull requests

2 participants