]> git.mxchange.org Git - friendica.git/commitdiff
Changes:
authorRoland Häder <roland@mxchange.org>
Fri, 12 Aug 2022 12:00:02 +0000 (14:00 +0200)
committerRoland Häder <roland@mxchange.org>
Fri, 12 Aug 2022 12:01:40 +0000 (14:01 +0200)
- added missing type-hints
- added documentation
- removed parameter $baseURL while it can be locally get the same way but
  lesser parameter
- used ActivityNamespace::SALMON_ME
- changed double-quotes to single

src/Moderation/DomainPatternBlocklist.php
src/Module/Api/ApiResponse.php
src/Module/Api/Friendica/Profile/Show.php
src/Module/Api/Twitter/ContactEndpoint.php
src/Module/Api/Twitter/DirectMessagesEndpoint.php
src/Module/Xrd.php
src/Navigation/Notifications/Repository/Notification.php
src/Navigation/Notifications/Repository/Notify.php
src/Protocol/Diaspora.php
src/Protocol/Salmon.php

index a57b5f04cbf2437a24ce5c45f02fbe979e822b15..7b6cf997aab1df9196df7fddcdfa641416761365 100644 (file)
@@ -73,6 +73,7 @@ class DomainPatternBlocklist
        /**
         * @param string $pattern
         * @param string $reason
+        *
         * @return int 0 if the block list couldn't be saved, 1 if the pattern was added, 2 if it was updated in place
         */
        public function addPattern(string $pattern, string $reason): int
@@ -105,6 +106,7 @@ class DomainPatternBlocklist
 
        /**
         * @param string $pattern
+        *
         * @return int 0 if the block list couldn't be saved, 1 if the pattern wasn't found, 2 if it was removed
         */
        public function removePattern(string $pattern): int
@@ -123,6 +125,13 @@ class DomainPatternBlocklist
                return $found ? ($this->set($blocklist) ? 2 : 0) : 1;
        }
 
