]> git.mxchange.org Git - friendica.git/commitdiff
Fix various PHP 8 deprecations
authorHypolite Petovan <hypolite@mrpetovan.com>
Sun, 20 Nov 2022 00:10:02 +0000 (19:10 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Sun, 20 Nov 2022 00:15:47 +0000 (19:15 -0500)
src/Content/Nav.php
src/Model/APContact.php
src/Model/Item.php
src/Model/Post/Media.php
src/Module/Home.php
src/Network/HTTPClient/Client/HttpClient.php
src/Protocol/Diaspora.php
src/Render/FriendicaSmartyEngine.php
src/Worker/Notifier.php
view/theme/frio/php/PHPColors/Color.php

index 0000b3d2962f3b35c390d61fb3f0fba195937f41..cb2edb4eb6f2dbf7b4108dbd258b22a3412768e8 100644 (file)
@@ -244,12 +244,8 @@ class Nav
                }
 
                $gdirpath = 'directory';
-
-               if (strlen(DI::config()->get('system', 'singleuser'))) {
-                       $gdir = DI::config()->get('system', 'directory');
-                       if (strlen($gdir)) {
-                               $gdirpath = Profile::zrl($gdir, true);
-                       }
+               if (DI::config()->get('system', 'singleuser') && DI::config()->get('system', 'directory')) {
+                       $gdirpath = Profile::zrl(DI::config()->get('system', 'directory'), true);
                }
 
                if ((DI::userSession()->getLocalUserId() || DI::config()->get('system', 'community_page_style') != Community::DISABLED_VISITOR) &&
index 742efcf190cae7561dcc2e679c2c5010046788c1..3b568f39f1d85c5c7be8880668adfe97d7c94e43 100644 (file)
@@ -383,7 +383,7 @@ class APContact
                // kroeg:blocks, updated
 
                // When the photo is too large, try to shorten it by removing parts
-               if (strlen($apcontact['photo']) > 255) {
+               if (strlen($apcontact['photo'] ?? '') > 255) {
                        $parts = parse_url($apcontact['photo']);
                        unset($parts['fragment']);
                        $apcontact['photo'] = (string)Uri::fromParts($parts);
@@ -574,7 +574,7 @@ class APContact
         *
         * @param array $apcontact
         *
-        * @return bool 
+        * @return bool
         */
        public static function isRelay(array $apcontact): bool
        {
index 900bf3a2c44c331a8cd1248ac1bf5dd53d98a659..7c8804a290be279e774094b76378de2f46324628 100644 (file)
@@ -210,7 +210,7 @@ class Item
                                                $fields['raw-body'] = BBCode::removeSharedData($fields['raw-body']);
                                        }
                                }
-               
+
                                Post\Media::insertFromAttachmentData($item['uri-id'], $fields['body']);
 
                                $content_fields = ['raw-body' => trim($fields['raw-body'] ?? $fields['body'])];
@@ -337,7 +337,7 @@ class Item
                 * generate a resource-id and therefore aren't intimately linked to the item.
                 */
                /// @TODO: this should first check if photo is used elsewhere
-               if (strlen($item['resource-id'])) {
+               if ($item['resource-id']) {
                        Photo::delete(['resource-id' => $item['resource-id'], 'uid' => $item['uid']]);
                }
 
index 6cee11e6c88659ac03736b074c01338c034aa62b..04c0db0f80aefea2ed8583a69b6dbe3fe706bbab 100644 (file)
@@ -279,7 +279,7 @@ class Media
                if (!empty($contact['gsid'])) {
                        $gserver = DBA::selectFirst('gserver', ['url', 'site_name'], ['id' => $contact['gsid']]);
                }
-               
+
                $media['type'] = self::ACTIVITY;
                $media['media-uri-id'] = $item['uri-id'];
                $media['height'] = null;
@@ -687,7 +687,7 @@ class Media
                                $previews[] = $medium['preview'];
                        }
 
-                       $type = explode('/', current(explode(';', $medium['mimetype'])));
+                       $type = explode('/', explode(';', $medium['mimetype'])[0]);
                        if (count($type) < 2) {
                                Logger::info('Unknown MimeType', ['type' => $type, 'media' => $medium]);
                                $filetype = 'unkn';
index ca4c4b89596a8e1af0e99ffba57b4825aa9360b2..06bfa5eba576aca4a22ceb88c348d0e9f1ce6864 100644 (file)
@@ -46,7 +46,7 @@ class Home extends BaseModule
                        DI::baseUrl()->redirect('network');
                }
 
-               if (strlen($config->get('system', 'singleuser'))) {
+               if ($config->get('system', 'singleuser')) {
                        DI::baseUrl()->redirect('/profile/' . $config->get('system', 'singleuser'));
                }
 
index cfc8fbfab1f0f3667f95e5a3a323dff9bd6f7860..32a1a22fc2b0b18b346d181f858a828d541fbbc7 100644 (file)
@@ -254,7 +254,7 @@ class HttpClient implements ICanSendHttpRequests
                $urlResult = $this->resolver->resolveURL($url);
 
                if ($urlResult->didErrorOccur()) {
-                       throw new TransferException($urlResult->getErrorMessageString(), $urlResult->getHTTPStatusCode());
+                       throw new TransferException($urlResult->getErrorMessageString(), $urlResult->getHTTPStatusCode() ?? 0);
                }
 
                return $urlResult->getURL();
index 8a5969dde105aed1a09b40c520fdd3a45f5a82cf..09f4380b0b1eb5d7210f18052d38d4e89751b31a 100644 (file)
@@ -3638,7 +3638,7 @@ class Diaspora
 
                Logger::info('Got relayable data ' . $type . ' for item ' . $item['guid'] . ' (' . $item['id'] . ')');
 
-               $msg = json_decode($item['signed_text'], true);
+               $msg = json_decode($item['signed_text'] ?? '', true);
 
                $message = [];
                if (is_array($msg)) {
index 5ea01166fd49a0d14dab88221e8a487800e995cd..201d99f82293f5dc6fa7ccf9a1871a4f746759c3 100644 (file)
@@ -81,7 +81,7 @@ final class FriendicaSmartyEngine extends TemplateEngine
 
                // "middleware": inject variables into templates
                $arr = [
-                       'template' => basename($this->smarty->filename),
+                       'template' => basename($this->smarty->filename ?? ''),
                        'vars' => $vars
                ];
                Hook::callAll('template_vars', $arr);
index 10fe6e3abceb0ac2d7c2fa956f10657a8bada33a..db593b6a4748fdf9b1fa5a0eaa3cf97de7645a2e 100644 (file)
@@ -336,7 +336,7 @@ class Notifier
                                foreach ($items as $item) {
                                        $recipients[] = $item['contact-id'];
                                        // pull out additional tagged people to notify (if public message)
-                                       if ($public_message && strlen($item['inform'])) {
+                                       if ($public_message && $item['inform']) {
                                                $people = explode(',',$item['inform']);
                                                foreach ($people as $person) {
                                                        if (substr($person,0,4) === 'cid:') {
index e4de79c40a764d3a30734decd1bb83c5b9d6bd70..30de5799665c55fc763e6dd842eb4d1ad96ded25 100644 (file)
@@ -132,16 +132,16 @@ class Color {
 
             $var_1 = 2 * $L - $var_2;
 
-            $r = round(255 * self::_huetorgb( $var_1, $var_2, $H + (1/3) ));
-            $g = round(255 * self::_huetorgb( $var_1, $var_2, $H ));
-            $b = round(255 * self::_huetorgb( $var_1, $var_2, $H - (1/3) ));
+            $r = 255 * self::_huetorgb( $var_1, $var_2, $H + (1/3) );
+            $g = 255 * self::_huetorgb( $var_1, $var_2, $H );
+            $b = 255 * self::_huetorgb( $var_1, $var_2, $H - (1/3) );
 
         }
 
         // Convert to hex
-        $r = dechex($r);
-        $g = dechex($g);
-        $b = dechex($b);
+        $r = dechex(round($r));
+        $g = dechex(round($g));
+        $b = dechex(round($b));
 
         // Make sure we get 2 digits for decimals
         $r = (strlen("".$r)===1) ? "0".$r:$r;