Repository navigation
Conversation
added 2 commits
December 2, 2026 16:42
…n level 6 asks for
…and builders in PHPDoc
Member
Author
|
Maintainer decision: held for the next major version. The generics can surface new PHPStan errors in projects that subclass the models (Eloquent's related-model template is invariant), with no runtime change. |
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.
Part of #44, lot A, second of two: generics, in PHPDoc only. Merge the first PR (array value types) before this one: this branch contains its commit. Apart from comments, the only line this PR adds to
srcis oneuseimport.The analysed level stays at 5.
phpstan.neon,phpstan-baseline.neon,.harness.jsonandapi-surface.jsonare untouched. Level 6 cannot be reached without regenerating the baseline (see below).PHPStan error counts
mainWhat changes
Model::belongsTo()andbelongsToMany(),class-string<T>on the$relatedargument of the four relation factories, and a template onsetInstanceConnection().MenuItem::newCollection()and on the sibling collections.CommentBuilder,PostBuilderandTaxonomyBuilderdeclare@template TModel of X = Xand@extends Builder<TModel>. The default keeps a barePostBuildervalid.MetaFields::$builtInClassesandgetMetaClass()now say the classes areclass-string<Meta>.Effect on user projects (static analysis only, reproduced)
A subclass that overrides a typed relation with another related class is now reported, even at level 5. A fixture with
Book extends Postwhoseauthor()returnsbelongsTo(Author::class, ...),Author extends User, gives after this PR (nothing before):(namespaces of
BelongsToshortened). Eloquent's related model template is invariant, so this is the usual consequence of typing relations.covariantwould avoid it but would stopassociate()and similar calls from type checking. Runtime behaviour is unaffected. Please decide whether that is acceptable in a minor release. The same applies in principle to a subclass that redeclares$builtInClasseswith a wider PHPDoc type.What this proves
main(files, identifiers, messages).composer qa:fast: every gate passed.composer qa: exit 0, every gate that ran passed (280 tests passed, 1 incomplete). Rector dry run: nothing to change.pollora/framework(main, 64acf70), whose models extend Colt's: its PHPStan run, with its own configuration, gives the same output with Colt frommain, from the first PR and from this one (a single deprecation notice in all three, unrelated, seen on local PHP 8.5). The CI downstream job only runs the framework's unit tests.What it does not prove
hasMany()/hasOne()(fields,meta,replies,comments,children,Taxonomy::meta,Term::taxonomy,User::posts,User::comments) are declared, but PHPStan cannot check them while those two factories return a raw type. In a throwaway run with the factories templated, none of these declarations raised an error.The 23 errors left, and why
Each of these changes the text or the count of a baseline entry, which
reportUnmatchedIgnoredErrorsturns into a failure. Fixing them needs a regenerated baseline, which is a maintainer's decision.$fillable(Post,Option,PostMeta,TermMeta,UserMeta,CommentMeta),User::$hiddenTermRelationship::$primaryKeyThumbnailMeta::size(),Post::getFormat()scopeNewest()/scopeOldest()return, onPostandUserModel::hasMany(),hasOne()thumbnail,attachment,revisionentriesPost::thumbnail(),attachment(),revision(),Menu::items()Post::parent()MenuItem::parent()entryPost::taxonomies()Model::$termentry disappears,Term::$slugthen occurs twicePost::newCollection()Commands for the maintainer
After both PRs are merged, from an up to date
main:Measured on a throwaway copy with the patch applied: level 6 without any baseline reports 37 errors, none of them
missingType.*orargument.templateType, against 48 baselined occurrences today. The baseline generation andratchet --updatethemselves were not run, nor were the tests with the patch applied. Review the regenerated file before committing it:Term::$sluggoes from 1 to 2 occurrences. The patch also widens the user-facing effect described above toparent(),taxonomies()and the other relations it types.level6.patch