]> git.mxchange.org Git - friendica.git/commitdiff
fix 17 PHPStan errors
authorArt4 <art4@wlabs.de>
Tue, 25 Feb 2025 11:36:32 +0000 (11:36 +0000)
committerArt4 <art4@wlabs.de>
Tue, 25 Feb 2025 11:36:32 +0000 (11:36 +0000)
src/Protocol/ATProtocol/Processor.php
src/Protocol/ActivityPub/Receiver.php
src/Protocol/DFRN.php
src/Protocol/Diaspora.php

index f551f6a273c1fb709a06b499d9dbb4954b44bddb..3a21ff3dd4341d38f758f2e802aafdee87e82202 100755 (executable)
@@ -279,7 +279,7 @@ class Processor
                $uri = $this->getUri($post);
 
                if ($uri_id = $this->fetchUriId($uri, $uid)) {
-                       return $uri_id;
+                       return (int) $uri_id;
                }
 
                if (empty($post->record)) {
@@ -322,7 +322,7 @@ class Processor
                        $this->logger->warning('Fetched post was not inserted', ['guid' => $item['guid'], 'uri' => $item['uri']]);
                }
 
-               return $this->fetchUriId($uri, $uid);
+               return (int) $this->fetchUriId($uri, $uid);
        }
 
        private function getHeaderFromJetstream(stdClass $data, int $uid, int $protocol = Conversation::PARCEL_JETSTREAM): array
@@ -860,7 +860,7 @@ class Processor
                        $this->logger->debug('Post with extid exists', ['uri' => $uri]);
                        return $reply['uri-id'];
                }
-               return 0;
+               return '0';
        }
 
        private function getPostUids(string $uri, bool $with_public_user): array
index 34732022b5a51ec8ff69ac45c30a8d97339cd45d..76f4d31d3d2f56a45cbf32ed7c1a4cd6814c957b 100644 (file)
@@ -250,7 +250,7 @@ class Receiver
         * @param string  $object_id Object ID of the provided object
         * @param integer $uid       User ID
         *
-        * @return string with object type or NULL
+        * @return string|null string with object type or NULL
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
         */
index be6dfc206d75d1165311cc969a5ed6fcf37dbd39..56cafc1a9768bc767cf9238e26f6caf9c85cad0d 100644 (file)
@@ -607,64 +607,64 @@ class DFRN
         * @param string      $element  Element name for the activity
         * @param string      $activity activity value
         * @param int         $uriid    Uri-Id of the post
