Skip to content
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

fixed input type of findBy hints #1912

Merged
merged 1 commit into from
Nov 15, 2022

Conversation

mringler
Copy link
Contributor

@mringler mringler commented Nov 13, 2022

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
Copy link

codecov-commenter commented Nov 13, 2022

Codecov Report

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

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
@@             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%) ⬇️
7.4 87.62% <97.05%> (-0.02%) ⬇️
agnostic 66.97% <88.23%> (-0.07%) ⬇️
mysql 68.76% <88.23%> (-0.06%) ⬇️
pgsql 68.77% <88.23%> (-0.07%) ⬇️
sqlite 66.60% <97.05%> (-0.06%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
src/Propel/Generator/Manager/AbstractManager.php 77.20% <0.00%> (ø)
src/Propel/Generator/Model/Table.php 91.41% <ø> (ø)
src/Propel/Generator/Util/QuickBuilder.php 84.95% <ø> (ø)
src/Propel/Generator/Util/VfsTrait.php 100.00% <ø> (ø)
src/Propel/Generator/Builder/Om/QueryBuilder.php 89.77% <100.00%> (-0.22%) ⬇️
...rc/Propel/Generator/Reverse/SqliteSchemaParser.php 89.55% <100.00%> (ø)
...rc/Propel/Runtime/Connection/ConnectionFactory.php 77.77% <100.00%> (ø)
...pel/Generator/Builder/Om/AbstractObjectBuilder.php 97.29% <0.00%> (-0.14%) ⬇️
src/Propel/Runtime/ActiveQuery/Join.php 79.79% <0.00%> (-0.11%) ⬇️
src/Propel/Runtime/Map/RelationMap.php 93.24% <0.00%> (-0.10%) ⬇️
... and 9 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

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

@mringler
Copy link
Contributor Author

mringler commented Nov 13, 2022

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
{

@mringler mringler force-pushed the bugfix/fix_findBy_signature branch 4 times, most recently from 5e40c21 to 1dcba33 Compare November 14, 2022 13:18
@dereuromark dereuromark merged commit cb84d9c into propelorm:master Nov 15, 2022
@mringler mringler deleted the bugfix/fix_findBy_signature branch September 29, 2023 22:20
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.

4 participants