Skip to content

fix(phpstan): use covariant Model in Scope apply signatures for laravel 13 [3.x]#151

Merged
ManukMinasyan merged 1 commit into3.xfrom
fix/phpstan-scope-covariant-laravel-13
May 8, 2026
Merged

fix(phpstan): use covariant Model in Scope apply signatures for laravel 13 [3.x]#151
ManukMinasyan merged 1 commit into3.xfrom
fix/phpstan-scope-covariant-laravel-13

Conversation

@ManukMinasyan
Copy link
Copy Markdown
Collaborator

Summary

  • Update @param Builder<Model> to @param Builder<covariant Model> on apply() methods of all 4 scope classes
  • Add the matching @param docblock to CustomFieldsActivableScope::apply() (PHPStan flagged it directly despite #[Override])

Why

Laravel 13's Illuminate\Database\Eloquent\Scope::apply() declares Builder<covariant Model>. PHPStan failed in the L13.* - prefer-stable matrix because the invariant Builder<Model> in the implementing classes was incompatible with the covariant parent signature.

Test plan

  • vendor/bin/phpstan analyse --memory-limit=2G → No errors (lockfile on laravel/framework v13.6.0)
  • vendor/bin/pint --test → pass
  • vendor/bin/rector --dry-run → OK
  • CI green on L12.* - prefer-stable and L13.* - prefer-stable matrices

Copilot AI review requested due to automatic review settings May 8, 2026 20:06
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates Eloquent global-scope apply() phpdoc generics to match Laravel 13’s Illuminate\Database\Eloquent\Scope::apply() signature (Builder<covariant Model>), resolving PHPStan/Larastan variance incompatibilities in the Laravel 13 matrix.

Changes:

  • Switch @param Builder<Model> to @param Builder<covariant Model> on apply() across the scope implementations.
  • Add the missing matching @param docblock to CustomFieldsActivableScope::apply() so PHPStan recognizes the covariant signature there as well.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/Models/Scopes/TenantScope.php Updates apply() builder generic to Builder<covariant Model> for Laravel 13 compatibility.
src/Models/Scopes/SortOrderScope.php Updates apply() builder generic to Builder<covariant Model> for Laravel 13 compatibility.
src/Models/Scopes/CustomFieldsActivableScope.php Adds apply() builder generic docblock (Builder<covariant Model>) to satisfy PHPStan on override.
src/Models/Scopes/ActivableScope.php Updates apply() builder generic to Builder<covariant Model> to match Laravel 13’s covariant signature.

@ManukMinasyan ManukMinasyan merged commit a3eb10c into 3.x May 8, 2026
8 checks passed
@ManukMinasyan ManukMinasyan deleted the fix/phpstan-scope-covariant-laravel-13 branch May 8, 2026 20:14
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