]> git.mxchange.org Git - friendica.git/commitdiff
[Scrutinizer] Fix undeclared variables in src/ (except Protocol/)
authorHypolite Petovan <mrpetovan@gmail.com>
Wed, 14 Feb 2018 05:05:00 +0000 (00:05 -0500)
committerHypolite Petovan <mrpetovan@gmail.com>
Wed, 14 Feb 2018 05:05:00 +0000 (00:05 -0500)
- Use dba::selectFirst to remove intermediate variables `$r`
- Remove unused variable `$url_recipients` in Worker\Dellivery

17 files changed:
src/Core/Cache.php
src/Core/Worker.php
src/Database/DBStructure.php
src/Model/Contact.php
src/Model/GContact.php
src/Model/Item.php
src/Model/Mail.php
src/Model/Photo.php
src/Model/Profile.php
src/Model/User.php
src/Network/Probe.php
src/Util/ParseUrl.php
src/Util/XML.php
src/Worker/Delivery.php
src/Worker/DiscoverPoCo.php
src/Worker/Notifier.php
src/Worker/OnePoll.php

index 70a9b9f292607489948a55c8f58a7c267bd4b6f8..5ceb97676fcbcaf2ea5cf190349a3719d0749f9a 100644 (file)
@@ -76,6 +76,7 @@ class Cache
                                $seconds = 300;
                                break;
                        case CACHE_MINUTE:
+                       default:
                                $seconds = 60;
                                break;
                }
