propelorm / Propel2

Propel2 is an open-source high-performance Object-Relational Mapping (ORM) for modern PHP
http://propelorm.org/
MIT License
1.26k stars 397 forks source link

fixed input type of findBy hints #1912

Closed mringler closed 1 year ago

mringler commented 1 year ago

Currently type hints for the findBy*($value) methods of query classes have the input type set to the column type. So if an id column uses integers, the findById method is said to expect an int as input:

 * @method     Book[]|Collection findById(int $id) Return Book objects filtered by the id column
 * @psalm-method Collection&\Traversable<Book> findById(int $id) Return ChildBook2 objects filtered by the id column

However, the findBy methods also deal with arrays, you can do BookQuery::create()->findById([1,2,3]), which will correctly generate an IN query (i.e. SELECT * from Book where id IN (1,2,3)). This is quite useful.

So I think the input type should be T|array<T> in @method and @psalm-method:

* @method     Book[]|Collection findById(int|array<int> $id) Return ChildBook2 objects filtered by the id column
* @psalm-method Collection&\Traversable<Book> findById(int|array<int> $id) Return ChildBook2 objects filtered by the id column

I also moved the docblock into its own template file.

codecov-commenter commented 1 year ago

Codecov Report

Base: 87.64% // Head: 87.62% // Decreases project coverage by -0.01% :warning:

Coverage data is based on head (5e40c21) compared to base (f9b9e12). Patch coverage: 97.05% of modified lines in pull request are covered.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1912 +/- ## ============================================ - Coverage 87.64% 87.62% -0.02% + Complexity 7829 7822 -7 ============================================ Files 227 227 Lines 21183 21135 -48 ============================================ - Hits 18565 18519 -46 + Misses 2618 2616 -2 ``` | Flag | Coverage Δ | | |---|---|---| | 5-max | `87.62% <97.05%> (-0.02%)` | :arrow_down: | | 7.4 | `87.62% <97.05%> (-0.02%)` | :arrow_down: | | agnostic | `66.97% <88.23%> (-0.07%)` | :arrow_down: | | mysql | `68.76% <88.23%> (-0.06%)` | :arrow_down: | | pgsql | `68.77% <88.23%> (-0.07%)` | :arrow_down: | | sqlite | `66.60% <97.05%> (-0.06%)` | :arrow_down: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=propelorm#carryforward-flags-in-the-pull-request-comment) to find out more. | [Impacted Files](https://codecov.io/gh/propelorm/Propel2/pull/1912?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=propelorm) | Coverage Δ | | |---|---|---| | [src/Propel/Generator/Manager/AbstractManager.php](https://codecov.io/gh/propelorm/Propel2/pull/1912/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=propelorm#diff-c3JjL1Byb3BlbC9HZW5lcmF0b3IvTWFuYWdlci9BYnN0cmFjdE1hbmFnZXIucGhw) | `77.20% <0.00%> (ø)` | | | [src/Propel/Generator/Model/Table.php](https://codecov.io/gh/propelorm/Propel2/pull/1912/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=propelorm#diff-c3JjL1Byb3BlbC9HZW5lcmF0b3IvTW9kZWwvVGFibGUucGhw) | `91.41% <ø> (ø)` | | | [src/Propel/Generator/Util/QuickBuilder.php](https://codecov.io/gh/propelorm/Propel2/pull/1912/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=propelorm#diff-c3JjL1Byb3BlbC9HZW5lcmF0b3IvVXRpbC9RdWlja0J1aWxkZXIucGhw) | `84.95% <ø> (ø)` | | | [src/Propel/Generator/Util/VfsTrait.php](https://codecov.io/gh/propelorm/Propel2/pull/1912/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=propelorm#diff-c3JjL1Byb3BlbC9HZW5lcmF0b3IvVXRpbC9WZnNUcmFpdC5waHA=) | `100.00% <ø> (ø)` | | | [src/Propel/Generator/Builder/Om/QueryBuilder.php](https://codecov.io/gh/propelorm/Propel2/pull/1912/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=propelorm#diff-c3JjL1Byb3BlbC9HZW5lcmF0b3IvQnVpbGRlci9PbS9RdWVyeUJ1aWxkZXIucGhw) | `89.77% <100.00%> (-0.22%)` | :arrow_down: | | [...rc/Propel/Generator/Reverse/SqliteSchemaParser.php](https://codecov.io/gh/propelorm/Propel2/pull/1912/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=propelorm#diff-c3JjL1Byb3BlbC9HZW5lcmF0b3IvUmV2ZXJzZS9TcWxpdGVTY2hlbWFQYXJzZXIucGhw) | `89.55% <100.00%> (ø)` | | | [...rc/Propel/Runtime/Connection/ConnectionFactory.php](https://codecov.io/gh/propelorm/Propel2/pull/1912/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=propelorm#diff-c3JjL1Byb3BlbC9SdW50aW1lL0Nvbm5lY3Rpb24vQ29ubmVjdGlvbkZhY3RvcnkucGhw) | `77.77% <100.00%> (ø)` | | | [...pel/Generator/Builder/Om/AbstractObjectBuilder.php](https://codecov.io/gh/propelorm/Propel2/pull/1912/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=propelorm#diff-c3JjL1Byb3BlbC9HZW5lcmF0b3IvQnVpbGRlci9PbS9BYnN0cmFjdE9iamVjdEJ1aWxkZXIucGhw) | `97.29% <0.00%> (-0.14%)` | :arrow_down: | | [src/Propel/Runtime/ActiveQuery/Join.php](https://codecov.io/gh/propelorm/Propel2/pull/1912/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=propelorm#diff-c3JjL1Byb3BlbC9SdW50aW1lL0FjdGl2ZVF1ZXJ5L0pvaW4ucGhw) | `79.79% <0.00%> (-0.11%)` | :arrow_down: | | [src/Propel/Runtime/Map/RelationMap.php](https://codecov.io/gh/propelorm/Propel2/pull/1912/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=propelorm#diff-c3JjL1Byb3BlbC9SdW50aW1lL01hcC9SZWxhdGlvbk1hcC5waHA=) | `93.24% <0.00%> (-0.10%)` | :arrow_down: | | ... and [9 more](https://codecov.io/gh/propelorm/Propel2/pull/1912/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=propelorm) | | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=propelorm). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=propelorm)

