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

[10.x] Add Generic Docblocks To Builder #857

Merged
merged 2 commits into from
Sep 3, 2024

Conversation

Magnesium38
Copy link
Contributor

This PR adds the Docblocks necessary for static analysis to make a Scout Builder generic over a model based on the Searchable trait.

I ran into the issue when iterating over the search results in a map and static analysis was expecting a model and not a child class of the model.

// Before: Static analysis errors with:
User::search('something')
  ->get()
  ->map(fn (User $user) => 'result'); // expects callable(Illuminate\Database\Eloquent\Model, int): string, Closure(App\Models\User): string given


// After: Static analysis is happy
User::search('')
  ->get()
  ->map(fn (User $user) => 'result'); // passes

This is admittedly my first time setting something like this up, but I looked at how the generics were implemented for the Eloquent Builder and went from there. It's resolved the static analysis issues in the original project and the changes were simple enough that I think it's correct.

It is backed up by some PHPStan type tests that are also newly introduced in this PR. I copied the setup from laravel/framework to adjust the CI process here. However, I would understand if that's not something that is desired out in a PR at this time and so I did all of the test and CI changes as a separate commit that could easily be reverted if desired.

@taylorotwell taylorotwell merged commit 00d0f52 into laravel:10.x Sep 3, 2024
14 checks passed
@Magnesium38 Magnesium38 deleted the add-generics-to-builder branch September 3, 2024 13:46
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

Successfully merging this pull request may close these issues.

2 participants