From 71c44692f6dc8cbbaf6bb274957b3a3519b72eb0 Mon Sep 17 00:00:00 2001 From: Andrew Longosz Date: Fri, 27 Dec 2024 14:53:52 +0100 Subject: [PATCH] [Pagerfanta] Defined int range for Notification total count --- src/contracts/Persistence/Notification/Handler.php | 2 +- src/contracts/Repository/NotificationService.php | 2 +- .../Repository/Values/Notification/NotificationList.php | 9 ++++++--- src/lib/Persistence/Legacy/Notification/Gateway.php | 2 +- .../Legacy/Notification/Gateway/DoctrineDatabase.php | 6 ++---- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/contracts/Persistence/Notification/Handler.php b/src/contracts/Persistence/Notification/Handler.php index 0329c46c46..6d57b25d91 100644 --- a/src/contracts/Persistence/Notification/Handler.php +++ b/src/contracts/Persistence/Notification/Handler.php @@ -62,7 +62,7 @@ public function loadUserNotifications(int $userId, int $offset, int $limit): arr /** * @param int $currentUserId * - * @return int + * @phpstan-return int<0, max> */ public function countNotifications(int $currentUserId): int; diff --git a/src/contracts/Repository/NotificationService.php b/src/contracts/Repository/NotificationService.php index 5561e50f14..f2cb8a58cc 100644 --- a/src/contracts/Repository/NotificationService.php +++ b/src/contracts/Repository/NotificationService.php @@ -59,7 +59,7 @@ public function getPendingNotificationCount(): int; /** * Get count of total users notifications. * - * @return int + * @phpstan-return int<0, max> */ public function getNotificationCount(): int; diff --git a/src/contracts/Repository/Values/Notification/NotificationList.php b/src/contracts/Repository/Values/Notification/NotificationList.php index 8b183f50be..bb66356aa8 100644 --- a/src/contracts/Repository/Values/Notification/NotificationList.php +++ b/src/contracts/Repository/Values/Notification/NotificationList.php @@ -13,13 +13,16 @@ use IteratorAggregate; use Traversable; +/** + * @implements \IteratorAggregate + */ class NotificationList extends ValueObject implements IteratorAggregate { - /** @var int */ - public $totalCount = 0; + /** @phpstan-var int<0, max> */ + public int $totalCount = 0; /** @var \Ibexa\Contracts\Core\Repository\Values\Notification\Notification[] */ - public $items = []; + public array $items = []; /** * {@inheritdoc} diff --git a/src/lib/Persistence/Legacy/Notification/Gateway.php b/src/lib/Persistence/Legacy/Notification/Gateway.php index a84594cdce..0069e58d0a 100644 --- a/src/lib/Persistence/Legacy/Notification/Gateway.php +++ b/src/lib/Persistence/Legacy/Notification/Gateway.php @@ -44,7 +44,7 @@ abstract public function updateNotification(Notification $notification): void; /** * @param int $userId * - * @return int + * @phpstan-return int<0, max> */ abstract public function countUserNotifications(int $userId): int; diff --git a/src/lib/Persistence/Legacy/Notification/Gateway/DoctrineDatabase.php b/src/lib/Persistence/Legacy/Notification/Gateway/DoctrineDatabase.php index 70cdd05e05..7a1a1083ad 100644 --- a/src/lib/Persistence/Legacy/Notification/Gateway/DoctrineDatabase.php +++ b/src/lib/Persistence/Legacy/Notification/Gateway/DoctrineDatabase.php @@ -99,9 +99,6 @@ public function updateNotification(Notification $notification): void $query->execute(); } - /** - * {@inheritdoc} - */ public function countUserNotifications(int $userId): int { $query = $this->connection->createQueryBuilder(); @@ -111,7 +108,8 @@ public function countUserNotifications(int $userId): int ->where($query->expr()->eq(self::COLUMN_OWNER_ID, ':user_id')) ->setParameter(':user_id', $userId, PDO::PARAM_INT); - return (int)$query->execute()->fetchColumn(); + /** @phpstan-var int<0, max> */ + return (int)$query->execute()->fetchOne(); } /**