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: c08ad6da30
ℹ️ 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".
| * @method $this with(array|string $relations) | ||
| * @method $this withCount(array|string $relations) | ||
| * @method $this force($value = true) | ||
| * @method $this withTrashed($enable = true) | ||
| * @method $this onlyTrashed($enable = true) |
There was a problem hiding this comment.
Preserve service type for search chains
When a typed service uses common fluent SearchTrait calls such as $service->searchQuery(...)->filterBy(...), these declarations do not cover them, so PHPStan falls back to @mixin BaseRepository<TModel> and infers the repository rather than the actual service. At runtime __call() replaces a repository self-return with the service, so the incorrect type prevents chaining service-specific methods; add $this declarations for the remaining self-returning search/filter/order methods and cover one such chain in the inference tests.
Useful? React with 👍 / 👎.
What changes
EntityControlTrait,BaseRepositoryandEntityServicedeclare@template TModel of Model = Model(PHPDoc only, no runtime signature changes). A project binds the model once per class with@extends BaseRepository<Event>/@extends EntityService<Event>.find(),first(),findBy(),last(),update()returnTModel|null;create(),firstOrCreate(),updateOrCreate()returnTModel. Collection-returning methods are untouched.EntityServicecarries the type through@mixin BaseRepository<TModel>and declares@method $thisforwith(),withCount(),force(),withTrashed(),onlyTrashed(), so$service->with(...)->find()resolves to the bound model and the chain stays typed as the service.BaseRequest::loadRouteEntity(). A new protected method with a method-level template, meant to be called frominit(): resolves the service, applies relations, finds the model by a route parameter (idby default) exactly once, and throwsNotFoundHttpExceptionwith the:entity does not exist.message (translatable through the project JSON file) when the parameter is missing or no row matches. The result is typed as the bound model withoutnull.getEntityName()is now public inEntityControlTrait, so the request gets the default entity name through the service proxy.phpstan.neon(level 8) scoped to the type fixtures only.assertTypefixtures for the repository, the service and the request; behavior tests inBaseRequestRouteEntityTest.documentation/services.md(binding and the new request -> controller -> Action flow),readme.md, and a newModel genericssection indocumentation/migration.md.Why
Requests used to look the route entity up in
init()/beforeAuthorization()into a nullable property, and the Action searched for it again by id. Now the entity is loaded once, a missing resource produces 404 before authorization runs, and the model is non-nullable for PHPStan without@varat the call site.How it was verified
vendor/bin/phpunit—OK (501 tests, 1868 assertions)vendor/bin/pint --test—PASS 136 filesvendor/bin/phpstan analyse -c phpstan.neon(level 8) —No errors= ModelPHPStan reportsextends generic class ... but does not specify its types: TModelon classes without@extends; with the default it is clean.loadRouteEntity(), its 29 tests pass without fixture changes, no missing generics errors on classes without@extends.Known limitations / notes for consumers
Model|nullstop matching (the type is more precise now), regenerate the baseline.authorize()stays on the model and reaches the resource throughwhenLoaded(); usewithoutRelations()if needed.find($this->route('id'))); constrain the route withwhereNumber().TModelfromclass-string<EntityService<TModel>>through the child's@extendsand shows "Incompatible types: Expected ..., Model provided"; PHPStan/larastan infer the type correctly.getEntityName()became public: aprotectedoverride in a project causes a fatal error, make the overridepublic.https://claude.ai/code/session_01SSJ49hkfqDc6bsDwk83JBA