]> git.mxchange.org Git - friendica.git/commitdiff
Fix 5 PHPStan errors
authorArt4 <art4@wlabs.de>
Wed, 26 Feb 2025 08:11:50 +0000 (08:11 +0000)
committerArt4 <art4@wlabs.de>
Wed, 26 Feb 2025 08:11:50 +0000 (08:11 +0000)
src/Database/Database.php
src/Navigation/Notifications/Collection/Notifications.php
src/Navigation/Notifications/Collection/Notifies.php
src/Navigation/Notifications/Repository/Notification.php

index 6ee4394901b039ccb54026a65ed6a14a597ef14f..14416a1899ee13525205cd42e3039b5d4cae02fa 100644 (file)
@@ -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)
index 2174b213a9f4a9e9b5e5ef3cfcb4d480d7d9c9e6..4c32cf598bafa2f59191e8fb72fd346949705686 100644 (file)
@@ -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);
        }
 }
index 4f41d2e261d059e1ec08f8149e1161a9ec9df097..fc97880de3a01097643f2cf63d88498f9a759c8c 100644 (file)
@@ -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(),
+               );
        }
 }
index e0e1d2aa983aab6f77171fd255a3540fb8fc66b7..49703bc1f97c5581300587cd7019913a9c6f7725 100644 (file)
@@ -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