Repository navigation
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c2a2053d8a
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| use RonasIT\Support\Traits\EntityControlTrait; | ||
|
|
||
| /** | ||
| * @template TModel of Model |
There was a problem hiding this comment.
Provide a default for the model template
Existing applications that extend BaseRepository without an @extends annotation will now get PHPStan/Larastan missingType.generics errors at stricter analysis levels, rather than transparently retaining Model as claimed. Declare the template with a Model default (and likewise default the two public trait templates) so repositories and direct trait consumers written before this change remain valid.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in c619b68: the template is declared as @template TModel of Model = Model on BaseRepository, EntityControlTrait and SearchTrait. Checked with PHPStan at level 6: a repository without @extends and a class using the traits directly no longer report missingType.generics, and find() is still inferred as Model|null.
…generic Annotate getQuery() and the search query property as Query<TModel>, so custom repository methods get the concrete model from the builder. refs: https://app.clickup.com/t/PRD-3225
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3cea84be21
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| /** | ||
| * @return $this | ||
| */ |
There was a problem hiding this comment.
Bind the model class argument to TModel
When a repository is declared as @extends BaseRepository<User> but its constructor accidentally calls setModel(Post::class), PHPStan accepts the mismatch because $modelClass is untyped, while the newly annotated methods are advertised as returning User even though they return Post. Add an @param class-string<TModel> $modelClass annotation so the generic contract is checked where the runtime model is selected.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 92435f7: setModel() is annotated with @param class-string<TModel> $modelClass. Checked with PHPStan at level 6: setModel(RelationModel::class) in a repository with @extends BaseRepository<TestModel> reports expects class-string<TestModel>, and a repository without @extends accepts any model class.
Repositories and trait consumers without @extends or @use annotations no longer get missingType.generics errors on PHPStan level 6 and above. refs: https://app.clickup.com/t/PRD-3225
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c619b68c01
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| /** @var Query<TModel> */ | ||
| protected $query; |
There was a problem hiding this comment.
Type the public query accessor with TModel
For a repository declared as @extends BaseRepository<User>, this property is typed internally, but getSearchQuery() still declares an unparameterized Query; expressions such as searchQuery($filters)->getSearchQuery()->first() therefore lose User and degrade to the generic bound or mixed type. Add an @return Query<TModel> annotation to the public accessor so callers receive the concrete model type.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 5de5631: getSearchQuery() is annotated with @return Query<TModel>. Checked with PHPStan at level 6: for a repository with @extends BaseRepository<TestModel>, searchQuery([])->getSearchQuery() is Builder<TestModel> and ->first() is TestModel|null; a repository without @extends still gets Model|null.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 92435f7acb
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| * @property Model model | ||
| * @template TModel of Model = Model | ||
| * | ||
| * @property TModel $model |
There was a problem hiding this comment.
Type the declared model property directly
When a generic repository implements a custom method that reads $this->model directly, PHPStan still sees the declared protected $model property as mixed: a class-level @property tag describes a virtual property and does not type an actual property declaration with the same name. Move this annotation to the declaration as @var TModel so this common repository extension point receives the concrete model type.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in bff763b, with one correction to the premise. For classes that extend BaseRepository the property was already typed: PHPStan resolved $this->model as the concrete model with @extends and as Model without it. It was mixed only for classes that use EntityControlTrait directly.
The annotation is now @var TModel on the property declaration. Moving it alone made $this->model an unresolved TModel in BaseRepository subclasses, because the duplicate @property TModel $model tag in SearchTrait took over, so that tag is removed as well; SearchTrait does not read the model.
Checked with PHPStan and Larastan at level 6: $this->model is the concrete model in a subclass with @extends and in a class with @use EntityControlTrait<...>, and Model in a subclass without @extends.
What
@template TModel of Model = ModelonBaseRepository,EntityControlTraitandSearchTrait.@usebindings:BaseRepositorybindsEntityControlTrait<TModel>,EntityControlTraitbindsSearchTrait<TModel>.TModel:create(),updateOrCreate(),firstOrCreate()TModel|null:update(),first(),last(),findBy(),find()Collection<int, TModel>:all(),get(),getByList()LengthAwarePaginator<int, TModel>:getSearchResults()$this: every fluent method with a nativeselfreturn typeQuery<TModel>ongetQuery(),getSearchQuery()and on the$queryproperty, so custom repository methods built on the builder get the concrete model. The malformed@property Query querytag is replaced with a@varannotation.@var TModelon the$modelproperty declaration instead of the class-level@propertytag, so the model is typed for classes that useEntityControlTraitdirectly as well.@param class-string<TModel>onsetModel(), so a model class that does not match@extendsis reported.Why
PHPStan/Larastan did not know the concrete model of a repository, so every result was
Modeland level 5 analysis produced noise on model properties and methods.How to use
Backward compatibility
PHPDoc only: native types and method bodies are unchanged. The template defaults to
Model, so repositories without@extendsand classes that use the traits without@useare still inferred asModeland get nomissingType.genericserrors on PHPStan level 6 and above.How verified
vendor/bin/phpunit: OK (491 tests, 1812 assertions).dumpType(not committed):@extends BaseRepository<TestModel>:$this->queryandgetQuery()->Builder<TestModel>,getSearchQuery()->first()->TestModel|null, a custom method returninggetQuery()->where()->first()as?TestModelhas no errors,setModel()with another model class is reported@extendsand a class using the traits directly: nomissingType.genericserrors,find()->Model|null@extends BaseRepository<Building>:find()/with()->find()->Building|nullcreate()->Buildingget()->Collection<int, Building>getSearchResults()->LengthAwarePaginator<int, Building>->idwith no errors@extends->Modelrefs: #320