+       /**
+        * @param string $filename
+        *
+        * @return void
+        * @throws Exception
+        * @todo maybe throw more explicit exception
+        */
        public function exportToFile(string $filename)
        {
                $fp = fopen($filename, 'w');
@@ -165,6 +174,7 @@ class DomainPatternBlocklist
         * Extracts a server domain pattern block list from the provided CSV file name. Deduplicates the list based on patterns.
         *
         * @param string $filename
+        *
         * @return array
         * @throws Exception
         */
index 0eb2f644b9fc57b5a893dad58c94914890dd524a..960ce3d2cb67460157939e99eaf9f6506a056454 100644 (file)
@@ -109,7 +109,7 @@ class ApiResponse extends Response
         * @param int   $cid Contact ID of template
         * @return array
         */
-       private function addRSSValues(array $arr, int $cid)
+       private function addRSSValues(array $arr, int $cid): array
        {
                if (empty($cid)) {
                        return $arr;
@@ -244,6 +244,8 @@ class ApiResponse extends Response
         * Wrapper around exit() for JSON only responses
         *
         * @param array $data
+        *
+        * @return void
         */
        public function exitWithJson(array $data)
        {
index 67f4e22edf308f301ece1e300bfab997b10044b2..6b583b936a261bac36234bae324cdddee51e01d6 100644 (file)
@@ -68,10 +68,11 @@ class Show extends BaseApi
        /**
         * @param array         $profile_row array containing data from db table 'profile'
         * @param ProfileFields $profileFields
+        *
         * @return array
         * @throws HTTPException\InternalServerErrorException
         */
-       private static function formatProfile($profile_row, ProfileFields $profileFields)
+       private static function formatProfile($profile_row, ProfileFields $profileFields): array
        {
                $custom_fields = [];
                foreach ($profileFields as $profileField) {
index fb165f1cadea06f684994080b7b327b367aa1e78..ea2edb30e9fa99aae9cf8c038bbc821d5dced3c7 100644 (file)
@@ -95,7 +95,7 @@ abstract class ContactEndpoint extends BaseApi
         * @throws HTTPException\NotFoundException
         * @throws \ImagickException
         */
-       protected static function list(array $ids, int $total_count, int $uid, int $cursor = -1, int $count = self::DEFAULT_COUNT, bool $skip_status = false, bool $include_user_entities = true)
+       protected static function list(array $ids, int $total_count, int $uid, int $cursor = -1, int $count = self::DEFAULT_COUNT, bool $skip_status = false, bool $include_user_entities = true): array
        {
                $return = self::ids($ids, $total_count, $cursor, $count, false);
 
@@ -128,7 +128,7 @@ abstract class ContactEndpoint extends BaseApi
         * @return array
         * @throws HTTPException\NotFoundException
         */
-       protected static function ids(array $ids, int $total_count, int $cursor = -1, int $count = self::DEFAULT_COUNT, bool $stringify_ids = false)
+       protected static function ids(array $ids, int $total_count, int $cursor = -1, int $count = self::DEFAULT_COUNT, bool $stringify_ids = false): array
        {
                $next_cursor = 0;
                $previous_cursor = 0;
index 5505c6c44c201b088562502b6098fc13dac7b539..2f385e3db74add44c18ad0556f8cda8a3f3f78b1 100644 (file)
@@ -54,6 +54,8 @@ abstract class DirectMessagesEndpoint extends BaseApi
         * @param array $request
         * @param int   $uid
         * @param array $condition
+        *
+        * @return void
         */
        protected function getMessages(array $request, int $uid, array $condition)
        {
index 1fc0431095d5e52dccd001b9723b445c52d02e57..9420a2c61a8cdf5028cfa7138c80f8fc5b65fb6c 100644 (file)
@@ -102,9 +102,9 @@ class Xrd extends BaseModule
                }
 
                if ($mode == Response::TYPE_XML) {
-                       self::printXML($alias, DI::baseUrl()->get(), $user, $owner, $avatar);
+                       self::printXML($alias, $user, $owner, $avatar);
                } else {
-                       self::printJSON($alias, DI::baseUrl()->get(), $owner, $avatar);
+                       self::printJSON($alias, $owner, $avatar);
                }
        }
 
@@ -153,8 +153,9 @@ class Xrd extends BaseModule
                System::jsonExit($json, 'application/jrd+json; charset=utf-8');
        }
 
-       private static function printJSON($alias, $baseURL, $owner, $avatar)
+       private static function printJSON(string $alias, array $owner, array $avatar)
        {
+               $baseURL = DI::baseUrl()->get();
                $salmon_key = Salmon::salmonKey($owner['spubkey']);
 
                $json = [
@@ -234,8 +235,9 @@ class Xrd extends BaseModule
                System::jsonExit($json, 'application/jrd+json; charset=utf-8');
        }
 
-       private static function printXML($alias, $baseURL, $user, $owner, $avatar)
+       private static function printXML(string $alias, array $user, array $owner, array $avatar)
        {
+               $baseURL = DI::baseUrl()->get();
                $salmon_key = Salmon::salmonKey($owner['spubkey']);
 
                $tpl = Renderer::getMarkupTemplate('xrd_person.tpl');
index bb835c33e9531e042a7d07d08a2eceb18a8a91ed..9b7b5c1033ec6541def4c4bb6e594419ca14ce57 100644 (file)
@@ -112,6 +112,7 @@ class Notification extends BaseRepository
         * Returns only the most recent notifications for the same conversation or contact
         *
         * @param int $uid
+        *
         * @return Collection\Notifications
         * @throws Exception
         */
@@ -139,6 +140,7 @@ class Notification extends BaseRepository
         * Returns only the most recent notifications for the same conversation or contact
         *
         * @param int $uid
+        *
         * @return Collection\Notifications
         * @throws Exception
         */
@@ -201,6 +203,7 @@ class Notification extends BaseRepository
         * @param int|null $min_id Retrieve models with an id no fewer than this, as close to it as possible
         * @param int|null $max_id Retrieve models with an id no greater than this, as close to it as possible
         * @param int      $limit
+        *
         * @return BaseCollection
         * @throws Exception
         * @see _selectByBoundaries
index 8fb0f5fb072d92a8b5a70d07c4641b7fab7ba953..813f91263bc05817bc378ad090049c4e56434bb6 100644 (file)
@@ -88,6 +88,7 @@ class Notify extends BaseRepository
        /**
         * @param array $condition
         * @param array $params
+        *
         * @return Entity\Notify
         * @throws HTTPException\NotFoundException
         */
@@ -117,6 +118,7 @@ class Notify extends BaseRepository
 
        /**
         * @param int $id
+        *
         * @return Entity\Notify
         * @throws HTTPException\NotFoundException
         */
@@ -153,6 +155,7 @@ class Notify extends BaseRepository
 
        /**
         * @param Entity\Notify $Notify
+        *
         * @return Entity\Notify
         * @throws HTTPException\NotFoundException
         * @throws HTTPException\InternalServerErrorException
@@ -459,7 +462,7 @@ class Notify extends BaseRepository
 
                        case Model\Notification\Type::SYSTEM:
                                switch($params['event']) {
-                                       case "SYSTEM_REGISTER_REQUEST":
+                                       case 'SYSTEM_REGISTER_REQUEST':
                                                $itemlink =  $params['link'];
                                                $subject = $l10n->t('[Friendica System Notify]') . ' ' . $l10n->t('registration request');
 
@@ -479,7 +482,8 @@ class Notify extends BaseRepository
                                                $tsitelink = sprintf($sitelink, $params['link']);
                                                $hsitelink = sprintf($sitelink, '<a href="'.$params['link'].'">'.$sitename.'</a><br><br>');
                                                break;
-                                       case "SYSTEM_DB_UPDATE_FAIL":
+
+                                       case 'SYSTEM_DB_UPDATE_FAIL': // @TODO Unused (only here)
                                                break;
                                }
                                break;
@@ -492,7 +496,7 @@ class Notify extends BaseRepository
                return $this->storeAndSend($params, $sitelink, $tsitelink, $hsitelink, $title, $subject, $preamble, $epreamble, $body, $itemlink, $show_in_notification_page);
        }
 
-       private function storeAndSend($params, $sitelink, $tsitelink, $hsitelink, $title, $subject, $preamble, $epreamble, $body, $itemlink, $show_in_notification_page)
+       private function storeAndSend(array $params, string $sitelink, string $tsitelink, string $hsitelink, string $title, string $subject, string $preamble, string $epreamble, string $body, string $itemlink, bool $show_in_notification_page): bool
        {
                $item_id = $params['item']['id'] ?? 0;
                $uri_id = $params['item']['uri-id'] ?? null;
@@ -671,7 +675,7 @@ class Notify extends BaseRepository
                return false;
        }
 
-       public function createFromNotification(Entity\Notification $Notification)
+       public function createFromNotification(Entity\Notification $Notification): bool
        {
                $this->logger->info('Start', ['uid' => $Notification->uid, 'id' => $Notification->id, 'type' => $Notification->type]);
 
index bec4fd333fa1219e1374341efeb5fe549bbd5fa6..045992333ea8bd316a28e2d8236330de9698d9c8 100644 (file)
@@ -128,7 +128,7 @@ class Diaspora
                        return false;
                }
 
-               $children = $basedom->children('http://salmon-protocol.org/ns/magic-env');
+               $children = $basedom->children(ActivityNamespace::SALMON_ME);
 
                if (sizeof($children) == 0) {
                        Logger::notice('XML has no children');
@@ -2969,7 +2969,7 @@ class Diaspora
                        ]
                ];
 
-               $namespaces = ['me' => 'http://salmon-protocol.org/ns/magic-env'];
+               $namespaces = ['me' => ActivityNamespace::SALMON_ME];
 
                return XML::fromArray($xmldata, $xml, false, $namespaces);
        }
index 7a4e8cc94e3d3940e046b7d5e10c47efde387a9d..b1bdb67e1dd206074cbe0e250f3de3ff2af28392 100644 (file)
@@ -145,14 +145,18 @@ class Salmon
                $signature3  = Strings::base64UrlEncode(Crypto::rsaSign($data, $owner['sprvkey']));
 
                // At first try the non compliant method that works for GNU Social
-               $xmldata = ["me:env" => ["me:data" => $data,
-                               "@attributes" => ["type" => $data_type],
-                               "me:encoding" => $encoding,
-                               "me:alg" => $algorithm,
-                               "me:sig" => $signature,
-                               "@attributes2" => ["key_id" => $keyhash]]];
-
-               $namespaces = ["me" => "http://salmon-protocol.org/ns/magic-env"];
+               $xmldata = [
+                       'me:env' => [
+                               'me:data' => $data,
+                               '@attributes' => ['type' => $data_type],
+                               'me:encoding' => $encoding,
+                               'me:alg' => $algorithm,
+                               'me:sig' => $signature,
+                               '@attributes2' => ['key_id' => $keyhash],
+                       ]
+               ];
+
+               $namespaces = ['me' => ActivityNamespace::SALMON_ME];
 
                $salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
 
@@ -170,14 +174,18 @@ class Salmon
                        Logger::notice('GNU Social salmon failed. Falling back to compliant mode');
 
                        // Now try the compliant mode that normally isn't used for GNU Social
-                       $xmldata = ["me:env" => ["me:data" => $data,
-                                       "@attributes" => ["type" => $data_type],
-                                       "me:encoding" => $encoding,
-                                       "me:alg" => $algorithm,
-                                       "me:sig" => $signature2,
-                                       "@attributes2" => ["key_id" => $keyhash]]];
-
-                       $namespaces = ["me" => "http://salmon-protocol.org/ns/magic-env"];
+                       $xmldata = [
+                               'me:env' => [
+                                       'me:data' => $data,
+                                       '@attributes' => ['type' => $data_type],
+                                       'me:encoding' => $encoding,
+                                       'me:alg' => $algorithm,
+                                       'me:sig' => $signature2,
+                                       '@attributes2' => ['key_id' => $keyhash]
+                               ]
+                       ];
+
+                       $namespaces = ['me' => ActivityNamespace::SALMON_ME];
 
                        $salmon = XML::fromArray($xmldata, $xml, false, $namespaces);
 
@@ -193,14 +201,18 @@ class Salmon
                        Logger::notice('compliant salmon failed. Falling back to old status.net');
 
                        // Last try. This will most likely fail as well.
-                       $xmldata = ["me:env" => ["me:data" => $data,
-                                       "@attributes" => ["type" => $data_type],
-                                       "me:encoding" => $encoding,
-                                       "me:alg" => $algorithm,
-                                       "me:sig" => $signature3,
-                                       "@attributes2" => ["key_id" => $keyhash]]];
-
-                       $namespaces = ["me" => "http://salmon-protocol.org/ns/magic-env"];
+                       $xmldata = [
+                               'me:env' => [
+                                       'me:data' => $data,
+                                       '@attributes' => ['type' => $data_type],
+                                       'me:encoding' => $encoding,
+                                       'me:alg' => $algorithm,
+                                       'me:sig' => $signature3,
+                                       '@attributes2' => ['key_id' => $keyhash],
+                               ]
+                       ];
+
+                       $namespaces = ['me' => ActivityNamespace::SALMON_ME];
 
                        $salmon = XML::fromArray($xmldata, $xml, false, $namespaces);