Browse Source

Minor - Remove empty (unused) conditions

Yannick Warnier 8 years ago
parent
commit
eb1d7ffe01

+ 8 - 20
main/auth/ldap/authldap.php

@@ -133,14 +133,10 @@ function ldap_find_user_info ($login) {
             //echo " Getting entries ...";
             $info = ldap_get_entries($ldap_connect, $sr);
             //echo "Data for ".$info["count"]." items returned:<p>";
-        } else {
-            //echo "LDAP bind failed...";
-        }
+        } // else could echo "LDAP bind failed...";
         //echo "Closing LDAP connection<hr>";
         ldap_close($ldap_connect);
-    } else {
-        //echo "<h3>Unable to connect to LDAP server</h3>";
-    }
+    } // else could echo "<h3>Unable to connect to LDAP server</h3>";
     //DEBUG: $result["firstname"] = "Jan"; $result["name"] = "De Test"; $result["email"] = "email@ugent.be";
     $result["firstname"] = $info[0]["cn"][0];
     $result["name"] = $info[0]["sn"][0];
@@ -261,9 +257,7 @@ function ldap_authentication_check ($uname, $passwd) {
     if ($test_bind_res===false) {
         $ds=ldap_connect($ldap_host2,$ldap_port2);
         ldap_set_version($ds);
-    } else {
-        //error_log('Connected to server '.$ldap_host);
-    }
+    } // else: error_log('Connected to server '.$ldap_host);
     if ($ds!==false) {
         //Creation of filter containing values input by the user
         // Here it might be necessary to use $filter="(samaccountName=$uname)"; - see http://support.chamilo.org/issues/4675
@@ -312,11 +306,9 @@ function ldap_set_version(&$resource) {
     //error_log('Entering ldap_set_version(&$resource)',0);
     global $ldap_version;
     if ($ldap_version>2) {
-        if (ldap_set_option($resource, LDAP_OPT_PROTOCOL_VERSION, 3)) {
-            //ok - don't do anything
-        } else {
-            //failure - should switch back to version 2 by default
-        }
+        ldap_set_option($resource, LDAP_OPT_PROTOCOL_VERSION, 3);
+        //ok - don't do anything
+        //failure - should switch back to version 2 by default
     }
 }
 /**
@@ -630,12 +622,8 @@ function syncro_users() {
                 }
             }
             //echo "Data for ".$info["count"]." items returned:<p>";
-        } else {
-            //echo "LDAP bind failed...";
-        }
+        } // else: could echo "LDAP bind failed...";
         //echo "Closing LDAP connection<hr>";
         ldap_close($ldap_connect);
-    } else {
-        //echo "<h3>Unable to connect to LDAP server</h3>";
-    }
+    } // else: could echo "<h3>Unable to connect to LDAP server</h3>";
 }

+ 15 - 14
main/exercise/hotpotatoes.lib.php

@@ -148,12 +148,15 @@ function WriteFileCont($full_file_path, $content)
         if (basename($full_file_path) != Security::filter_filename(basename($full_file_path))) {
             return false;
         }
-        if (!($fp = fopen(urldecode($full_file_path), 'w'))) {
+        //if (!($fp = fopen(urldecode($full_file_path), 'w'))) {
             //die('Could not open Quiz input.');
+        //}
+        $fp = fopen(urldecode($full_file_path), 'w');
+        if ($fp !== false) {
+            fwrite($fp, $content);
+            fclose($fp);
+            return true;
         }
-        fwrite($fp, $content);
-        fclose($fp);
-        return true;
     }
     return false;
 }
@@ -200,7 +203,7 @@ function GetSrcName($imgtag)
     // Select src tag from img tag.
     $match = array();
     preg_match("|(src=\".*\" )|U", $imgtag, $match); //src
-    list($key, $srctag) = each($match);
+    list(, $srctag) = each($match);
     $src = substr($srctag, 5, (strlen($srctag) - 7));
     if (stristr($src, 'http') === false) {
     // valid or invalid image name
@@ -226,9 +229,9 @@ function GetImgParams($fname, $fpath, &$imgparams, &$imgcount)
     $matches = array();
     preg_match_all('(<img .*>)', $contents, $matches);
     $imgcount = 0;
-    while (list($int, $match) = each($matches)) {
+    while (list(, $match) = each($matches)) {
         // Each match consists of a key and a value.
-        while (list($key, $imgtag) = each($match)) {
+        while (list(, $imgtag) = each($match)) {
             $imgname = GetImgName($imgtag);
             if ($imgname != '' && !in_array($imgname, $imgparams)) {
                 array_push($imgparams, $imgname); // name (+ type) of the images in the html test
@@ -247,7 +250,7 @@ function GenerateHiddenList($imgparams)
 {
     $list = '';
     if (is_array($imgparams)) {
-        while (list($int, $string) = each($imgparams)) {
+        while (list(, $string) = each($imgparams)) {
             $list .= "<input type=\"hidden\" name=\"imgparams[]\" value=\"$string\" />\n";
         }
     }
@@ -299,12 +302,10 @@ function ReplaceImgTag($content)
     $newcontent = $content;
     $matches = array();
     preg_match_all('(<img .*>)', $content, $matches);
-    while (list($int, $match) = each($matches)) {
-        while (list($key, $imgtag) = each($match)) {
+    while (list(, $match) = each($matches)) {
+        while (list(, $imgtag) = each($match)) {
             $imgname = GetSrcName($imgtag);
-            if ($imgname == '') {
-                // Valid or invalid image name.
-            } else {
+            if ($imgname != '') {
                 $prehref = $imgname;
                 $posthref = basename($imgname);
                 $newcontent = str_replace($prehref, $posthref, $newcontent);
@@ -443,7 +444,7 @@ function HotPotGCt($folder, $flag, $user_id)
         }
         closedir($dir);
     }
-    while (list($key, $val) = each($filelist)) {
+    while (list(, $val) = each($filelist)) {
         if (stristr($val, $user_id.'.t.html')) {
             if ($flag == 1) {
                 my_delete($folder.'/'.$val);

+ 8 - 27
main/lp/learnpath.class.php

@@ -1539,15 +1539,6 @@ class learnpath
                     prerequisite_max_score = $max_score
                  WHERE c_id = $course_id AND id = $id";
         Database::query($sql);
-
-        if ($prerequisite_id != 'NULL' && $prerequisite_id != '') {
-            // Will this be enough to ensure unicity?
-            /*$sql = " UPDATE $tbl_lp_item
-                     SET mastery_score = $mastery_score
-                     WHERE c_id = $course_id AND ref = '$prerequisite_id'";
-
-            Database::query($sql);*/
-        }
         // TODO: Update the item object (can be ignored for now because refreshed).
         return true;
     }
