-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add generic types for ActiveRecord and Container #20325
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #20325 +/- ##
=========================================
Coverage 64.85% 64.85%
Complexity 11435 11435
=========================================
Files 431 431
Lines 37193 37193
=========================================
Hits 24120 24120
Misses 13073 13073 ☔ View full report in Codecov by Sentry. |
framework/db/ActiveQuery.php
Outdated
* @return array|ActiveRecord[] the query results. If the query results in nothing, an empty array will be returned. | ||
* @return T[] the query results. If the query results in nothing, an empty array will be returned. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That will likely break many IDEs. It will likely break API docs generation as well. Can we keep regular type for @return
and add psalm/phpstan annotations only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's possible
framework/db/ActiveQuery.php
Outdated
/** | ||
* {@inheritdoc} | ||
* | ||
* @return T[][] | ||
* @psalm-return T[][]|BatchQueryResult | ||
* @phpstan-return T[][]|BatchQueryResult | ||
* @codeCoverageIgnore | ||
*/ | ||
public function batch($batchSize = 100, $db = null) | ||
{ | ||
return parent::batch($batchSize, $db); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @return T[] | ||
* @psalm-return T[]|BatchQueryResult | ||
* @phpstan-return T[]|BatchQueryResult | ||
* @codeCoverageIgnore | ||
*/ | ||
public function each($batchSize = 100, $db = null) | ||
{ | ||
return parent::each($batchSize, $db); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do it without adding methods? I think @method
annotation for a class may work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, @method
phpdoc doesn't support multiple @return
phpdocs
Thank you! |
Using this two-way binding allows PHPStorm / PHPStan / Psalm recognize return type of calling
all()
/one()
/batch()
/each()
methodsIt's possible both:
@extends ActiveQuery<ModelClass>
phpdoc to the query class@method static ActiveQuery<static> find()
phpdoc to the active record class in case the query class isn't necessary