:umbrella: View full report at Codecov.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.

mringler commented 1 year ago

Docbloc is now generated like this (for BookReaderQuery from the test suite):

/**
 * Base class that represents a query for the book_reader table.
 *
 * @method     ChildBookReaderQuery orderById($order = Criteria::ASC) Order by the id column
 * @method     ChildBookReaderQuery orderByName($order = Criteria::ASC) Order by the name column
 *
 * @method     ChildBookReaderQuery groupById() Group by the id column';
 * @method     ChildBookReaderQuery groupByName() Group by the name column';
 *
 * @method     ChildBookReaderQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
 * @method     ChildBookReaderQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
 * @method     ChildBookReaderQuery innerJoin($relation) Adds a INNER JOIN clause to the query
 *
 * @method     ChildBookReaderQuery leftJoinWith($relation) Adds a LEFT JOIN clause and with to the query
 * @method     ChildBookReaderQuery rightJoinWith($relation) Adds a RIGHT JOIN clause and with to the query
 * @method     ChildBookReaderQuery innerJoinWith($relation) Adds a INNER JOIN clause and with to the query
 *
 * @method     ChildBookReaderQuery leftJoinBookOpinion($relationAlias = null) Adds a LEFT JOIN clause to the query using the BookOpinion relation
 * @method     ChildBookReaderQuery rightJoinBookOpinion($relationAlias = null) Adds a RIGHT JOIN clause to the query using the BookOpinion relation
 * @method     ChildBookReaderQuery innerJoinBookOpinion($relationAlias = null) Adds a INNER JOIN clause to the query using the BookOpinion relation
 *
 * @method     ChildBookReaderQuery joinWithBookOpinion($joinType = Criteria::INNER_JOIN) Adds a join clause and with to the query using the ' . $relationName . " relation
 *
 * @method     ChildBookReaderQuery leftJoinWithBookOpinion() Adds a LEFT JOIN clause and with to the query using the BookOpinion relation
 * @method     ChildBookReaderQuery rightJoinWithBookOpinion() Adds a RIGHT JOIN clause and with to the query using the BookOpinion relation
 * @method     ChildBookReaderQuery innerJoinWithBookOpinion() Adds a INNER JOIN clause and with to the query using the BookOpinion relation
 *
 * @method     ChildBookReaderQuery leftJoinReaderFavorite($relationAlias = null) Adds a LEFT JOIN clause to the query using the ReaderFavorite relation
 * @method     ChildBookReaderQuery rightJoinReaderFavorite($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ReaderFavorite relation
 * @method     ChildBookReaderQuery innerJoinReaderFavorite($relationAlias = null) Adds a INNER JOIN clause to the query using the ReaderFavorite relation
 *
 * @method     ChildBookReaderQuery joinWithReaderFavorite($joinType = Criteria::INNER_JOIN) Adds a join clause and with to the query using the ' . $relationName . " relation
 *
 * @method     ChildBookReaderQuery leftJoinWithReaderFavorite() Adds a LEFT JOIN clause and with to the query using the ReaderFavorite relation
 * @method     ChildBookReaderQuery rightJoinWithReaderFavorite() Adds a RIGHT JOIN clause and with to the query using the ReaderFavorite relation
 * @method     ChildBookReaderQuery innerJoinWithReaderFavorite() Adds a INNER JOIN clause and with to the query using the ReaderFavorite relation
 *
 * @method     \Propel\Tests\Bookstore\BookOpinionQuery|\Propel\Tests\Bookstore\ReaderFavoriteQuery endUse() Finalizes a secondary criteria and merges it with its primary Criteria
 *
 * @method     ChildBookReader|null findOne(?ConnectionInterface $con = null) Return the first ChildBookReader matching the query
 * @method     ChildBookReader findOneOrCreate(?ConnectionInterface $con = null) Return the first ChildBookReader matching the query, or a new ChildBookReader object populated from the query conditions when no match is found
 *
 * @method     ChildBookReader|null findOneById(int $id) Return the first ChildBookReader filtered by the id column
 * @method     ChildBookReader|null findOneByName(string $name) Return the first ChildBookReader filtered by the name column
 *
 * @method     ChildBookReader requirePk($key, ?ConnectionInterface $con = null) Return the ChildBookReader by primary key and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
 * @method     ChildBookReader requireOne(?ConnectionInterface $con = null) Return the first ChildBookReader matching the query and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
 *
 * @method     ChildBookReader requireOneById(int $id) Return the first ChildBookReader filtered by the $name column and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
 * @method     ChildBookReader requireOneByName(string $name) Return the first ChildBookReader filtered by the $name column and throws \Propel\Runtime\Exception\EntityNotFoundException when not found
 *
 * @method     ChildBookReader[]|Collection find(?ConnectionInterface $con = null) Return ChildBookReader objects based on current ModelCriteria
 * @psalm-method Collection&\Traversable<ChildBookReader> find(?ConnectionInterface $con = null) Return ChildBookReader objects based on current ModelCriteria
 *
 * @method     ChildBookReader[]|Collection findById(int|array<int> $id) Return ChildBookReader objects filtered by the id column
 * @psalm-method Collection&\Traversable<ChildBookReader> findById(int|array<int> $id) Return ChildBookReader objects filtered by the id column
 * @method     ChildBookReader[]|Collection findByName(string|array<string> $name) Return ChildBookReader objects filtered by the name column
 * @psalm-method Collection&\Traversable<ChildBookReader> findByName(string|array<string> $name) Return ChildBookReader objects filtered by the name column
 *
 * @method     ChildBookReader[]|\Propel\Runtime\Util\PropelModelPager paginate($page = 1, $maxPerPage = 10, ?ConnectionInterface $con = null) Issue a SELECT query based on the current ModelCriteria and uses a page and a maximum number of results per page to compute an offset and a limit
 * @psalm-method \Propel\Runtime\Util\PropelModelPager&\Traversable<ChildBookReader> paginate($page = 1, $maxPerPage = 10, ?ConnectionInterface $con = null) Issue a SELECT query based on the current ModelCriteria and uses a page and a maximum number of results per page to compute an offset and a limit
 */
abstract class BookReaderQuery extends ModelCriteria
{