fix(phpstan): use covariant Model in Scope apply signatures for laravel 13 [3.x]#151
Merged
ManukMinasyan merged 1 commit into3.xfrom May 8, 2026
Merged
Conversation
There was a problem hiding this comment.
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>onapply()across the scope implementations. - Add the missing matching
@paramdocblock toCustomFieldsActivableScope::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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@param Builder<Model>to@param Builder<covariant Model>onapply()methods of all 4 scope classes@paramdocblock toCustomFieldsActivableScope::apply()(PHPStan flagged it directly despite#[Override])Why
Laravel 13's
Illuminate\Database\Eloquent\Scope::apply()declaresBuilder<covariant Model>. PHPStan failed in theL13.* - prefer-stablematrix because the invariantBuilder<Model>in the implementing classes was incompatible with the covariant parent signature.Test plan
vendor/bin/phpstan analyse --memory-limit=2G→ No errors (lockfile onlaravel/framework v13.6.0)vendor/bin/pint --test→ passvendor/bin/rector --dry-run→ OKL12.* - prefer-stableandL13.* - prefer-stablematrices