-        * @return DOMElement XML activity object
+        * @return DOMElement|false XML activity object or false on error
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @todo  Find proper type-hints
         */
        private static function createActivity(DOMDocument $doc, string $element, string $activity, int $uriid)
        {
-               if ($activity) {
-                       $entry = $doc->createElement($element);
+               if (!$activity) {
+                       return false;
+               }
 
-                       $r = XML::parseString($activity);
-                       if (!$r) {
-                               return false;
-                       }
+               $entry = $doc->createElement($element);
 
-                       if ($r->type) {
-                               XML::addElement($doc, $entry, "activity:object-type", $r->type);
-                       }
+               $r = XML::parseString($activity);
+               if (!$r) {
+                       return false;
+               }
 
-                       if ($r->id) {
-                               XML::addElement($doc, $entry, "id", $r->id);
-                       }
+               if ($r->type) {
+                       XML::addElement($doc, $entry, "activity:object-type", $r->type);
+               }
 
-                       if ($r->title) {
-                               XML::addElement($doc, $entry, "title", $r->title);
-                       }
+               if ($r->id) {
+                       XML::addElement($doc, $entry, "id", $r->id);
+               }
 
-                       if ($r->link) {
-                               if (substr($r->link, 0, 1) == '<') {
-                                       if (strstr($r->link, '&') && (! strstr($r->link, '&amp;'))) {
-                                               $r->link = str_replace('&', '&amp;', $r->link);
-                                       }
+               if ($r->title) {
+                       XML::addElement($doc, $entry, "title", $r->title);
+               }
 
-                                       $r->link = preg_replace('/\<link(.*?)\"\>/', '<link$1"/>', $r->link);
-
-                                       // XML does need a single element as root element so we add a dummy element here
-                                       $data = XML::parseString("<dummy>" . $r->link . "</dummy>");
-                                       if (is_object($data)) {
-                                               foreach ($data->link as $link) {
-                                                       $attributes = [];
-                                                       foreach ($link->attributes() as $parameter => $value) {
-                                                               $attributes[$parameter] = $value;
-                                                       }
-                                                       XML::addElement($doc, $entry, "link", "", $attributes);
+               if ($r->link) {
+                       if (substr($r->link, 0, 1) == '<') {
+                               if (strstr($r->link, '&') && (! strstr($r->link, '&amp;'))) {
+                                       $r->link = str_replace('&', '&amp;', $r->link);
+                               }
+
+                               $r->link = preg_replace('/\<link(.*?)\"\>/', '<link$1"/>', $r->link);
+
+                               // XML does need a single element as root element so we add a dummy element here
+                               $data = XML::parseString("<dummy>" . $r->link . "</dummy>");
+                               if (is_object($data)) {
+                                       foreach ($data->link as $link) {
+                                               $attributes = [];
+                                               foreach ($link->attributes() as $parameter => $value) {
+                                                       $attributes[$parameter] = $value;
                                                }
+                                               XML::addElement($doc, $entry, "link", "", $attributes);
                                        }
-                               } else {
-                                       $attributes = ["rel" => "alternate", "type" => "text/html", "href" => $r->link];
-                                       XML::addElement($doc, $entry, "link", "", $attributes);
                                }
+                       } else {
+                               $attributes = ["rel" => "alternate", "type" => "text/html", "href" => $r->link];
+                               XML::addElement($doc, $entry, "link", "", $attributes);
                        }
-                       if ($r->content) {
-                               XML::addElement($doc, $entry, "content", BBCode::convertForUriId($uriid, $r->content, BBCode::EXTERNAL), ["type" => "html"]);
-                       }
-
-                       return $entry;
+               }
+               if ($r->content) {
+                       XML::addElement($doc, $entry, "content", BBCode::convertForUriId($uriid, $r->content, BBCode::EXTERNAL), ["type" => "html"]);
                }
 
-               return false;
+               return $entry;
        }
 
        /**
@@ -1925,7 +1925,7 @@ class DFRN
                // Check if the message is wanted
                if (!self::isSolicitedMessage($item, $importer)) {
                        DBA::delete('item-uri', ['uri' => $item['uri']]);
-                       return 403;
+                       return;
                }
 
                // Get the type of the item (Top level post, reply or remote reply)
@@ -2051,7 +2051,7 @@ class DFRN
                                        Item::distribute($posted_id);
                                }
 
-                               return true;
+                               return;
                        }
                } else { // $entrytype == self::TOP_LEVEL
                        if (($item['uid'] != 0) && !Contact::isSharing($item['owner-id'], $item['uid']) && !Contact::isSharing($item['author-id'], $item['uid'])) {
@@ -2099,7 +2099,7 @@ class DFRN
                }
 
                if (!$uri || !$importer['id']) {
-                       return false;
+                       return;
                }
 
                $condition = ['uri' => $uri, 'uid' => $importer['importer_uid']];
index a8db02f045aecc476722a8d4f6c12000bf221219..0166e65f9dfe13dad22e9f9ebea444ffffc54007 100644 (file)
@@ -337,7 +337,7 @@ class Diaspora
         * @param string $xml      urldecoded Diaspora salmon
         * @param string $privKey  The private key of the importer
         *
-        * @return array
+        * @return array|false array with decoded data or false on error
         * 'message' -> decoded Diaspora XML message
         * 'author' -> author diaspora handle
         * 'key' -> author public key (converted to pkcs#8)
@@ -1051,7 +1051,7 @@ class Diaspora
         * @param string $server The url of the server
         * @param int    $level  Endless loop prevention
         *
-        * @return array
+        * @return array|false The message as array or false on error
         *      'message' => The message XML
         *      'author' => The author handle
         *      'key' => The public key of the author
@@ -2795,7 +2795,7 @@ class Diaspora
                // without a public key nothing will work
                if (!$pubkey) {
                        DI::logger()->notice('pubkey missing: contact id: ' . $contact['id']);
-                       return false;
+                       return '';
                }
 
                $aes_key   = random_bytes(32);
@@ -2809,7 +2809,7 @@ class Diaspora
 
                $encrypted_key_bundle = '';
                if (!@openssl_public_encrypt($json, $encrypted_key_bundle, $pubkey)) {
-                       return false;
+                       return '';
                }
 
                $json_object = json_encode(