Skip to content

Add generic type annotations#578

Open
Tigrov wants to merge 4 commits into
masterfrom
generic-type
Open

Add generic type annotations#578
Tigrov wants to merge 4 commits into
masterfrom
generic-type

Conversation

@Tigrov

@Tigrov Tigrov commented May 26, 2026

Copy link
Copy Markdown
Member
Q A
Is bugfix?
New feature? ✔️/❌
Breaks BC? ✔️/❌
Fixed issues

Summary by CodeRabbit

  • Bug Fixes

    • Fixed return type declarations for findByPkOrFail() and findOneOrFail() to accurately indicate they never return null values.
  • Refactor

    • Improved static type annotations and generic documentation in active record components to enable better IDE support, type checking, and error detection.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 26, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 80ec8541-e9a0-4529-9a0c-ae399d8f2f08

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch generic-type

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented May 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.69%. Comparing base (9902991) to head (13012a4).
⚠️ Report is 3 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Tigrov Tigrov added the status:code review The pull request needs review. label May 26, 2026
@Tigrov Tigrov requested a review from a team May 26, 2026 09:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 @template parameters to ActiveQueryInterface / ActiveQuery and refined Psalm return types for one(), all(), populate(), etc.
  • Updated ActiveRecordInterface and AbstractActiveRecord relation/query factory annotations to propagate generic model types through relations.
  • Adjusted RepositoryTrait PHPDoc 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.

Comment thread src/Trait/RepositoryTrait.php Outdated
Comment thread src/Trait/RepositoryTrait.php Outdated
* 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 {
Comment thread src/ActiveRecordInterface.php
Comment thread src/AbstractActiveRecord.php
Comment thread src/AbstractActiveRecord.php
Comment thread src/AbstractActiveRecord.php Outdated
Comment thread src/AbstractActiveRecord.php
Comment thread src/AbstractActiveRecord.php Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Comment thread src/ActiveQuery.php Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread src/ActiveQueryInterface.php
Comment thread src/ActiveQueryInterface.php
@samdark samdark requested a review from vjik May 26, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status:code review The pull request needs review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants