Repository navigation
Exempt names and declarations that Laravel and Nova dictate - #395
Merged
mikebronner merged 3 commits intoOct 5, 2026
Merged
mikebronner merged 3 commits into
mikebronner merged 3 commits into
Conversation
Watson-Branch: #391
RedundantNamespaceSuffix skips a *ServiceProvider class declared
directly in App\Providers. BooleanGetMethodName skips a get{Name}Attribute
accessor on an Eloquent model, using a model test shared with
ModelNamingConventions through the new EloquentModels helper.
PropertyTypeHint skips a property whose nearest ancestor declaration is
untyped and not private. DisallowStaticMembers also skips a static
property no ancestor declares but an ancestor reads as static::$name.
Nova 5's Resource reads static::$model that way and never declares it,
which is why the existing exemption missed it on crossbible.
Fixes: #391
mikebronner
marked this pull request as ready for review
October 5, 2026 18:29
There was a problem hiding this comment.
✅ Approved
Review Summary
- Reviewed the four exemptions, the shared
EloquentModelshelper, the nearest-declaration walk and thestatic::$nameread check inInheritedMembers, plus the fixtures, tests and guidelines. - All 18 acceptance criteria are met. This repo has no CI, so I ran the checks on the PR head:
composer testpassed 2919 tests andcomposer lint:selfexited 0. - Everything in the unit is clean. The model test moved into the helper unchanged, so
ModelNamingConventionsandBooleanGetMethodNamecannot disagree.
Two divergences from the AC wording, both met by intent
- AC 3f/3g, the crossbible miss. The AC describes the shape as overriding a static that a vendor parent declares. Nova 5 declares no
$modeland only readsstatic::$model. Silencing a static that an ancestor reads but never declares is what fixes the miss.$ownCachestill reports, so a static that no ancestor declares or reads still fails. - AC 3a,
$model. The AC lists$modelas covered, but its rule is "nearest ancestor declaration is untyped". Nova 5 has no declaration, sopublic static string $modelis legal and the report has a code fix. Keeping that report satisfies the rule's intent, andinherited-reported.phppins it.
Claims I checked and dropped
- The typed-over-untyped fixture uses a private grandparent. That is the only legal shape: PHP refuses a typed property over a non-private untyped ancestor ("Type of P::$count must be omitted").
protected $a, $b;checks only$a. Slevomat's parent already handles only the first variable, so no report is lost.- The
file_get_contentsread instaticReadsInhas no readability guard. A real run cannot reach that path, because Composer loads an ancestor only from a readable file. - The static-read scan covers the whole ancestor file. A false match needs a second class in the file, which breaks PSR-4.
📋 Non-blocking follow-ups
- None.
Ready for @mikebronner to merge.
…at-laravel-and-nova
mikebronner
deleted the
feature/391-exempt-names-and-declarations-that-laravel-and-nova
branch
October 5, 2026 19:34
mikebronner
added a commit
that referenced
this pull request
Oct 5, 2026
Resolving the conflict in TypeHintsInheritanceTest.php dropped the `);` that ends the last PropertyTypeHint test and left a whitespace-only line. Pest stopped on the ParseError before running any test, and `composer lint` reported the trailing whitespace.
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
Implements #391. Four CleanCode sniffs stop reporting names and declarations that Laravel or Nova dictate. Each exemption is narrow, and every error code is unchanged.
Why
DisallowStaticMembersfired on crossbibleNova 5's
Laravel\Nova\Resourcenever declares$model. It only readsstatic::$model(src/Resource.phpline 250), so each resource must declare it. The existing exemption looks for an ancestor declaration and found none.Evidence from crossbible's own
vendor/bin/phpcsonapp/Nova/Book.php, clean-code 0.2.3: only$modelreportedStaticProperty.$group,$titleand$searchwere already silent, because Nova declares them.DisallowStaticMembersSniff/vendor-resource.phpreproduces it. Withmain's two files swapped in:The fix: a static property that no ancestor declares, but that an ancestor reads as
static::$name, does not report. The sniff tokenises each ancestor's file once per run and caches the result.Two places this reads the AC differently
$ownCacheabove). Without that reading, the crossbible miss cannot be fixed, and the AC requires that fix.PropertyTypeHinton Nova's$model. The AC lists$modelamong the covered properties, but its rule is "the nearest ancestor declaration is untyped". Nova 5 declares no$model, sopublic static string $model = Book::class;is legal, and the report has a code fix. It still reports, andinherited-reported.phppins this.Changes
CleanCode/Helpers/EloquentModels.php: new helper with the model test (an Eloquent parent, or aModelsnamespace segment).ModelNamingConventionsandBooleanGetMethodNameboth use it, so they cannot disagree.RedundantNamespaceSuffix: skips a*ServiceProviderclass with a prefix, declared directly inApp\Providers. The namespace match ignores case.BooleanGetMethodName: skipsget{Name}Attributeon a model class.InheritedMembers: adds the nearest-declaration walk and thestatic::$nameread check. An ancestor whose load throws now counts as unresolvable, so the sniff no longer crashes on it.PropertyTypeHintandDisallowStaticMembersuse those checks.tests/fixtures/_ancestors/: test ancestors, autoloaded through a newautoload-deventry, which is how a consumer's vendor parent loads. CONTRIBUTING.md documents the directory.Removing each exemption fails its own test
skips a *ServiceProvider class declared directly in App\ProvidersAppServiceProvider(line 8) and the restget…Attributeskips a boolean get{Name}Attribute accessor…(both datasets)getHasDetailsAttribute()(line 14) and the restskips a property whose nearest ancestor declaration is untyped…Post::$group(line 15) and the restskips every static a Nova-shaped vendor parent declares or reads…$group,$title,$search)$model)Three guards were also mutation-checked: the declared-ancestor guard in the read check, the
catcharoundclass_exists, and the class-only check for accessors. Each one reddens its test.Acceptance Criteria
Service providers
*ServiceProviderclass with a prefix, declared directly inApp\Providers, is silent. The namespace check ignores case and no base class is required (service-providers.php).PaymentProvider, a bareServiceProvider,App\Providers\Billing\BillingServiceProviderandApp\Services\BillingServicestill report, each with a fixture (service-provider-lookalikes.php).RedundantNamespaceSuffixtests pass unmodified.Eloquent accessors
get{Name}Attributemethod on a model is silent forbool,?booland@return bool.Modelparents and aModelsnamespace segment each have a fixture, with no Laravel app needed. The model test is shared withModelNamingConventions.getHasDetails(),getAttribute()and a lowercasegethasOwnerAttribute()still report.ModelNamingConventionsstill reportsLegacyAttributeAccessoron every skipped accessor, and a test asserts it.Inherited untyped properties
MissingAnyTypeHintandMissingNativeTypeHint, for static and instance properties.Post extends AppResource extends VendorResource, andMember extends User extends Model), with the ancestors loaded through Composer.DisallowStaticMembersis silent on the crossbible-shaped resource, still reports$ownCache, and keeps the typed-static exemption (Labelled).mainand is silent here.Across all three
composer test(2919 passed) andcomposer lint:selfboth exit 0 locally.composer lintalso exits 0.Test Plan
Fixes #391