Add generic type annotations#578
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #578 +/- ##
=========================================
Coverage 99.69% 99.69%
Complexity 662 662
=========================================
Files 43 43
Lines 1646 1646
=========================================
Hits 1641 1641
Misses 5 5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR introduces Psalm generic type parameters across the Active Record querying API to improve static analysis (model type + “asArray” mode), and updates repository/query-related PHPDoc accordingly.
Changes:
- Added
@templateparameters toActiveQueryInterface/ActiveQueryand refined Psalm return types forone(),all(),populate(), etc. - Updated
ActiveRecordInterfaceandAbstractActiveRecordrelation/query factory annotations to propagate generic model types through relations. - Adjusted
RepositoryTraitPHPDoc return types and tightened PHP return typehints for*OrFail()methods.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 13 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Trait/RepositoryTrait.php | Adds Psalm generic return annotations and updates several repository method PHPDocs / signatures. |
| src/ActiveRecordInterface.php | Introduces method-level templates to express model-class-dependent query return types. |
| src/ActiveQueryInterface.php | Adds generics for model + asArray mode and refines Psalm return types across query methods. |
| src/ActiveQuery.php | Implements the new generic ActiveQueryInterface contract and refines internal Psalm typing. |
| src/AbstractActiveRecord.php | Adds templated Psalm annotations for query creation and relation query helpers. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * or throws {@see NotFoundException} if nothing matches. | ||
| */ | ||
| public static function findByPkOrFail(array|float|int|string $values): array|ActiveRecordInterface|null | ||
| public static function findByPkOrFail(array|float|int|string $values): array|ActiveRecordInterface |
| array|string|ExpressionInterface|null $condition = null, | ||
| array $params = [], | ||
| ): ActiveRecordInterface|array|null { | ||
| ): ActiveRecordInterface|array { |
Summary by CodeRabbit
Bug Fixes
findByPkOrFail()andfindOneOrFail()to accurately indicate they never return null values.Refactor