diff --git a/include/class_baseSelector.inc b/include/class_baseSelector.inc
index 04ccef91351e532af882de0ea69624a039e7dc2a..7285e58ea702951bbebe2a5e24a04827b0eae864 100644
--- a/include/class_baseSelector.inc
+++ b/include/class_baseSelector.inc
@@ -83,8 +83,8 @@ class baseSelector {
   function setBase($base)
   {
     if (isset($this->pathMapping[$base])) {
-      $this->base = $base;
-      $this->lastState = TRUE;
+      $this->base       = $base;
+      $this->lastState  = TRUE;
       return $this->update(TRUE);
     } else {
       $this->lastState = FALSE;
@@ -124,17 +124,14 @@ class baseSelector {
     global $config;
 
     $this->pathMapping = array();
-    $selected     = ($this->base == $config->current['BASE']?"Selected":"");
-    $first        = TRUE;
-    $last_indent  = 2;
+    $selected = ($this->base == $config->current['BASE']);
 
     foreach ($bases as $base => $dummy) {
-
       // Build path style display
       $elements = explode(',', substr($base, 0, strlen($base) - strlen($config->current['BASE'])));
       $elements = array_reverse($elements, TRUE);
 
-      $this->pathMapping[$base] = ($base == $config->current['BASE']? '/' : ldap::fix(preg_replace('/(^|,)[a-z0-9]+=/i', '/', implode(',', $elements))));
+      $this->pathMapping[$base] = ($selected? '/' : ldap::fix(preg_replace('/(^|,)[a-z0-9]+=/i', '/', implode(',', $elements))));
     }
 
     // Save bases to session for autocompletion
diff --git a/include/class_filter.inc b/include/class_filter.inc
index 15888995a9ed8a7a3d50f4453ee311a789276fc6..8726e0f31565489ddb76226fdfe63bc60f3b68da 100644
--- a/include/class_filter.inc
+++ b/include/class_filter.inc
@@ -1,5 +1,4 @@
 <?php
-
 /*
   This code is part of FusionDirectory (http://www.fusiondirectory.org/)
   Copyright (C) 2003-2010  Cajus Pollmeier
@@ -30,7 +29,6 @@
  */
 class filter
 {
-
   var $xmlData;
   var $elements         = array();
   var $elementValues    = array();
@@ -55,8 +53,6 @@ class filter
    */
   function filter($filename)
   {
-    global $config;
-
     // Load eventually passed filename
     if (!$this->load($filename)) {
       die("Cannot parse $filename!");
@@ -629,7 +625,6 @@ class filter
    */
   function processAutocomplete()
   {
-    global $class_mapping;
     $result = array();
 
     // Introduce maximum number of entries
diff --git a/include/class_ldap.inc b/include/class_ldap.inc
index daba72379db016110b51adab08a94d2699becab2..9a366510062757890a7cbc8dd6bb9583eb38bca2 100644
--- a/include/class_ldap.inc
+++ b/include/class_ldap.inc
@@ -34,8 +34,8 @@ define("SPECIALS_OVERRIDE", TRUE);
  * ldap operations easy
  */
 
-class LDAP{
-
+class LDAP
+{
   var $hascon         = FALSE;
   var $reconnect      = FALSE;
   var $tls            = FALSE;
@@ -1073,7 +1073,6 @@ class LDAP{
     $admin  = escapeshellarg($this->binddn);
     $filter = escapeshellarg($filter);
 
-
     $cmd = "ldapsearch -x -LLLL -D {$admin} {$filter} {$limit} {$scope} -H {$host} -b {$dn} -w {$pwd} ";
 
     // Create list of process pipes
@@ -1248,8 +1247,9 @@ class LDAP{
       trigger_error("Can't import ldif, can't read config object.");
     }
 
-
-    if ($this->reconnect) $this->connect();
+    if ($this->reconnect) {
+      $this->connect();
+    }
 
     $ret  = FALSE;
     $rows = preg_split("/\n/", $str_attr);
@@ -1520,7 +1520,7 @@ class LDAP{
       die ("Can't bind to LDAP. No check possible!");
     }
     ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
-    $r = ldap_bind ($ds, $admin, $password);
+    ldap_bind ($ds, $admin, $password);
 
     /* Get base to look for naming contexts */
     $sr   = @ldap_read ($ds, "", "objectClass=*", array("+"));
@@ -1538,7 +1538,7 @@ class LDAP{
       die ("Can't bind to LDAP. No check possible!");
     }
     ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
-    $r = ldap_bind ($ds, $admin, $password);
+    ldap_bind ($ds, $admin, $password);
 
     /* Get base to look for naming contexts */
     $sr   = @ldap_read ($ds, "", "objectClass=*", array("+"));
diff --git a/include/class_management.inc b/include/class_management.inc
index 563ccfb31a8cb925f8863febf2a0aeb8b8be8367..d17388a8b757f8ab8c360f41f126e932ebe1b893 100644
--- a/include/class_management.inc
+++ b/include/class_management.inc
@@ -396,8 +396,7 @@ class management
 
     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $target, "Entry removel confirmed!");
 
-    foreach ($this->dns as $key => $dn) {
-
+    foreach ($this->dns as $dn) {
       // Check permissions, are we allowed to remove this object?
       $acl = $this->ui->get_permissions($dn, $aclCategory."/".$this->aclPlugin);
       if (preg_match("/d/", $acl)) {
@@ -758,7 +757,7 @@ class management
       $msgs = $this->tabObject->check();
       if (count($msgs)) {
         msg_dialog::displayChecks($msgs);
-        return "";
+        return;
       } else {
         $this->tabObject->save();
         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->dns, "Entry saved!");
@@ -770,7 +769,7 @@ class management
       $msgs = $this->dialogObject->check();
       if (count($msgs)) {
         msg_dialog::displayChecks($msgs);
-        return "";
+        return;
       } else {
         $this->dialogObject->save();
         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->dns, "Entry saved!");
diff --git a/include/class_objects.inc b/include/class_objects.inc
index b8abcc70ff615cf156b98fdb58d782e5386ef82e..a087bd252322ba52f2fbf82b13b04f2a53c555db 100644
--- a/include/class_objects.inc
+++ b/include/class_objects.inc
@@ -41,8 +41,6 @@ class objects
    */
   static function ls ($type, $attrs = NULL, $ou = NULL, $filter = '')
   {
-    global $config;
-
     if ($attrs === NULL) {
       $infos = self::infos($type);
       $attrs = $infos['mainAttr'];
@@ -95,8 +93,6 @@ class objects
    */
   static function count ($type, $ou = NULL, $filter = '')
   {
-    global $config;
-
     try {
       $ldap = self::search($type, array('dn'), $ou, $filter);
     } catch (EmptyFilterException $e) {
@@ -229,8 +225,6 @@ class objects
 
   static function isOfType ($attrs, $type)
   {
-    global $config;
-
     //TODO : cache ldapFilter objects?
     $infos  = self::infos($type);
     $filter = ldapFilter::parse($infos['filter']);
diff --git a/include/class_xml.inc b/include/class_xml.inc
index 318ebd4c45d8e989ce3c4bd8608b36c16d8f1a26..e934c949df2e655a64dbde93b102fc54fd74089a 100644
--- a/include/class_xml.inc
+++ b/include/class_xml.inc
@@ -106,9 +106,6 @@ class xml {
 
     //Initializations
     $xml_array    = array();
-    $parents      = array();
-    $opened_tags  = array();
-    $arr          = array();
 
     $current = &$xml_array; //Refference
 
diff --git a/include/functions.inc b/include/functions.inc
index 253bfa735e3052006471799d390dc9f8c551ab13..e105db5ab09497eff60cf260359897d0c3d59964 100644
--- a/include/functions.inc
+++ b/include/functions.inc
@@ -734,7 +734,6 @@ function add_lock($object, $user)
     unset($cache['READ_ONLY'][$object]);
   }
 
-
   /* Just a sanity check... */
   if ($object == "" || $user == "") {
     msg_dialog::display(_("Internal error"), _("Error while adding a lock. Contact the developers!"), ERROR_DIALOG);
@@ -1342,7 +1341,6 @@ function convert_department_dn($dn, $base = NULL)
     return "/";
   }
 
-
   $dep = "";
   foreach (explode(',', $dn) as $rdn) {
     $dep = preg_replace("/^[^=]+=/", "", $rdn)."/".$dep;
@@ -1873,7 +1871,6 @@ function range_selector($dcnt, $start, $range = 25, $post_var = FALSE)
   }
   $ppage = (int)(($start / $range) + 0.5);
 
-
   /* Align selected page to +/- max_entries/2 */
   $begin  = $ppage - $max_entries / 2;
   $end    = $ppage + $max_entries / 2;
@@ -3098,13 +3095,14 @@ function generate_smb_nt_hash($password)
 /* Lock or unlock samba account */
 function lock_samba_account($mode, $attrs)
 {
+  global $config;
   $modify = array('sambaNTPassword' => $attrs['sambaNTPassword'][0]);
   if ($config->get_cfg_value("sambaGenLMPassword", "FALSE") == "TRUE") {
     $modify['sambaLMPassword'] = $attrs['sambaLMPassword'][0];
   } else {
     $modify['sambaLMPassword'] = array();
   }
-  foreach ($modify as $key => &$pwd) {
+  foreach ($modify as &$pwd) {
     if (is_array($pwd)) {
       continue;
     }
@@ -3118,7 +3116,7 @@ function lock_samba_account($mode, $attrs)
       $pwd = preg_replace("/^\!/",  "",   $pwd);
     }
   }
-  unset($value);
+  unset($pwd);
   return $modify;
 }
 
@@ -3659,7 +3657,8 @@ function fix_dos_linebreaks($str)
   return preg_replace('/\\r\\n/', "\n", $str);
 }
 
-function load_all_classes() {
+function load_all_classes()
+{
   global $BASE_DIR, $class_list, $class_mapping;
   /* Initially load all classes */
   $class_list = get_declared_classes();
diff --git a/plugins/admin/ogroups/class_ogroup.inc b/plugins/admin/ogroups/class_ogroup.inc
index 16b68b680540944ff7ce017f1d76475ca18cc867..4c41f03ee5beb3370312de0806cf531f6fb29cb6 100644
--- a/plugins/admin/ogroups/class_ogroup.inc
+++ b/plugins/admin/ogroups/class_ogroup.inc
@@ -291,10 +291,10 @@ class ogroup_old extends plugin
             msg_dialog::display(_("Error"), sprintf(_("These systems are already configured by other object groups and cannot be added:")."<br><ul>%s</ul>", $str), ERROR_DIALOG);
           }
 
-          foreach($objects as $object){
+          foreach ($objects as $object){
 
               $tmp = "";
-              foreach($this->memberList as $obj){
+              foreach ($this->memberList as $obj){
                   $tmp .= $obj['type'];
               }
 
diff --git a/setup/class_setupStep_Checks.inc b/setup/class_setupStep_Checks.inc
index dd22bdd67fd577163239dff281e8c301ee4fbcf0..66d751b4720fcf4d61a5f215df9bbb77f99fca8b 100644
--- a/setup/class_setupStep_Checks.inc
+++ b/setup/class_setupStep_Checks.inc
@@ -56,9 +56,9 @@ class Step_Checks extends setup_step
   /* Execute all checks */
   function run_checks()
   {
-    $this->basic_checks = array();
-    $this->config_checks = array();
-    $this->is_writeable = array();
+    $this->basic_checks   = array();
+    $this->config_checks  = array();
+    $this->is_writeable   = array();
 
     /* PHP version check */
     $N = _("Checking PHP version");
@@ -157,7 +157,6 @@ class Step_Checks extends setup_step
     $M = FALSE;
     $this->basic_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
 
-
     /* PHP Configuration checks */
 
     /* Register_globals off */
@@ -168,7 +167,6 @@ class Step_Checks extends setup_step
     $M = FALSE;
     $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
 
-
     /* session lifetime set to >=86400 seconds ? */
     $N = "session.gc_maxlifetime &gt;= <b>86400</b>";
     $D = _("PHP uses this value for the garbage collector to delete old sessions.")." ".
@@ -227,9 +225,7 @@ class Step_Checks extends setup_step
     $M = FALSE;
     $this->config_checks[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
 
-
-    /* Configuration file
-     */
+    /* Configuration file */
 
     /* Check if we can create a config file.*/
     $N = _("Configuration writeable");
@@ -240,7 +236,6 @@ class Step_Checks extends setup_step
           || (!file_exists(CONFIG_DIR."/".CONFIG_FILE) && is_writeable(CONFIG_DIR));
     $M = FALSE;
     $this->is_writeable[] = array("NAME" => $N , "DESC" => $D , "RESULT" => $R , "SOLUTION" => $S , "MUST" => $M );
-
   }
 
 
diff --git a/setup/class_setupStep_Config3.inc b/setup/class_setupStep_Config3.inc
index b8b5f6355b5dd6e9453e2038b2980165311429f7..905850b0027b17d6ad7e9af433510b09ec831b22 100644
--- a/setup/class_setupStep_Config3.inc
+++ b/setup/class_setupStep_Config3.inc
@@ -163,7 +163,6 @@ class Step_Config3 extends setup_step
 
   function save_config_in_ldap ()
   {
-    global $BASE_DIR;
     $cv = $this->parent->captured_values;
 
     $attrs = array(
diff --git a/setup/class_setupStep_Finish.inc b/setup/class_setupStep_Finish.inc
index 5d03074acf482c1f7222ac4b78e8af57f188a1d5..80db7223fe8e8de0ca6f8de95ec3271b7eaf5459 100644
--- a/setup/class_setupStep_Finish.inc
+++ b/setup/class_setupStep_Finish.inc
@@ -77,7 +77,8 @@ class Step_Finish extends setup_step
 
   function execute()
   {
-    global $config, $BASE_DIR;
+    global $BASE_DIR;
+
     if (!function_exists("posix_getgrgid")) {
       $webgroup = "";
     } else {
@@ -94,7 +95,7 @@ class Step_Finish extends setup_step
      *   - Permisssion are set correctly
      */
 
-    if(isset($_POST['next']) && $exists && !$this->is_world_readable(CONFIG_DIR."/".CONFIG_FILE)){
+    if (isset($_POST['next']) && $exists && !$this->is_world_readable(CONFIG_DIR."/".CONFIG_FILE)) {
       $this->insertConfigDefaults();
       session::destroy();
       header("Location: index.php");
@@ -110,13 +111,13 @@ class Step_Finish extends setup_step
 
     if ($exists && $this->is_world_readable(CONFIG_DIR."/".CONFIG_FILE)) {
       $err_msg = _("Your configuration file is currently world readable. Please update the file permissions!");
-    } elseif(!$exists) {
+    } elseif (!$exists) {
       $err_msg = _("The configuration is currently not readable or it does not exists.");
     }
 
     $smarty = get_smarty();
     $smarty->assign("err_msg",  $err_msg);
-    $smarty->assign("msg2",     sprintf(_("After downloading and placing the file under %s, please make sure that the user the webserver is running with is able to read %s, while other users shouldn't."),CONFIG_DIR,CONFIG_FILE));
+    $smarty->assign("msg2",     sprintf(_("After downloading and placing the file under %s, please make sure that the user the webserver is running with is able to read %s, while other users shouldn't."), CONFIG_DIR, CONFIG_FILE));
     $smarty->assign("cv",       $this->parent->captured_values);
 
     return $smarty->fetch("$BASE_DIR/setup/setup_finish.tpl");
diff --git a/setup/class_setupStep_Migrate.inc b/setup/class_setupStep_Migrate.inc
index 43603d9d1d90a1905ee8a04366994e7b7609f384..9dd8f4acee9ffa234fb9a22dfecebe1c2fd958a5 100644
--- a/setup/class_setupStep_Migrate.inc
+++ b/setup/class_setupStep_Migrate.inc
@@ -112,7 +112,7 @@ class Step_Migrate extends setup_step
   /* One valid admin dn */
   var $valid_admin = FALSE;
 
-  function Step_Migrate()
+  function __construct()
   {
     $this->update_strings();
   }
@@ -554,7 +554,6 @@ class Step_Migrate extends setup_step
     $this->show_details = $only_ldif;
 
     /* Establish ldap connection */
-    $cv   = $this->parent->captured_values;
     $ldap = $this->get_ldap_link();
 
     /* Add gosaAccount objectClass to the selected users */
@@ -679,7 +678,6 @@ class Step_Migrate extends setup_step
     $this->show_details = $only_ldif;
 
     /* Establish ldap connection */
-    $cv   = $this->parent->captured_values;
     $ldap = $this->get_ldap_link();
 
     /* Add gosaDepartment objectClass to each selected entry */
@@ -785,7 +783,7 @@ class Step_Migrate extends setup_step
                     $valid_admin = $member;
                   }
                   $valid_users    .= $users[$member].", ";
-                  $FD_1_0_8_found  = TRUE;
+                  $FD_1_0_8_found = TRUE;
                 }
                 if (isset($groups[$member])) {
                   $ldap->cat($member);
@@ -832,7 +830,7 @@ class Step_Migrate extends setup_step
                       $valid_admin = $member;
                     }
                     $valid_users    .= $users[$member].", ";
-                    $FD_1_0_7_found  = TRUE;
+                    $FD_1_0_7_found = TRUE;
                   }
                 }
                 if (isset($groups[$member])) {
@@ -878,7 +876,7 @@ class Step_Migrate extends setup_step
                           $valid_admin = $member;
                         }
                         $valid_users    .= $users[$member].", ";
-                        $FD_1_0_7_found  = TRUE;
+                        $FD_1_0_7_found = TRUE;
                       }
                       if (isset($groups[$member])) {
                         $ldap->cat($member);
@@ -963,12 +961,11 @@ class Step_Migrate extends setup_step
     if ($attrs = $ldap->fetch()) {
       $roledn = $attrs['dn'];
     } else {
-      $roledn = 'cn=admin,'.get_ou(aclRoleRDN).$cv['base'];
-      if ($only_ldif) {
-      } else {
+      $roledn = 'cn=admin,'.get_ou('aclRoleRDN').$cv['base'];
+      if (!$only_ldif) {
         $ldap->create_missing_trees($roledn);
         $ldap->cd($roledn);
-        $attrs_role =  array(
+        $attrs_role = array(
           'cn'              => 'admin',
           'objectclass'     => array( 'top', 'gosaRole' ),
           'gosaAclTemplate' => '0:all;cmdrw'
@@ -1992,7 +1989,6 @@ class Step_Migrate extends setup_step
   function move($source, $destination)
   {
     /* Establish ldap connection */
-    $cv   = $this->parent->captured_values;
     $ldap = $this->get_ldap_link();
 
      /* Update object references in gosaGroupOfNames */
@@ -2304,7 +2300,6 @@ class Step_Migrate extends setup_step
   function migrate_services()
   {
     /* Establish ldap connection */
-    $cv   = $this->parent->captured_values;
     $ldap = $this->get_ldap_link();
 
     /* Handle each service */