Skip to content

fix(database): declare TModel template on where-builder traits - #2322

Open
ondrejmirtes wants to merge 1 commit into
tempestphp:3.xfrom
ondrejmirtes:fix/trait-template-tmodel
Open

ondrejmirtes wants to merge 1 commit into
tempestphp:3.xfrom
ondrejmirtes:fix/trait-template-tmodel

Conversation

@ondrejmirtes

Copy link
Copy Markdown

HasWhereRelationMethods and HasWhereQueryBuilderMethods use TModel in their PHPDoc (@return static<TModel>, @var WhereGroupBuilder<TModel>) without declaring it. A trait does not see the template types of the class that uses it, so PHPStan resolves TModel as the class Tempest\Database\Builder\QueryBuilders\TModel. The resulting errors were hidden by the class.notFound ignore for packages/database/src/Builder/*.

PHPStan 2.3 resolves template types on generic static<...> return types correctly (phpstan/phpstan-src#6695). Because of that, the unknown class now reaches call sites: Tag::select()->whereHas(...)->all() returns TModel[], and every property access on the result is reported (28 errors in WhereHasTest and IsDatabaseModelTest).

This declares @template TModel on both traits and passes it through with @use. The class.notFound ignore is no longer needed. Keeping it would fail on reportUnmatchedIgnoredErrors, so it's removed. No change in output with PHPStan 2.2.13.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FbAUWcmATbQhrWDPZrVGSg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant