]> git.mxchange.org Git - friendica.git/commitdiff
Fix 7 PHPStan errors
authorArt4 <art4@wlabs.de>
Wed, 5 Mar 2025 14:27:34 +0000 (14:27 +0000)
committerArt4 <art4@wlabs.de>
Wed, 5 Mar 2025 14:27:34 +0000 (14:27 +0000)
src/Core/Hook.php
src/Factory/Api/Friendica/Photo.php
src/Model/Item.php
src/Model/Log/ParsedLogIterator.php
src/Model/Photo.php
src/Model/Post/Delayed.php

index 44dfad70bcbd83d20e8b8fa0b525cf2e021f7e54..8c9f3ba91018ba3c79608bf2a34fa96621180cc9 100644 (file)
@@ -172,7 +172,7 @@ class Hook
         * the provided data.
         *
         * @param string        $name of the hook to call
-        * @param string|array &$data to transmit to the callback handler
+        * @param string|array|null $data to transmit to the callback handler
         * @return void
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         */
index 82c80ac7f39ae998826764f84b73c18192b3c92f..051ae66a5d7dd04da28927541ec040d1de3a8534 100644 (file)
@@ -41,7 +41,6 @@ class Photo extends BaseFactory
         * @param int    $scale
         * @param int    $uid
         * @param string $type
-        * @return Array
         */
        public function createFromId(string $photo_id, int $scale = null, int $uid, string $type = 'json', bool $with_posts = true): array
        {
@@ -66,7 +65,7 @@ class Photo extends BaseFactory
                $data['id']       = $data['resource-id'];
 
                if (is_int($scale)) {
-                       $data['data'] = base64_encode(ModelPhoto::getImageDataForPhoto($data));
+                       $data['data'] = base64_encode(ModelPhoto::getImageDataForPhoto($data) ?? '');
                }
 
                if ($type == 'xml') {
index 31f8a8e22eeb337298ead37dee6820ed830378df..6500c8005ca098eb1211ec67a8fb26c0fde067c1 100644 (file)
@@ -672,7 +672,7 @@ class Item
        /**
         * Inserts item record
         *
-        * @param array $item Item array to be inserted
+        * @param array<string,mixed> $item Item array to be inserted
         * @param int   $notify Notification (type?)
         * @param bool  $post_local (???)
         * @return int Zero means error, otherwise primary key (id) is being returned
@@ -695,6 +695,7 @@ class Item
 
                // If it is a posting where users should get notifications, then define it as wall posting
                if ($notify) {
+                       /** @var array<string,mixed> */
                        $item = $itemHelper->prepareOriginPost($item);
 
                        if (is_int($notify) && in_array($notify, Worker::PRIORITIES)) {
@@ -708,6 +709,7 @@ class Item
                        $item['network'] = trim(($item['network'] ?? '') ?: Protocol::PHANTOM);
                }
 
+               /** @var array<string,mixed> */
                $item = $itemHelper->prepareItemData($item, (bool) $notify);
 
                // Store conversation data
@@ -749,6 +751,7 @@ class Item
                        }
                }
 
+               /** @var array<string,mixed> */
                $item = $itemHelper->validateItemData($item);
 
                // Ensure that there is an avatar cache
@@ -846,6 +849,7 @@ class Item
                                $dummy_session = false;
                        }
 
+                       /** @var array<string,mixed> */
                        $item = $eventDispatcher->dispatch(
                                new ArrayFilterEvent(ArrayFilterEvent::POST_LOCAL, $item)
                        )->getArray();
@@ -3061,7 +3065,14 @@ class Item
        {
                $appHelper = DI::appHelper();
                $uid       = DI::userSession()->getLocalUserId();
-               Hook::callAll('prepare_body_init', $item);
+
+               $item_copy = $item;
+
+               Hook::callAll('prepare_body_init', $item_copy);
+
+               if (is_array($item_copy)) {
+                       $item = $item_copy;
+               }
 
                // In order to provide theme developers more possibilities, event items
                // are treated differently.
index 44c98462c129f2d8d3c8967245f4c7cd7b05daed..58c8bddb77441cef6dcac90cdb6395ea3d9a0681 100644 (file)
@@ -21,7 +21,7 @@ class ParsedLogIterator implements \Iterator
        /** @var ReversedFileReader */
        private $reader;
 
-       /** @var ParsedLogLine current iterator value*/
+       /** @var ParsedLogLine|null current iterator value*/
        private $value = null;
 
        /** @var int max number of lines to read */
index c2757539601ca9bf866589fb56cd11bd23ac05b4..74edaf360d6838e76d1acf30ce5ba5dc5c253aaf 100644 (file)
@@ -244,7 +244,7 @@ class Photo
         *
         * @param array $photo Photo data. Needs at least 'id', 'type', 'backend-class', 'backend-ref'
         *
-        * @return \Friendica\Object\Image|null Image object or null on error
+        * @return string|null Image data as string or null on error
         */
        public static function getImageDataForPhoto(array $photo)
        {
@@ -254,7 +254,7 @@ class Photo
 
                try {
                        $backendClass = DI::storageManager()->getByName($photo['backend-class'] ?? '');
-                       /// @todo refactoring this returning, because the storage returns a "string" which is casted in different ways - a check "instanceof Image" will fail!
+
                        return $backendClass->get($photo['backend-ref'] ?? '');
                } catch (InvalidClassStorageException $storageException) {
                        try {
@@ -834,10 +834,9 @@ class Photo
         * - Sharing a post with a group will create a photo that only the group can see.
         * - Sharing a photo again that been shared non public before doesn't alter the permissions.
         *
-        * @return string
         * @throws \Exception
         */
-       public static function setPermissionFromBody($body, $uid, $original_contact_id, $str_contact_allow, $str_circle_allow, $str_contact_deny, $str_circle_deny)
+       public static function setPermissionFromBody($body, $uid, $original_contact_id, $str_contact_allow, $str_circle_allow, $str_contact_deny, $str_circle_deny): bool
        {
                // Simplify image codes
                $img_body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $body);
index e4862c27c26fdeae5da62fe27877062c9f694cb5..b0c5d09dcd34e2faa0beb8a880ddb121d0801505 100644 (file)
@@ -170,9 +170,8 @@ class Delayed
         * @param array  $attachments
         * @param int    $preparation_mode
         * @param string $uri
-        * @return bool
         */
-       public static function publish(array $item, int $notify = 0, array $taglist = [], array $attachments = [], int $preparation_mode = self::PREPARED, string $uri = '')
+       public static function publish(array $item, int $notify = 0, array $taglist = [], array $attachments = [], int $preparation_mode = self::PREPARED, string $uri = ''): int
        {
                if (!empty($attachments)) {
                        $item['attachments'] = $attachments;