index 140d0e014d5f348aa7f910909bba5472639cc3e3..f5979a82ab9f4c697a91e0990fdc6b4a3022136b 100644 (file)
@@ -389,9 +389,10 @@ class Worker
                if (Config::get("system", "profiler")) {
                        $duration = microtime(true)-$a->performance["start"];
 
+                       $o = '';
                        if (Config::get("rendertime", "callstack")) {
                                if (isset($a->callstack["database"])) {
-                                       $o = "\nDatabase Read:\n";
+                                       $o .= "\nDatabase Read:\n";
                                        foreach ($a->callstack["database"] as $func => $time) {
                                                $time = round($time, 3);
                                                if ($time > 0) {
@@ -417,8 +418,6 @@ class Worker
                                                }
                                        }
                                }
-                       } else {
-                               $o = '';
                        }
 
                        logger(
@@ -564,6 +563,7 @@ class Worker
                                        // We killed the stale process.
                                        // To avoid a blocking situation we reschedule the process at the beginning of the queue.
                                        // Additionally we are lowering the priority. (But not PRIORITY_CRITICAL)
+                                       $new_priority = $entry["priority"];
                                        if ($entry["priority"] == PRIORITY_HIGH) {
                                                $new_priority = PRIORITY_MEDIUM;
                                        } elseif ($entry["priority"] == PRIORITY_MEDIUM) {
@@ -768,7 +768,7 @@ class Worker
                $limit = min($queue_length, ceil($slope * pow($jobs, $exponent)));
 
                logger('Total: '.$jobs.' - Maximum: '.$queue_length.' - jobs per queue: '.$limit, LOGGER_DEBUG);
-
+               $ids = [];
                if (self::passingSlow($highest_priority)) {
                        // Are there waiting processes with a higher priority than the currently highest?
                        $result = dba::select(
index 9a1c8a2d52c9f6c0bd6186dd6ce60ada336512a3..12cf71861d6609f60a602013ec8112bd0273d24d 100644 (file)
@@ -244,19 +244,18 @@ class DBStructure
 
                // Compare it
                foreach ($definition AS $name => $structure) {
-                       $is_new_table = False;
+                       $is_new_table = false;
                        $group_by = "";
                        $sql3 = "";
+                       $is_unique = false;
+                       $temp_name = $name;
                        if (!isset($database[$name])) {
                                $r = self::createTable($name, $structure["fields"], $verbose, $action, $structure['indexes']);
                                if (!DBM::is_result($r)) {
                                        $errors .= self::printUpdateError($name);
                                }
-                               $is_new_table = True;
+                               $is_new_table = true;
                        } else {
-                               $is_unique = false;
-                               $temp_name = $name;
-
                                foreach ($structure["indexes"] AS $indexname => $fieldnames) {
                                        if (isset($database[$name]["indexes"][$indexname])) {
                                                $current_index_definition = implode(",",$database[$name]["indexes"][$indexname]);
@@ -463,7 +462,7 @@ class DBStructure
                                                if ($ignore != "") {
                                                        dba::e("SET session old_alter_table=1;");
                                                } else {
-                                                       dba::e("DROP TABLE IF EXISTS `".$temp_name."`;");
+                                                       $r = dba::e("DROP TABLE IF EXISTS `".$temp_name."`;");
                                                        if (!DBM::is_result($r)) {
                                                                $errors .= self::printUpdateError($sql3);
                                                                return $errors;
index 1d31c6cb5b38f5a50a547f2d54b1e2fcb4aeb341..7415bac0a958bd5d1efc9236d93f5f4193a6cae3 100644 (file)
@@ -1365,6 +1365,7 @@ class Contact extends BaseObject
                $url = notags(trim($datarray['author-link']));
                $name = notags(trim($datarray['author-name']));
                $photo = notags(trim($datarray['author-avatar']));
+               $nick = '';
 
                if (is_object($item)) {
                        $rawtag = $item->get_item_tags(NAMESPACE_ACTIVITY,'actor');
@@ -1398,20 +1399,16 @@ class Contact extends BaseObject
                                intval(CONTACT_IS_FOLLOWER)
                        );
 
-                       $r = q("SELECT `id`, `network` FROM `contact` WHERE `uid` = %d AND `url` = '%s' AND `pending` = 1 LIMIT 1",
-                                       intval($importer['uid']),
-                                       dbesc($url)
-                       );
-                       if (DBM::is_result($r)) {
-                               $contact_record = $r[0];
-                               Contact::updateAvatar($photo, $importer["uid"], $contact_record["id"], true);
-                       }
+                       $contact_record = [
+                               'id' => dba::lastInsertId(),
+                               'network' => NETWORK_OSTATUS
+                       ];
+                       Contact::updateAvatar($photo, $importer["uid"], $contact_record["id"], true);
 
                        /// @TODO Encapsulate this into a function/method
-                       $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
-                               intval($importer['uid'])
-                       );
-                       if (DBM::is_result($r) && !in_array($r[0]['page-flags'], [PAGE_SOAPBOX, PAGE_FREELOVE, PAGE_COMMUNITY])) {
+                       $fields = ['uid', 'username', 'email', 'page-flags', 'notify-flags', 'language'];
+                       $user = dba::selectFirst('user', $fields, ['uid' => $importer['uid']]);
+                       if (DBM::is_result($user) && !in_array($user['page-flags'], [PAGE_SOAPBOX, PAGE_FREELOVE, PAGE_COMMUNITY])) {
                                // create notification
                                $hash = random_string();
 
@@ -1423,16 +1420,16 @@ class Contact extends BaseObject
 
                                Group::addMember(User::getDefaultGroup($importer['uid'], $contact_record["network"]), $contact_record['id']);
 
-                               if (($r[0]['notify-flags'] & NOTIFY_INTRO) &&
-                                       in_array($r[0]['page-flags'], [PAGE_NORMAL])) {
+                               if (($user['notify-flags'] & NOTIFY_INTRO) &&
+                                       in_array($user['page-flags'], [PAGE_NORMAL])) {
 
                                        notification([
                                                'type'         => NOTIFY_INTRO,
-                                               'notify_flags' => $r[0]['notify-flags'],
-                                               'language'     => $r[0]['language'],
-                                               'to_name'      => $r[0]['username'],
-                                               'to_email'     => $r[0]['email'],
-                                               'uid'          => $r[0]['uid'],
+                                               'notify_flags' => $user['notify-flags'],
+                                               'language'     => $user['language'],
+                                               'to_name'      => $user['username'],
+                                               'to_email'     => $user['email'],
+                                               'uid'          => $user['uid'],
                                                'link'             => System::baseUrl() . '/notifications/intro',
                                                'source_name'  => ((strlen(stripslashes($contact_record['name']))) ? stripslashes($contact_record['name']) : L10n::t('[Name Withheld]')),
                                                'source_link'  => $contact_record['url'],
@@ -1442,13 +1439,12 @@ class Contact extends BaseObject
                                        ]);
 
                                }
-                       } elseif (DBM::is_result($r) && in_array($r[0]['page-flags'], [PAGE_SOAPBOX, PAGE_FREELOVE, PAGE_COMMUNITY])) {
+                       } elseif (DBM::is_result($user) && in_array($user['page-flags'], [PAGE_SOAPBOX, PAGE_FREELOVE, PAGE_COMMUNITY])) {
                                q("UPDATE `contact` SET `pending` = 0 WHERE `uid` = %d AND `url` = '%s' AND `pending` LIMIT 1",
                                                intval($importer['uid']),
                                                dbesc($url)
                                );
                        }
-
                }
        }
 
index e543e4baebf92b895e48aac4dc0718a170f9f8ac..7b14b2cdc4d19e42ce4cab9298f6a153aaa92343 100644 (file)
@@ -665,6 +665,8 @@ class GContact
        {
                $gcontact_id = 0;
                $doprobing = false;
+               $last_failure_str = '';
+               $last_contact_str = '';
 
                if (in_array($contact["network"], [NETWORK_PHANTOM])) {
                        logger("Invalid network for contact url ".$contact["url"]." - Called by: ".System::callstack(), LOGGER_DEBUG);
index fae3394bc32457944df984e2aa512a7dd5c7e95f..30fc4ecef9e1a90575be5c9b867c86405a62ffcc 100644 (file)
@@ -251,9 +251,8 @@ class Item extends BaseObject
                        $arr['network'] = trim(defaults($arr, 'network', NETWORK_PHANTOM));
                }
 
-               if ($notify) {
-                       $guid_prefix = "";
-               } elseif ((trim($arr['guid']) == "") && (trim($arr['plink']) != "")) {
+               $guid_prefix = '';
+               if ((trim($arr['guid']) == "") && (trim($arr['plink']) != "")) {
                        $arr['guid'] = self::guidFromUri($arr['plink']);
                } elseif ((trim($arr['guid']) == "") && (trim($arr['uri']) != "")) {
                        $arr['guid'] = self::guidFromUri($arr['uri']);
@@ -521,6 +520,11 @@ class Item extends BaseObject
 
                $arr['thr-parent'] = $arr['parent-uri'];
 
+               $notify_type = '';
+               $allow_cid = '';
+               $allow_gid = '';
+               $deny_cid  = '';
+               $deny_gid  = '';
                if ($arr['parent-uri'] === $arr['uri']) {
                        $parent_id = 0;
                        $parent_deleted = 0;
index b2e9e1a48734770b4b2ec5a0b9fcf05287eb0eda..81494e7ebb4e15dbcc0e1f8f8fef0416dcef23b3 100644 (file)
@@ -67,6 +67,7 @@ class Mail
                        }
                }
 
+               $convuri = '';
                if (!$convid) {
                        // create a new conversation
                        $recip_host = substr($contact['url'], strpos($contact['url'], '://') + 3);
index cf31849c8d23c1e2a7971c4cd3d2ffc9104a724c..e4e609155cc625d8f70e17d82ba71ac9bcb1686f 100644 (file)
@@ -91,6 +91,9 @@ class Photo
         */
        public static function importProfilePhoto($image_url, $uid, $cid, $quit_on_error = false)
        {
+               $thumb = '';
+               $micro = '';
+
                $photo = dba::selectFirst(
                        'photo', ['resource-id'], ['uid' => $uid, 'contact-id' => $cid, 'scale' => 4, 'album' => 'Contact Photos']
                );
index f79b89014b4e3299ecc5f9070d6b7d3929ac4529..f31c83c857f5cb4be4c3d14f15765946b0a26408 100644 (file)
@@ -565,8 +565,10 @@ class Profile
                                Cache::set($cachekey, $r, CACHE_HOUR);
                        }
                }
+
+               $total = 0;
+               $classtoday = '';
                if (DBM::is_result($r)) {
-                       $total = 0;
                        $now = strtotime('now');
                        $cids = [];
 
index f92611cb236fd966137e721836e834cdab90da15..eacd4ec33c7e936920ab3960465b65c4f9181d18 100644 (file)
@@ -157,6 +157,8 @@ class User
         */
        private static function getAuthenticationInfo($user_info)
        {
+               $user = null;
+
                if (is_object($user_info) || is_array($user_info)) {
                        if (is_object($user_info)) {
                                $user = (array) $user_info;
index dac01b1e53b8cc1255daf55002c093396ae55284..d14c623e864b7f6df93407f1fc52f21bbbd86ab5 100644 (file)
@@ -1542,29 +1542,31 @@ class Probe
                        return false;
                }
 
-               if ($uid != 0) {
-                       $x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1", intval($uid));
-
-                       $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval($uid));
-
-                       if (DBM::is_result($x) && DBM::is_result($r)) {
-                               $mailbox = Email::constructMailboxName($r[0]);
-                               $password = '';
-                               openssl_private_decrypt(hex2bin($r[0]['pass']), $password, $x[0]['prvkey']);
-                               $mbox = Email::connect($mailbox, $r[0]['user'], $password);
-                               if (!mbox) {
-                                       return false;
-                               }
-                       }
+               if ($uid == 0) {
+                       return false;
+               }
+
+               $x = q("SELECT `prvkey` FROM `user` WHERE `uid` = %d LIMIT 1", intval($uid));
 
-                       $msgs = Email::poll($mbox, $uri);
-                       logger('searching '.$uri.', '.count($msgs).' messages found.', LOGGER_DEBUG);
+               $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval($uid));
 
-                       if (!count($msgs)) {
+               if (DBM::is_result($x) && DBM::is_result($r)) {
+                       $mailbox = Email::constructMailboxName($r[0]);
+                       $password = '';
+                       openssl_private_decrypt(hex2bin($r[0]['pass']), $password, $x[0]['prvkey']);
+                       $mbox = Email::connect($mailbox, $r[0]['user'], $password);
+                       if (!$mbox) {
                                return false;
                        }
                }
 
+               $msgs = Email::poll($mbox, $uri);
+               logger('searching '.$uri.', '.count($msgs).' messages found.', LOGGER_DEBUG);
+
+               if (!count($msgs)) {
+                       return false;
+               }
+
                $phost = substr($uri, strpos($uri, '@') + 1);
 
                $data = [];
index e8094959d6b348b9c9c51e4bb5c855084d8a12a8..b267c610864326ed216d7e90e9ed64a70435bee7 100644 (file)
@@ -50,19 +50,11 @@ class ParseUrl
                        return false;
                }
 
-               $r = q(
-                       "SELECT * FROM `parsed_url` WHERE `url` = '%s' AND `guessing` = %d AND `oembed` = %d",
-                       dbesc(normalise_link($url)),
-                       intval(!$no_guessing),
-                       intval($do_oembed)
+               $parsed_url = dba::selectFirst('parsed_url', ['content'],
+                       ['url' => normalise_link($url), 'guessing' => !$no_guessing, 'oembed' => $do_oembed]
                );
-
-               if ($r) {
-                       $data = $r[0]["content"];
-               }
-
-               if (!is_null($data)) {
-                       $data = unserialize($data);
+               if (!empty($parsed_url['content'])) {
+                       $data = unserialize($parsed_url['content']);
                        return $data;
                }
 
index d8c5e032396df4f7626eab100f0700afff740836..8dc540324368b23af4d917c9e05956de333ade1e 100644 (file)
@@ -52,6 +52,7 @@ class XML
                        }
                }
 
+               $element = null;
                foreach ($array as $key => $value) {
                        if (!isset($element) && isset($xml)) {
                                $element = $xml;
@@ -185,12 +186,13 @@ class XML
                        return(null);
                }
 
+               $xml_element_copy = '';
                if (!is_string($xml_element)
                        && !is_array($xml_element)
                        && (get_class($xml_element) == 'SimpleXMLElement')
                ) {
-                               $xml_element_copy = $xml_element;
-                               $xml_element = get_object_vars($xml_element);
+                       $xml_element_copy = $xml_element;
+                       $xml_element = get_object_vars($xml_element);
                }
 
                if (is_array($xml_element)) {
index 2b9a00176e658d442cd45aa6397046315d7e331b..dbc0bdb5d0da22a1f746622e7fb446eb6dfad19e 100644 (file)
@@ -34,11 +34,12 @@ class Delivery {
                $relocate = false;
                $top_level = false;
                $recipients = [];
-               $url_recipients = [];
                $followup = false;
 
                $normal_mode = true;
 
+               $item = null;
+
                $recipients[] = $contact_id;
 
                if ($cmd === 'mail') {
@@ -182,16 +183,14 @@ class Delivery {
 
                }
 
-               $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `blocked` = 0 AND `pending` = 0",
-                       intval($contact_id)
+               // We don't deliver our items to blocked or pending contacts, and not to ourselves either
+               $contact = dba::selectFirst('contact', [],
+                       ['id' => $contact_id, 'blocked' => false, 'pending' => false, 'self' => false]
                );
-
-               if (DBM::is_result($r)) {
-                       $contact = $r[0];
-               }
-               if ($contact['self']) {
+               if (!DBM::is_result($contact)) {
                        return;
                }
+
                $deliver_status = 0;
 
                // Transmit via Diaspora if not possible via Friendica
@@ -207,7 +206,7 @@ class Delivery {
                                logger('notifier: '.$target_item["guid"].' dfrndelivery: '.$contact['name']);
 
                                if ($mail) {
-                                       $item['body'] = Item::fixPrivatePhotos($item['body'],$owner['uid'],null,$message[0]['contact-id']);
+                                       $item['body'] = Item::fixPrivatePhotos($item['body'], $owner['uid'], null, $item['contact-id']);
                                        $atom = DFRN::mail($item, $owner);
                                } elseif ($fsuggest) {
                                        $atom = DFRN::fsuggest($item, $owner);
index a5e1e6ee2d3ab04b04a9a3c3fc790dc78709670f..a82fa12087ac9459bcc72c8cb4aba643a5663a3a 100644 (file)
@@ -30,6 +30,8 @@ class DiscoverPoCo {
                - check_profile: Update remote profile data
                */
 
+               $search = "";
+               $mode = 0;
                if ($command == "dirsearch") {
                        $search = urldecode($param1);
                        $mode = 1;
@@ -47,10 +49,7 @@ class DiscoverPoCo {
                        $mode = 7;
                } elseif ($command == "check_profile") {
                        $mode = 8;
-               } elseif ($command == '') {
-                       $search = "";
-                       $mode = 0;
-               } else {
+               } elseif ($command !== "") {
                        logger("Unknown or missing parameter ".$command."\n");
                        return;
                }
index b050c5e2f5773ac349e653de06fcb5a47c95573b..f22549c2b822fa13982250c9e2e4b1ac2691329a 100644 (file)
@@ -67,6 +67,7 @@ class Notifier {
                $url_recipients = [];
 
                $normal_mode = true;
+               $recipients_relocate = [];
 
                if ($cmd === 'mail') {
                        $normal_mode = false;
@@ -178,6 +179,10 @@ class Notifier {
                // fill this in with a single salmon slap if applicable
                $slap = '';
 
+               $followup = false;
+               $recipients_followup = [];
+               $conversants = [];
+               $sql_extra = '';
                if (! ($mail || $fsuggest || $relocate)) {
 
                        $slap = OStatus::salmon($target_item, $owner);
@@ -321,8 +326,6 @@ class Notifier {
                                        Worker::add($a->queue['priority'], 'Notifier', 'uplink', $item_id);
                                }
 
-                               $conversants = [];
-
                                foreach ($items as $item) {
                                        $recipients[] = $item['contact-id'];
                                        $conversants[] = $item['contact-id'];
@@ -519,7 +522,7 @@ class Notifier {
                                        // except for Diaspora batch jobs
                                        // Don't deliver to folks who have already been delivered to
 
-                                       if (($rr['network'] !== NETWORK_DIASPORA) && (in_array($rr['id'],$conversants))) {
+                                       if (($rr['network'] !== NETWORK_DIASPORA) && (in_array($rr['id'], $conversants))) {
                                                logger('notifier: already delivered id=' . $rr['id']);
                                                continue;
                                        }
index 377bda85f4c4ebd94b3eea0c47f2d1329c7ffab8..2594f4ec1dadf01a214e01bc370c5bf0598d59a2 100644 (file)
@@ -153,6 +153,7 @@ class OnePoll
                }
 
                $importer = $r[0];
+               $url = '';
 
                logger("poll: ({$contact['network']}-{$contact['id']}) IMPORTER: {$importer['name']}, CONTACT: {$contact['name']}");