]> git.mxchange.org Git - friendica.git/commitdiff
fix 7 PHPStan errors in factoriy and Model
authorArt4 <art4@wlabs.de>
Wed, 5 Mar 2025 15:15:18 +0000 (15:15 +0000)
committerArt4 <art4@wlabs.de>
Wed, 5 Mar 2025 15:15:18 +0000 (15:15 +0000)
src/Factory/Api/Mastodon/Attachment.php
src/Factory/Api/Twitter/Status.php
src/Federation/Repository/GServer.php
src/Model/Contact/User.php
src/Model/Event.php
src/Model/GServer.php

index ae0ebf182690911a715c23006610c60bfcd3b632..52361284ac2c6b7303f1d77e21d147094c06d074 100644 (file)
@@ -11,7 +11,7 @@ use Friendica\App\BaseURL;
 use Friendica\BaseFactory;
 use Friendica\Model\Attach;
 use Friendica\Model\Photo;
-use Friendica\Network\HTTPException;
+use Friendica\Network\HTTPException\InternalServerErrorException;
 use Friendica\Model\Post;
 use Friendica\Util\Images;
 use Friendica\Util\Proxy;
@@ -32,7 +32,7 @@ class Attachment extends BaseFactory
        /**
         * @param int $uriId Uri-ID of the attachments
         * @return array
-        * @throws HTTPException\InternalServerErrorException
+        * @throws InternalServerErrorException
         */
        public function createFromUriId(int $uriId): array
        {
@@ -47,21 +47,30 @@ class Attachment extends BaseFactory
        /**
         * @param int $id id of the media
         * @return \Friendica\Object\Api\Mastodon\Attachment
-        * @throws HTTPException\InternalServerErrorException
+        * @throws InternalServerErrorException
         */
        public function createFromId(int $id): \Friendica\Object\Api\Mastodon\Attachment
        {
                $attachment = Post\Media::getById($id);
+
                if (empty($attachment)) {
-                       return [];
+                       $attachment = [
+                               'id' => '',
+                               'description' => '',
+                               'url' => '',
+                               'mimetype' => '',
+                               'blurhash' => '',
+                               'type' => Post\Media::UNKNOWN,
+                       ];
                }
+
                return $this->createFromMediaArray($attachment);
        }
 
        /**
         * @param array $attachment
         * @return \Friendica\Object\Api\Mastodon\Attachment
-        * @throws HTTPException\InternalServerErrorException
+        * @throws InternalServerErrorException
         */
        private function createFromMediaArray(array $attachment):  \Friendica\Object\Api\Mastodon\Attachment
        {
@@ -100,7 +109,7 @@ class Attachment extends BaseFactory
         * @param int $id id of the photo
         *
         * @return array
-        * @throws HTTPException\InternalServerErrorException
+        * @throws InternalServerErrorException
         */
        public function createFromPhoto(int $id): array
        {
@@ -136,7 +145,7 @@ class Attachment extends BaseFactory
         * @param int $id id of the attachment
         *
         * @return array
-        * @throws HTTPException\InternalServerErrorException
+        * @throws InternalServerErrorException
         */
        public function createFromAttach(int $id): array
        {
index b31a89fc4469c1fd9114190a52d1197ea7da2001..c83b0aa9ab1645a21beb995ecf1d13294302a2a7 100644 (file)
@@ -39,7 +39,7 @@ class Status extends BaseFactory
        private $mention;
        /** @var Activities entity */
        private $activities;
-       /** @var Activities entity */
+       /** @var Attachment entity */
        private $attachment;
        /** @var ContentItem */
        private $contentItem;
index 5a12f3339b4cb288337b055a2f6035c4564972bc..8e9c7e94494008924ccc80a33648d7f1248ed0bf 100644 (file)
@@ -28,6 +28,8 @@ class GServer extends \Friendica\BaseRepository
         */
        public function selectOneById(int $gsid): Entity\GServer
        {
-               return $this->_selectOne(['id' => $gsid]);
+               $fields = $this->_selectFirstRowAsArray( ['id' => $gsid]);
+
+               return $this->factory->createFromTableRow($fields);
        }
 }
index 17663e233b237f65007db147fd28b53c6d3515fd..aa850138117e7bef25c09104f0d8a0e9ff50f849 100644 (file)
@@ -30,9 +30,8 @@ class User
         * Insert a user-contact for a given contact array
         *
         * @param array $contact
-        * @return void
         */
-       public static function insertForContactArray(array $contact)
+       public static function insertForContactArray(array $contact): bool
        {
                if (empty($contact['uid'])) {
                        // We don't create entries for the public user - by now
@@ -339,7 +338,7 @@ class User
        {
                $pcid = Contact::getPublicContactId($cid, $uid);
                if (!$pcid) {
-                       return false;
+                       return self::FREQUENCY_DEFAULT;
                }
 
                $public_contact = DBA::selectFirst('user-contact', ['channel-frequency'], ['cid' => $pcid, 'uid' => $uid]);
index 6cb73f4c37e65fe9330785acd60da852f3f506f6..39aba01efda3824fcbe53e72aa5774285ee845fb 100644 (file)
@@ -305,7 +305,7 @@ class Event
                        Hook::callAll("event_created", $event['id']);
                }
 
-               return $event['id'];
+               return (int) $event['id'];
        }
 
        public static function getItemArrayForId(int $event_id, array $item = []): array
index 7029adbb532fc8ebfba3a225527c2d606b2acecd..8ead59940852ac0c4c835dc3d758420920bb1378 100644 (file)
@@ -2200,8 +2200,6 @@ class GServer
         * Converts input value to a boolean value
         *
         * @param string|integer $val
-        *
-        * @return boolean
         */
        private static function toBoolean($val): bool
        {
@@ -2211,7 +2209,7 @@ class GServer
                        return false;
                }
 
-               return $val;
+               return (bool) $val;
        }
 
        /**