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

Trait doesn't preserves Eloquent model generic when running static analysis #36

Open
khalyomede opened this issue Jul 30, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@khalyomede
Copy link
Owner

khalyomede commented Jul 30, 2023

Running PHPStan on this code will return the error below

$shoppingLists = ShoppingList::with("items")
  ->authorOrMemberMatching($user)
  ->when(
    $sort === ViewOrder::UncompletedFirst->value,
    fn (Builder $query): Builder =>
    $query->withCount(["items" => fn (Builder $item): Builder => $item->uncompleted()])
      ->orderByRaw("(items_count > 0) DESC, updated_at DESC")
  )
  ->when(
    $sort !== ViewOrder::UncompletedFirst->value,
    fn (Builder $query): Builder =>
    $query->orderByDesc("updated_at")
  )
  ->paginate(8)
  ->appends([
    "sort" => $sort,
  ]);
Anonymous function should return Illuminate\Database\Eloquent\Builder<Illuminate\Database\Eloquent\Model> but returns  
  Khalyomede\EloquentUuidSlug\Builder\SluggableBuilder<App\Models\ShoppingList>.                                         
  💡 Template type TModelClass on class Illuminate\Database\Eloquent\Builder is not covariant. Learn more:               
    https://phpstan.org/blog/whats-up-with-template-covariant
@khalyomede khalyomede added the enhancement New feature or request label Jul 30, 2023
@khalyomede khalyomede self-assigned this Jul 30, 2023
@khalyomede khalyomede changed the title Static analysis does not preserves Eloquent model Trait doesn't preserves Eloquent model generic when running static analysis Jul 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant