Skip to content

Commit

Permalink
Precise EntityRepository::count (#11579)
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet authored Aug 24, 2024
1 parent e1dc94d commit c6b2d89
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/EntityRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public function findOneBy(array $criteria, array|null $orderBy = null): object|n
* @psalm-param array<string, mixed> $criteria
*
* @return int The cardinality of the objects that match the given criteria.
* @psalm-return 0|positive-int
*
* @todo Add this method to `ObjectRepository` interface in the next major release
*/
Expand Down
5 changes: 4 additions & 1 deletion src/Persisters/Entity/BasicEntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,10 @@ public function count(array|Criteria $criteria = []): int
? $this->expandCriteriaParameters($criteria)
: $this->expandParameters($criteria);

return (int) $this->conn->executeQuery($sql, $params, $types)->fetchOne();
$count = (int) $this->conn->executeQuery($sql, $params, $types)->fetchOne();
assert($count >= 0);

return $count;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/Persisters/Entity/EntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ public function delete(object $entity): bool;
* Count entities (optionally filtered by a criteria)
*
* @param mixed[]|Criteria $criteria
*
* @psalm-return 0|positive-int
*/
public function count(array|Criteria $criteria = []): int;

Expand Down

0 comments on commit c6b2d89

Please sign in to comment.