From 1820bfc2b3edb4936acfa69c7da8ea3a9f8307a7 Mon Sep 17 00:00:00 2001 From: Art4 Date: Wed, 26 Feb 2025 08:11:50 +0000 Subject: [PATCH] Fix 5 PHPStan errors --- src/Database/Database.php | 2 +- .../Collection/Notifications.php | 40 +++++++++++++------ .../Notifications/Collection/Notifies.php | 18 +++++---- .../Notifications/Repository/Notification.php | 11 +++-- 4 files changed, 46 insertions(+), 25 deletions(-) diff --git a/src/Database/Database.php b/src/Database/Database.php index 6ee4394901..14416a1899 100644 --- a/src/Database/Database.php +++ b/src/Database/Database.php @@ -474,7 +474,7 @@ class Database * * @param string $sql SQL statement * - * @return bool|object statement object or result object + * @return bool|mysqli_result|mysqli_stmt|object|PDOStatement statement object or result object * @throws \Exception */ public function p(string $sql) diff --git a/src/Navigation/Notifications/Collection/Notifications.php b/src/Navigation/Notifications/Collection/Notifications.php index 2174b213a9..4c32cf598b 100644 --- a/src/Navigation/Notifications/Collection/Notifications.php +++ b/src/Navigation/Notifications/Collection/Notifications.php @@ -8,36 +8,50 @@ namespace Friendica\Navigation\Notifications\Collection; use Friendica\BaseCollection; -use Friendica\Navigation\Notifications\Entity; +use Friendica\Navigation\Notifications\Entity\Notification as NotificationEntity; class Notifications extends BaseCollection { - /** - * @return Entity\Notification - */ - public function current(): Entity\Notification + public function current(): NotificationEntity { return parent::current(); } public function setSeen(): Notifications { - return $this->map(function (Entity\Notification $Notification) { - $Notification->setSeen(); - }); + $class = get_class($this); + + return new $class( + array_map( + function (NotificationEntity $notification) { + $notification->setSeen(); + }, + $this->getArrayCopy() + ), + $this->getTotalCount(), + ); } public function setDismissed(): Notifications { - return $this->map(function (Entity\Notification $Notification) { - $Notification->setDismissed(); - }); + $class = get_class($this); + + return new $class( + array_map( + function (NotificationEntity $notification) { + $notification->setDismissed(); + }, + $this->getArrayCopy(), + ), + $this->getTotalCount(), + ); + } public function countUnseen(): int { - return array_reduce($this->getArrayCopy(), function (int $carry, Entity\Notification $Notification) { - return $carry + ($Notification->seen ? 0 : 1); + return array_reduce($this->getArrayCopy(), function (int $carry, NotificationEntity $notification) { + return $carry + ($notification->seen ? 0 : 1); }, 0); } } diff --git a/src/Navigation/Notifications/Collection/Notifies.php b/src/Navigation/Notifications/Collection/Notifies.php index 4f41d2e261..fc97880de3 100644 --- a/src/Navigation/Notifications/Collection/Notifies.php +++ b/src/Navigation/Notifications/Collection/Notifies.php @@ -8,22 +8,24 @@ namespace Friendica\Navigation\Notifications\Collection; use Friendica\BaseCollection; -use Friendica\Navigation\Notifications\Entity; +use Friendica\Navigation\Notifications\Entity\Notify as NotifyEntity; class Notifies extends BaseCollection { - /** - * @return Entity\Notify - */ - public function current(): Entity\Notify + public function current(): NotifyEntity { return parent::current(); } public function setSeen(): Notifies { - return $this->map(function (Entity\Notify $Notify) { - $Notify->setSeen(); - }); + $class = get_class($this); + + return new $class(array_map( + function (NotifyEntity $notify) { + $notify->setSeen(); + }, + $this->getArrayCopy()), $this->getTotalCount(), + ); } } diff --git a/src/Navigation/Notifications/Repository/Notification.php b/src/Navigation/Notifications/Repository/Notification.php index e0e1d2aa98..49703bc1f9 100644 --- a/src/Navigation/Notifications/Repository/Notification.php +++ b/src/Navigation/Notifications/Repository/Notification.php @@ -162,12 +162,17 @@ class Notification extends BaseRepository LIMIT 50 ", ...$values); - $Entities = new NotificationsCollection(); + $entities = new NotificationsCollection(); + + if (!is_iterable($rows)) { + return $entities; + } + foreach ($rows as $fields) { - $Entities[] = $this->factory->createFromTableRow($fields); + $entities[] = $this->factory->createFromTableRow($fields); } - return $Entities; + return $entities; } public function selectAllForUser(int $uid): NotificationsCollection -- 2.39.5