Fix Scope detection false positives - #499
Merged
calebdw merged 9 commits intoApr 20, 2026
Merged
Conversation
nikspyratos
marked this pull request as draft
April 16, 2026 05:57
calebdw
requested changes
Apr 16, 2026
calebdw
reviewed
Apr 16, 2026
MakeModelAttributesAndScopesProtectedRector
nikspyratos
marked this pull request as ready for review
April 19, 2026 08:46
Contributor
Author
|
Thanks for the feedback! Have updated per the suggestions, let me know if that suffices to resolve the comments. Got around to testing in an affected project and it all worked fine for me, so marking as ready for review properly. |
calebdw
approved these changes
Apr 19, 2026
calebdw
enabled auto-merge (squash)
April 20, 2026 12:33
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.
Closes #498
TL;DR expands scope checking rule analyzers to check for more markers of a local scope:
Illuminate\Database\Eloquent\Builder(new)Existing behaviour to check for the method name being only
scope(#380) is preservedIn draft until I test this in a real repo soon, unless y'all think it's fine with the test coverage
Ah, didn't notice #409 tries to cover the same ground, as there wasn't an issue for it. Mine covers both
ScopeNamedClassMethodToScopeAttributedClassMethodRectorandMakeModelAttributesAndScopesProtectedRector, take your pick on which approach is preferred. There are some differences though:Differences
Name pattern check: PR 409 uses
/^scope.+$/which matches names likescopedItems. This PR checks for scope + uppercase char at position 5, which is more precise to Laravel's convention (onlyscopeXwhere X is uppercase is a valid scope).Type validation strategy: PR 409 checks "if return type OR first param type is missing, assume scope". This branch checks each item independently: an untyped first param is accepted, but a non-Builder/non-void return type still disqualifies the method.
Additional fix: This branch also fixes a pre-existing bug where
str_replace('scope', '', $name)could remove multiple occurrences of "scope" in a method name (e.g. scopeRescope → re instead of rescope). Replaced withsubstr($name, 5).