@@ -3040,12 +3031,8 @@ class learnpath
         if ($this->debug > 0) {
             error_log('New LP - In learnpath::get_type()', 0);
         }
-        if (!empty ($this->type)) {
-            if ($get_name) {
-                // Get it from the lp_type table in main db.
-            } else {
-                $res = $this->type;
-            }
+        if (!empty ($this->type) && (!$get_name)) {
+            $res = $this->type;
         }
         if ($this->debug > 2) {
             error_log('New LP - In learnpath::get_type() - Returning ' . ($res ? $res : 'false'), 0);
@@ -3757,8 +3744,7 @@ class learnpath
                 if ($this->debug > 2) {
                     error_log('Movement up detected', 0);
                 }
-                if ($display <= 1) { /*do nothing*/
-                } else {
+                if ($display > 1) {
                     $sql_sel2 = "SELECT * FROM $tbl_lp_item
                                  WHERE c_id = ".$course_id." AND id = $previous";
 
@@ -3823,8 +3809,7 @@ class learnpath
                 if ($this->debug > 2) {
                     error_log('Movement down detected', 0);
                 }
-                if ($next == 0) { /* Do nothing. */
-                } else {
+                if ($next != 0) {
                     $sql_sel2 = "SELECT * FROM $tbl_lp_item WHERE c_id = ".$course_id." AND id = $next";
                     if ($this->debug > 2) {
                         error_log('Selecting next: ' . $sql_sel2, 0);
@@ -4374,7 +4359,7 @@ class learnpath
 
         if (!api_is_invitee()) {
             // Save progress.
-            list($progress, $text) = $this->get_progress_bar_text('%');
+            list($progress,) = $this->get_progress_bar_text('%');
             if ($progress >= 0 && $progress <= 100) {
                 $progress = (int) $progress;
                 $sql = "UPDATE $table SET
@@ -4952,9 +4937,8 @@ class learnpath
                 $prereq_check = $this->prerequisites_match($this->current);
                 $this->items[$this->current]->save(false, $prereq_check);
                 //$this->update_queue[$this->last] = $this->items[$this->last]->get_status();
-            } else {
-                // If sco, then it is supposed to have been updated by some other call.
             }
+            // If sco, then it is supposed to have been updated by some other call.
             if ($item_type == 'sco') {
                 $this->items[$this->current]->restart();
             }
@@ -5599,8 +5583,7 @@ class learnpath
             $return_audio  .= '<td align="left" style="padding-left:10px;">';
             $audio = '';
             if (!$update_audio || $update_audio <> 'true') {
-                if (!empty($arrLP[$i]['audio'])) {
-                } else {
+                if (empty($arrLP[$i]['audio'])) {
                     $audio .= '';
                 }
             } else {
@@ -10433,9 +10416,7 @@ EOD;
                 // Try to add an extension to the file if it hasn't one.
                 $new_file_name = add_ext_on_mime(stripslashes($image_array['name']), $image_array['type']);
 
-                if (!filter_extension($new_file_name)) {
-
-                } else {
+                if (filter_extension($new_file_name)) {
                     $file_extension = explode('.', $image_array['name']);
                     $file_extension = strtolower($file_extension[sizeof($file_extension) - 1]);
                     $filename = uniqid('');

+ 13 - 31
plugin/advanced_subscription/src/HookAdvancedSubscription.php

@@ -38,9 +38,8 @@ class HookAdvancedSubscription extends HookObserver implements
     public function hookAdminBlock(HookAdminBlockEventInterface $hook)
     {
         $data = $hook->getEventData();
-        if ($data['type'] === HOOK_EVENT_TYPE_PRE) {
-            // Nothing to do
-        } elseif ($data['type'] === HOOK_EVENT_TYPE_POST) {
+        // if ($data['type'] === HOOK_EVENT_TYPE_PRE) // Nothing to do
+        if ($data['type'] === HOOK_EVENT_TYPE_POST) {
 
             if (isset($data['blocks'])) {
                 $data['blocks']['sessions']['items'][] = array(
@@ -48,10 +47,7 @@ class HookAdvancedSubscription extends HookObserver implements
                     'label' => get_plugin_lang('plugin_title', 'AdvancedSubscriptionPlugin'),
                 );
             }
-        } else {
-            // Hook type is not valid
-            // Nothing to do
-        }
+        } // Else: Hook type is not valid, nothing to do
 
         return $data;
     }
@@ -64,9 +60,8 @@ class HookAdvancedSubscription extends HookObserver implements
     public function hookWSRegistration(HookWSRegistrationEventInterface $hook)
     {
         $data = $hook->getEventData();
-        if ($data['type'] === HOOK_EVENT_TYPE_PRE) {
-
-        } elseif ($data['type'] === HOOK_EVENT_TYPE_POST) {
+        //if ($data['type'] === HOOK_EVENT_TYPE_PRE) // nothing to do
+        if ($data['type'] === HOOK_EVENT_TYPE_POST) {
             /** @var \nusoap_server $server */
             $server = &$data['server'];
 
@@ -403,9 +398,7 @@ class HookAdvancedSubscription extends HookObserver implements
             );
 
             return $data;
-        } else {
-            // Nothing to do
-        }
+        } // Else: Nothing to do
 
         return false;
     }
@@ -421,10 +414,9 @@ class HookAdvancedSubscription extends HookObserver implements
         if ($debug) {
             error_log(__FUNCTION__);
             error_log('Params '.print_r($params, 1));
-        }
-        if (!WSHelperVerifyKey($params)) {
-
-            //return return_error(WS_ERROR_SECRET_KEY);
+            if (!WSHelperVerifyKey($params)) {
+                error_log(return_error(WS_ERROR_SECRET_KEY));
+            }
         }
         // Check if category ID is set
         if (!empty($params['id']) && empty($params['name'])) {
@@ -525,18 +517,14 @@ class HookAdvancedSubscription extends HookObserver implements
                                 } elseif ($status == ADVANCED_SUBSCRIPTION_QUEUE_STATUS_ADMIN_APPROVED) {
                                     // send url action
                                     $data['action_url'] = self::$plugin->getSessionUrl($sessionId);
-                                } else {
-                                    // In queue, output status message, no more info.
-                                }
+                                } // Else: In queue, output status message, no more info.
                             } else {
                                 if ($status == ADVANCED_SUBSCRIPTION_QUEUE_STATUS_ADMIN_APPROVED) {
                                     $data['action_url'] = self::$plugin->getSessionUrl($sessionId);
                                 } elseif ($status == ADVANCED_SUBSCRIPTION_QUEUE_STATUS_NO_QUEUE) {
                                     // in Queue or not, cannot be subscribed to session
                                     $data['action_url'] = self::$plugin->getTermsUrl($params);
-                                } else {
-                                    // In queue, output status message, no more info.
-                                }
+                                } // Else: In queue, output status message, no more info.
                             }
                         }
                     }
@@ -664,10 +652,7 @@ class HookAdvancedSubscription extends HookObserver implements
             }
 
             return $data;
-        } else {
-            // Hook type is not valid
-            // Nothing to do
-        }
+        } //Else hook type is not valid, nothing to do
         return false;
     }
 
@@ -691,10 +676,7 @@ class HookAdvancedSubscription extends HookObserver implements
             }
 
             return $data;
-        } else {
-            // Hook type is not valid
-            // Nothing to do
-        }
+        } // Else: hook type is not valid, nothing to do
         return false;
     }
 }