diff --git a/html/main.php b/html/main.php
index 1fe54dd68a6b1fcab0b9f561d9fe6848c8d1527e..280d327f6a25c1950199a9a020782ada269260e0 100644
--- a/html/main.php
+++ b/html/main.php
@@ -42,10 +42,10 @@ session::set('errorsAlreadyPosted', array());
 session::global_set('runtime_cache', array());
 session::set('limit_exceeded', FALSE);
 
-if ($_SERVER["REQUEST_METHOD"] == "POST") {
-  @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_POST, "_POST");
+if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+  @DEBUG (DEBUG_POST, __LINE__, __FUNCTION__, __FILE__, $_POST, '_POST');
 }
-@DEBUG (DEBUG_SESSION, __LINE__, __FUNCTION__, __FILE__, session::get_all(), "_SESSION");
+@DEBUG (DEBUG_SESSION, __LINE__, __FUNCTION__, __FILE__, $_SESSION, '_SESSION');
 
 /* Logged in? Simple security check */
 if (!session::global_is_set('connected')) {
@@ -201,11 +201,10 @@ if (memory_get_usage() > (to_byte(ini_get('memory_limit')) - 2048000 )) {
   msg_dialog::display(_("Configuration error"), _("Running out of memory!"), WARNING_DIALOG);
 }
 
-/* Redirect on back event */
-if ($_SERVER["REQUEST_METHOD"] == "POST") {
-
-  /* Look for button events that match /^back[0-9]+$/,
-     extract the number and step the correct plugin. */
+if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+  /* Redirect on back event
+      Look for button events that match /^back[0-9]+$/,
+      extract the number and step the correct plugin. */
   foreach ($_POST as $key => $value) {
     if (preg_match("/^back[0-9]+$/", $key)) {
       $back = substr($key, 4);
@@ -213,12 +212,11 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {
       exit;
     }
   }
-}
-
-/* Redirect on password back event */
-if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['password_back'])) {
-  header ("Location: main.php");
-  exit;
+  /* Redirect on password back event */
+  if (isset($_POST['password_back'])) {
+    header ("Location: main.php");
+    exit;
+  }
 }
 
 /* Load department list when plugin has changed. That is some kind of
@@ -250,24 +248,23 @@ $smarty->assign ("plug", "$plug");
 $smarty->assign("usePrototype", "false");
 
 /* React on clicks */
-if ($_SERVER["REQUEST_METHOD"] == "POST") {
-  if (isset($_POST['delete_lock']) || isset($_POST['open_readonly'])) {
+if (($_SERVER['REQUEST_METHOD"'] == 'POST')
+  && (isset($_POST['delete_lock']) || isset($_POST['open_readonly']))) {
 
-    /* Set old Post data */
-    if (session::global_is_set('LOCK_VARS_USED_GET')) {
-      foreach (session::global_get('LOCK_VARS_USED_GET') as $name => $value) {
-        $_GET[$name]  = $value;
-      }
+  /* Set old Post data */
+  if (session::global_is_set('LOCK_VARS_USED_GET')) {
+    foreach (session::global_get('LOCK_VARS_USED_GET') as $name => $value) {
+      $_GET[$name]  = $value;
     }
-    if (session::global_is_set('LOCK_VARS_USED_POST')) {
-      foreach (session::global_get('LOCK_VARS_USED_POST') as $name => $value) {
-        $_POST[$name] = $value;
-      }
+  }
+  if (session::global_is_set('LOCK_VARS_USED_POST')) {
+    foreach (session::global_get('LOCK_VARS_USED_POST') as $name => $value) {
+      $_POST[$name] = $value;
     }
-    if (session::global_is_set('LOCK_VARS_USED_REQUEST')) {
-      foreach (session::global_get('LOCK_VARS_USED_REQUEST') as $name => $value) {
-        $_REQUEST[$name] = $value;
-      }
+  }
+  if (session::global_is_set('LOCK_VARS_USED_REQUEST')) {
+    foreach (session::global_get('LOCK_VARS_USED_REQUEST') as $name => $value) {
+      $_REQUEST[$name] = $value;
     }
   }
 }
diff --git a/include/class_IconTheme.inc b/include/class_IconTheme.inc
index f0482a04e393babb4fb3e6e3574c6456bec5bfaa..5fdb279f7568c0b7612c33135d4f5ddc2c4f1269 100644
--- a/include/class_IconTheme.inc
+++ b/include/class_IconTheme.inc
@@ -202,6 +202,7 @@ class IconTheme
 
   /* We store themes in the session. To do otherwise, override these methods. */
   static public $session_var    = 'IconThemes';
+
   static public function loadThemes($path)
   {
     $themes = array();
@@ -222,6 +223,7 @@ class IconTheme
     }
     $_SESSION[static::$session_var] = $themes;
   }
+
   static public function findThemeIcon($theme, $context, $icon, $size)
   {
     if (!isset($_SESSION[static::$session_var])) {
@@ -232,11 +234,11 @@ class IconTheme
     }
     return $_SESSION[static::$session_var][static::$default_theme]->FindIcon($context, $icon, $size);
   }
+
   public function findTheme($theme)
   {
     if (isset($_SESSION[static::$session_var][$theme])) {
-      $ret = &$_SESSION[static::$session_var][$theme];
-      return $ret;
+      return $_SESSION[static::$session_var][$theme];
     }
     return NULL;
   }
diff --git a/include/class_config.inc b/include/class_config.inc
index 579e3f6122e9f66f7ac4c173e2b82e812683cc6a..6847484d68946f18d37b403e600579e5e2bcfeed 100644
--- a/include/class_config.inc
+++ b/include/class_config.inc
@@ -45,8 +45,8 @@ class config
   var $current = array();
 
   /* Link to LDAP-server */
-  var $ldap       = NULL;
-  var $referrals  = array();
+  protected $ldapLink = NULL;
+  var $referrals      = array();
 
   /*
    * \brief Configuration data
@@ -96,10 +96,9 @@ class config
     /* Check if class_location.inc has changed, this is the case
         if we have installed or removed plugins. */
     $tmp = stat(CACHE_DIR.'/'.CLASS_CACHE);
-    if (session::global_is_set('class_location.inc:timestamp')) {
-      if ($tmp['mtime'] != session::global_get('class_location.inc:timestamp')) {
-        session::global_un_set('plist');
-      }
+    if (session::global_is_set('class_location.inc:timestamp')
+      && ($tmp['mtime'] != session::global_get('class_location.inc:timestamp'))) {
+      session::global_un_set('plist');
     }
     session::global_set('class_location.inc:timestamp', $tmp['mtime']);
 
@@ -313,23 +312,23 @@ class config
    */
   function get_ldap_link($sizelimit = FALSE)
   {
-    if ($this->ldap === NULL || !is_resource($this->ldap->cid)) {
+    if ($this->ldapLink === NULL || !is_resource($this->ldapLink->cid)) {
 
       /* Build new connection */
-      $this->ldap = ldap_init ($this->current['SERVER'], $this->current['BASE'],
+      $this->ldapLink = ldap_init ($this->current['SERVER'], $this->current['BASE'],
           $this->current['ADMINDN'], $this->get_credentials($this->current['ADMINPASSWORD']));
 
       /* Check for connection */
-      if (is_null($this->ldap) || (is_int($this->ldap) && $this->ldap == 0)) {
+      if (is_null($this->ldapLink) || (is_int($this->ldapLink) && $this->ldapLink == 0)) {
         msg_dialog::display(_("LDAP error"), _("Cannot bind to LDAP. Please contact the system administrator."), FATAL_ERROR_DIALOG);
         exit();
       }
 
       /* Move referrals */
       if (!isset($this->current['REFERRAL'])) {
-        $this->ldap->referrals = array();
+        $this->ldapLink->referrals = array();
       } else {
-        $this->ldap->referrals = $this->current['REFERRAL'];
+        $this->ldapLink->referrals = $this->current['REFERRAL'];
       }
 
       if (!session::global_is_set('size_limit')) {
@@ -338,7 +337,7 @@ class config
       }
     }
 
-    $obj  = new ldapMultiplexer($this->ldap);
+    $obj  = new ldapMultiplexer($this->ldapLink);
     if ($sizelimit) {
       $obj->set_size_limit(session::global_get('size_limit'));
     } else {
@@ -454,13 +453,12 @@ class config
       }
 
       /* If no samba servers are found, look for configured sid/ridbase */
-      if (count($this->data['SERVERS']['SAMBA']) == 0) {
-        if (isset($this->current['SAMBASID']) && isset($this->current['SAMBARIDBASE'])) {
-          $this->data['SERVERS']['SAMBA']['DEFAULT'] = array(
-            'SID'     => $this->get_cfg_value('SAMBASID'),
-            'RIDBASE' => $this->get_cfg_value('SAMBARIDBASE')
-          );
-        }
+      if ((count($this->data['SERVERS']['SAMBA']) == 0)
+        && isset($this->current['SAMBASID']) && isset($this->current['SAMBARIDBASE'])) {
+        $this->data['SERVERS']['SAMBA']['DEFAULT'] = array(
+          'SID'     => $this->get_cfg_value('SAMBASID'),
+          'RIDBASE' => $this->get_cfg_value('SAMBARIDBASE')
+        );
       }
     }
 
@@ -475,10 +473,9 @@ class config
     if (!$forceReload) {
       $ldap = $this->get_ldap_link();
       $ldap->cat($dn, array('fusionConfigMd5'));
-      if ($attrs = $ldap->fetch()) {
-        if (isset($attrs['fusionConfigMd5'][0]) && ($attrs['fusionConfigMd5'][0] == md5_file(CACHE_DIR.'/'.CLASS_CACHE))) {
-          return;
-        }
+      if (($attrs = $ldap->fetch()) && isset($attrs['fusionConfigMd5'][0])
+        && ($attrs['fusionConfigMd5'][0] == md5_file(CACHE_DIR.'/'.CLASS_CACHE))) {
+        return;
       }
     }
 
diff --git a/include/class_filter.inc b/include/class_filter.inc
index b578e79300fdd6ab5ef1ca0542f04c566de1ac8a..95d52598c8a1e51a7afc3179d097603bfceebdc5 100644
--- a/include/class_filter.inc
+++ b/include/class_filter.inc
@@ -301,33 +301,33 @@ class filter
       return $this->alphabet;
     }
 
-    $characters = _("*ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
-    $alphabet   = "";
-    $c          = 0;
+    $characters     = _('*ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789');
+    $this->alphabet = '';
+    $c              = 0;
 
     /* Fill cells with charaters */
     for ($i = 0, $l = mb_strlen($characters, 'UTF8'); $i < $l; $i++) {
       if ($c == 0) {
-        $alphabet .= "<tr>";
+        $this->alphabet .= "<tr>";
       }
 
-      $ch       = mb_substr($characters, $i, 1, "UTF8");
-      $alphabet .= "<td><a class=\"alphaselect\" href=\"main.php?plug=".
+      $ch             = mb_substr($characters, $i, 1, "UTF8");
+      $this->alphabet .= "<td><a class=\"alphaselect\" href=\"main.php?plug=".
         validate($_GET['plug'])."&amp;filter=".$ch."\">&nbsp;".$ch."&nbsp;</a></td>";
 
       if ($c++ == $columns) {
-        $alphabet .= "</tr>";
-        $c        = 0;
+        $this->alphabet .= "</tr>";
+        $c              = 0;
       }
     }
 
     /* Fill remaining cells */
     while ($c++ <= $columns) {
-      $alphabet .= "<td>&nbsp;</td>";
+      $this->alphabet .= "<td>&nbsp;</td>";
     }
 
     /* Save alphabet */
-    $this->alphabet = "<table width='100%'>$alphabet</table>";
+    $this->alphabet = '<table width="100%">'.$this->alphabet.'</table>';
 
     return $this->alphabet;
   }
@@ -473,24 +473,24 @@ class filter
         }
       }
 
-      $objectStorage = $this->objectStorage;
+      $branches = $this->objectStorage;
 
       if (isset($this->elements['FILTERTEMPLATE']) && $this->elementValues['FILTERTEMPLATE']) {
-        $objectStorage = array_merge(
-          $objectStorage,
+        $branches = array_merge(
+          $branches,
           array_map(
             function ($oc)
             {
               return 'ou=templates,'.$oc;
             },
-            $objectStorage
+            $branches
           )
         );
       }
 
       // Now call filter method and merge resulting entries.
       $result = array_merge($result, call_user_func(array($backend, 'query'),
-            $this, $this->base, $this->scope, $filter, $attributes, $this->category, $objectStorage));
+            $this, $this->base, $this->scope, $filter, $attributes, $this->category, $branches));
     }
 
     return $result;
@@ -504,10 +504,9 @@ class filter
   function isValid()
   {
     foreach ($this->elements as $tag => $element) {
-      if (isset($element->regex)) {
-        if (!preg_match('/'.(string)$element->regex.'/', $this->elementValues[$tag])) {
-          return FALSE;
-        }
+      if (isset($element->regex)
+       && !preg_match('/'.(string)$element->regex.'/', $this->elementValues[$tag])) {
+        return FALSE;
       }
     }
     return TRUE;
diff --git a/include/class_ldap.inc b/include/class_ldap.inc
index 1b367ca7406b216ac33aa76d0a695adc54114fb7..95c2d18072dfb41314233b9503961eee16bbb6a3 100644
--- a/include/class_ldap.inc
+++ b/include/class_ldap.inc
@@ -252,7 +252,7 @@ class LDAP
         $this->connect();
       }
 
-      $start = microtime(TRUE);
+      $startTime = microtime(TRUE);
       $this->clearResult($srp);
       switch (strtolower($scope)) {
         case 'base':
@@ -271,14 +271,12 @@ class LDAP
       $this->hasres[$srp] = TRUE;
 
       /* Check if query took longer as specified in max_ldap_query_time */
-      if ($this->max_ldap_query_time) {
-        $diff = microtime(TRUE) - $start;
-        if ($diff > $this->max_ldap_query_time) {
-          msg_dialog::display(_("Performance warning"), sprintf(_("LDAP performance is poor: last query took about %.2fs!"), $diff), WARNING_DIALOG);
-        }
+      $diff = microtime(TRUE) - $startTime;
+      if ($this->max_ldap_query_time && ($diff > $this->max_ldap_query_time)) {
+        msg_dialog::display(_("Performance warning"), sprintf(_("LDAP performance is poor: last query took about %.2fs!"), $diff), WARNING_DIALOG);
       }
 
-      $this->log("LDAP operation: time=".(microtime(TRUE) - $start)." operation=search('".$this->basedn."', '$filter')");
+      $this->log("LDAP operation: time=".$diff." operation=search('".$this->basedn."', '$filter')");
       return $this->sr[$srp];
     } else {
       $this->error = "Could not connect to LDAP server";
@@ -653,15 +651,14 @@ class LDAP
     }
 
     $str = "";
-    if (preg_match("/^objectClass: value #([0-9]*) invalid per syntax$/", $this->get_additional_error(), $m)) {
-      if (isset($attrs['objectClass'])) {
-        $ocs = $attrs['objectClass'];
-        if (!is_array($ocs)) {
-          $ocs = array($ocs);
-        }
-        if (isset($ocs[$m[1]])) {
-          $str .= " - <b>objectClass: ".$ocs[$m[1]]."</b>";
-        }
+    if (isset($attrs['objectClass'])
+      && preg_match("/^objectClass: value #([0-9]*) invalid per syntax$/", $this->get_additional_error(), $m)) {
+      $ocs = $attrs['objectClass'];
+      if (!is_array($ocs)) {
+        $ocs = array($ocs);
+      }
+      if (isset($ocs[$m[1]])) {
+        $str .= " - <b>objectClass: ".$ocs[$m[1]]."</b>";
       }
     }
     if ($error == "Undefined attribute type") {
@@ -886,12 +883,17 @@ class LDAP
       return $this->error;
     } else {
       $adderror = $this->get_additional_error();
-      if ($adderror != "") {
-        $error = $this->error." (".$this->get_additional_error().", ".sprintf(_("while operating on '%s' using LDAP server '%s'"), $this->basedn, $this->hostname).")";
+      if ($adderror != '') {
+        return sprintf(
+          _('%s (%s, while operating on "%s" using LDAP server "%s")'),
+          $this->error, $adderror, $this->basedn, $this->hostname
+        );
       } else {
-        $error = $this->error." (".sprintf(_("while operating on LDAP server %s"), $this->hostname).")";
+        return sprintf(
+          _('%s (while operating on LDAP server "%s")'),
+          $this->error, $this->hostname
+        );
       }
-      return $error;
     }
   }
 
@@ -1191,17 +1193,17 @@ class LDAP
     }
 
     // Get base to look for schema
-    $sr   = @ldap_read($this->cid, '', 'objectClass=*', array('subschemaSubentry'));
-    $attr = @ldap_get_entries($this->cid, $sr);
-    if (!isset($attr[0]['subschemasubentry'][0])) {
+    $res    = @ldap_read($this->cid, '', 'objectClass=*', array('subschemaSubentry'));
+    $attrs  = @ldap_get_entries($this->cid, $res);
+    if (!isset($attrs[0]['subschemasubentry'][0])) {
       return array();
     }
 
     /* Get list of objectclasses and fill array */
-    $nb = $attr[0]['subschemasubentry'][0];
+    $nb = $attrs[0]['subschemasubentry'][0];
     $objectclasses = array();
-    $sr = ldap_read ($this->cid, $nb, 'objectClass=*', array('objectclasses'));
-    $attrs = ldap_get_entries($this->cid, $sr);
+    $res    = ldap_read ($this->cid, $nb, 'objectClass=*', array('objectclasses'));
+    $attrs  = ldap_get_entries($this->cid, $res);
     if (!isset($attrs[0])) {
       return array();
     }
@@ -1332,10 +1334,10 @@ class LDAP
     ldap_bind ($ds, $admin, $password);
 
     /* Get base to look for naming contexts */
-    $sr   = @ldap_read ($ds, '', 'objectClass=*', array('namingContexts'));
-    $attr = @ldap_get_entries($ds, $sr);
+    $res    = @ldap_read ($ds, '', 'objectClass=*', array('namingContexts'));
+    $attrs  = @ldap_get_entries($ds, $res);
 
-    return $attr[0]['namingcontexts'];
+    return $attrs[0]['namingcontexts'];
   }
 }
 ?>
diff --git a/include/class_listing.inc b/include/class_listing.inc
index e5bbeaf87a6330b90356b5d45e380a4bbb1be4c7..168eceb93e5755cabdfb8f3e0ee5c8c8d40a3305 100644
--- a/include/class_listing.inc
+++ b/include/class_listing.inc
@@ -57,7 +57,7 @@ class listing
   protected $objectDnMapping  = array();
   protected $copyPasteHandler = NULL;
   protected $snapshotHandler  = NULL;
-  var $exporter       = array();
+  var $exporters      = array();
   var $exportColumns  = array();
   var $scrollPosition = 0;
   var $baseSelector;
@@ -112,7 +112,7 @@ class listing
       if (preg_match('/Exporter$/', $class)) {
         $info = call_user_func(array($class, "getInfo"));
         if ($info != NULL) {
-          $this->exporter = array_merge($this->exporter, $info);
+          $this->exporters = array_merge($this->exporters, $info);
         }
       }
     }
@@ -166,7 +166,7 @@ class listing
     $this->filter     = $filter;
     $filter->headpage = $this;
     if ($this->departmentBrowser) {
-      $this->departments = $this->getDepartments();
+      $this->refreshDepartmentsCache();
     }
     $this->filter->setBase($this->base);
   }
@@ -537,29 +537,26 @@ class listing
       }
 
       // Override the base if we got a message from the browser navigation
-      if ($this->departmentBrowser && isset($_GET['act'])) {
-        if (preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)) {
-          if (isset($this->departments[$match[1]])) {
-            $this->setBase($this->departments[$match[1]]['dn']);
-          }
-        }
+      if ($this->departmentBrowser && isset($_GET['act'])
+        && preg_match('/^department_([0-9]+)$/', validate($_GET['act']), $match)
+        && isset($this->departments[$match[1]])) {
+        $this->setBase($this->departments[$match[1]]['dn']);
       }
 
       // Filter POST with "act" attributes -> posted from action menu
-      if (isset($_POST['exec_act']) && $_POST['act'] != '') {
-        if (preg_match('/^export.*$/', $_POST['act']) && isset($this->exporter[$_POST['act']])) {
-          $exporter = $this->exporter[$_POST['act']];
-          $userinfo = ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
-          $entryIterator = new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
-          $sortedEntries = array();
-          foreach ($entryIterator as $entry) {
-            $sortedEntries[] = $entry;
-          }
-          $instance = new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
-          $type = call_user_func(array($exporter['class'], "getInfo"));
-          $type = $type[$_POST['act']];
-          send_binary_content($instance->query(), $type['filename'], $type = $type['mime']);
+      if (isset($_POST['exec_act']) && ($_POST['act'] != '')
+        && preg_match('/^export.*$/', $_POST['act']) && isset($this->exporters[$_POST['act']])) {
+        $exporter = $this->exporters[$_POST['act']];
+        $userinfo = ", "._("created by")." ".$ui->cn." - ".strftime('%A, %d. %B %Y, %H:%M:%S');
+        $entryIterator = new listingSortIterator($this->entries, $this->sortDirection[$this->sortColumn], "_sort".$this->sortColumn, $this->sortType);
+        $sortedEntries = array();
+        foreach ($entryIterator as $entry) {
+          $sortedEntries[] = $entry;
         }
+        $instance = new $exporter['class']($this->headline.$userinfo, $this->plainHeader, $sortedEntries, $this->exportColumns);
+        $type = call_user_func(array($exporter['class'], "getInfo"));
+        $type = $type[$_POST['act']];
+        send_binary_content($instance->query(), $type['filename'], $type = $type['mime']);
       }
 
       // Filter GET with "act" attributes
@@ -594,8 +591,7 @@ class listing
           $deps = $ui->get_module_departments($this->categories);
           $this->setBase($deps[0]);
         } elseif ($action == 'BACK') {
-          $base = preg_replace('/^[^,]+,/', '', $this->base);
-          $this->tryAndSetBase($base);
+          $this->tryAndSetBase(preg_replace('/^[^,]+,/', '', $this->base));
         } elseif ($action == 'HOME') {
           $this->tryAndSetBase(get_base_from_people($ui->dn));
         }
@@ -604,7 +600,7 @@ class listing
 
     // Reload departments
     if ($this->departmentBrowser) {
-      $this->departments = $this->getDepartments();
+      $this->refreshDepartmentsCache();
     }
 
     // Update filter and refresh entries
@@ -765,11 +761,10 @@ class listing
       foreach ($matches as $match) {
         $cl     = '';
         $method = '';
-        if (!preg_match('/^(.*)::(.*)$/', $match[1][0], $m)) {
-          if (!isset($this->filters[$match[1][0]]) || !preg_match('/^(.*)::(.*)$/', $this->filters[$match[1][0]], $m)) {
-            trigger_error('Unknown filter '.$match[1][0]);
-            continue;
-          }
+        if (!preg_match('/^(.*)::(.*)$/', $match[1][0], $m)
+          && (!isset($this->filters[$match[1][0]]) || !preg_match('/^(.*)::(.*)$/', $this->filters[$match[1][0]], $m))) {
+          trigger_error('Unknown filter '.$match[1][0]);
+          continue;
         }
         $cl     = $m[1];
         $method = $m[2];
@@ -1094,7 +1089,6 @@ class listing
    */
   function filterLink($row, $dn, $mask, ...$vals)
   {
-    $pid    = $this->pid;
     $params = array($mask);
 
     // Collect sprintf params
@@ -1119,7 +1113,7 @@ class listing
     if (count($params) > 1) {
       $trans  = sprintf(...$params);
       if ($trans != '') {
-        return '<a href="?plug='.$_GET['plug'].'&amp;PID='.$pid.'&amp;act=listing_edit_'.$row.'" title="'.$dn.'">'.$trans.'</a>';
+        return '<a href="?plug='.$_GET['plug'].'&amp;PID='.$this->pid.'&amp;act=listing_edit_'.$row.'" title="'.$dn.'">'.$trans.'</a>';
       }
     }
 
@@ -1217,10 +1211,9 @@ class listing
           /* Detect the longer base valid for this dn */
           $longerBase = '';
           foreach (array_keys($this->bases) as $base) {
-            if (preg_match('/'.preg_quote($base, '/').'$/i', $dn)) {
-              if (strlen($base) > strlen($longerBase)) {
-                $longerBase = $base;
-              }
+            if (preg_match('/'.preg_quote($base, '/').'$/i', $dn)
+              && (strlen($base) > strlen($longerBase))) {
+              $longerBase = $base;
             }
           }
           $this->setBase($longerBase);
@@ -1286,10 +1279,9 @@ class listing
     }
 
     // Filter POST with "act" attributes -> posted from action menu
-    if (isset($_POST['act']) && $_POST['act'] != '') {
-      if (!preg_match('/^export.*$/', $_POST['act'])) {
-        $result['action'] = validate($_POST['act']);
-      }
+    if (isset($_POST['act']) && ($_POST['act'] != '')
+      && !preg_match('/^export.*$/', $_POST['act'])) {
+      $result['action'] = validate($_POST['act']);
     }
 
     // Drop targets if empty
@@ -1554,19 +1546,20 @@ class listing
     }
   }
 
-  /*! \brief Get the departments */
-  function getDepartments()
+  /*! \brief Cache the departments */
+  function refreshDepartmentsCache()
   {
-    $departments = array();
     $ui = get_userinfo();
 
+    $this->departments = array();
+
     // Get list of supported department types
     $types = departmentManagement::getDepartmentTypes();
 
     // Load departments allowed by ACL
     $validDepartments = $ui->get_module_departments($this->categories);
 
-    /* Fetch departments andtheir informations */
+    /* Fetch departments and their informations */
     foreach ($types as $type) {
       $i    = objects::infos($type);
       $deps = objects::ls(
@@ -1602,11 +1595,9 @@ class listing
         $department['sort-attribute'] = $i['mainAttr'];
 
         // Move to the result list
-        $departments[] = $department;
+        $this->departments[] = $department;
       }
     }
-
-    return $departments;
   }
 
 
@@ -1731,7 +1722,7 @@ class listing
     $result .= "<li$separator id='actionmenu_exportList'><a href='#'><img class='center' src='geticon.php?context=actions&amp;icon=document-export&amp;size=16' alt='export'>&nbsp;"._("Export list")."&nbsp;<img src='images/forward-arrow.png' alt='arrow'></a><ul class='level3'>";
 
     // Render export actions
-    foreach ($this->exporter as $action => $exporter) {
+    foreach ($this->exporters as $action => $exporter) {
       $result .= $this->renderActionMenuActionLink('', $action, $exporter['label'], $exporter['image']);
     }
 
diff --git a/include/class_listingSortIterator.inc b/include/class_listingSortIterator.inc
index ab37ff1ab8a5b08aabd522ea01a689af264116de..f4b666d65095f01ef8f81326de59f3293cb76dd5 100644
--- a/include/class_listingSortIterator.inc
+++ b/include/class_listingSortIterator.inc
@@ -76,11 +76,6 @@ class listingSortIterator implements Iterator {
 
           // Take a look at the several types
           switch ($type) {
-            // Sort for string by default
-            default:
-            case 'string':
-              return strcoll($a, $b);
-
             case 'department':
               return strnatcmp($a, $b);
 
@@ -109,6 +104,11 @@ class listingSortIterator implements Iterator {
                 }
               }
               return 0;
+
+            // Sort for string by default
+            case 'string':
+            default:
+              return strcoll($a, $b);
           }
         }
       );
diff --git a/include/class_objects.inc b/include/class_objects.inc
index 6c1459599a1ea6c6873c719a3d212774f8b9c318..7fc6b55fd8c48c106d9f9b70bd155619e10a6d2c 100644
--- a/include/class_objects.inc
+++ b/include/class_objects.inc
@@ -408,10 +408,9 @@ class objects
       if ($ldap->count() != 0) {
         while ($attrs = $ldap->fetch()) {
           $dn = $attrs['dn'];
-          if ($requiredPermissions != '') {
-            if (!preg_match('/'.$requiredPermissions.'/', $ui->get_permissions($dn, $infos['aclCategory'].'/'.'template'))) {
-              continue;
-            }
+          if (($requiredPermissions != '')
+            && !preg_match('/'.$requiredPermissions.'/', $ui->get_permissions($dn, $infos['aclCategory'].'/'.'template'))) {
+            continue;
           }
           $templates[$dn] = $attrs['cn'][0].' - '.$key;
         }
diff --git a/include/class_pluglist.inc b/include/class_pluglist.inc
index a3a45571a4fbf94449d2d89184cc66994c932f45..8b83ec7ce0e7ece2fad4659a03ec20369723a145 100644
--- a/include/class_pluglist.inc
+++ b/include/class_pluglist.inc
@@ -408,10 +408,9 @@ class pluglist {
 
       /* Parse headlines */
       foreach ($config->data['SECTIONS'] as $section => $section_infos) {
-        $entries  = '';
-        $menu     = '';
-        $menu     = '<div class="iconmenu-section"><h1 class="menuheader">';
-        $menu     .= $section_infos['NAME']."</h1>\n";
+        $entries      = '';
+        $sectionMenu  = '<div class="iconmenu-section"><h1 class="menuheader">';
+        $sectionMenu  .= $section_infos['NAME']."</h1>\n";
 
         foreach ($config->data['MENU'][$section] as $info) {
           if (!$this->check_access($info)) {
@@ -445,7 +444,7 @@ class pluglist {
 
         /* Append to menu */
         if ($entries != "") {
-          $this->iconmenu .= $menu.$entries."</div>\n";
+          $this->iconmenu .= $sectionMenu.$entries."</div>\n";
         }
       }
     }
diff --git a/include/class_session.inc b/include/class_session.inc
index e54a922a279cca81d0906eefb9126db0393ad002..28f052c1266396e01a4acb059d2f212b6fba8190 100644
--- a/include/class_session.inc
+++ b/include/class_session.inc
@@ -117,9 +117,8 @@ class session {
     }
 
     /* Global fallback if not set */
-    if ($channel == "") {
-      $ret = &$_SESSION[$name];
-      return $ret;
+    if ($channel == '') {
+      return $_SESSION[$name];
     }
 
     /* Sanity check */
@@ -128,9 +127,7 @@ class session {
       exit;
     }
 
-    $channel  = "gch_".$channel;
-    $ret      = &$_SESSION[$channel][$name];
-    return $ret;
+    return $_SESSION['gch_'.$channel][$name];
   }
 
   /*!
@@ -154,8 +151,7 @@ class session {
    */
   public static function &global_get_ref($name)
   {
-    $ret = &$_SESSION[$name];
-    return $ret;
+    return $_SESSION[$name];
   }
 
   /*!
@@ -260,14 +256,5 @@ class session {
   {
     @session_destroy();
   }
-
-  /*!
-   * \brief Get all sessions
-   */
-  public static function &get_all()
-  {
-    $ret = &$_SESSION;
-    return $ret;
-  }
 }
 ?>
diff --git a/include/class_template.inc b/include/class_template.inc
index f5897d3d73d75615f8faa5f26e33d2a21096794b..58517ba1c0159e1c996a1e514c607c8235337719 100644
--- a/include/class_template.inc
+++ b/include/class_template.inc
@@ -140,19 +140,19 @@ class template
 
   function serialize()
   {
-    $attributes = array();
+    $ret = array();
     foreach ($this->tabObject->by_object as $class => $plugin) {
       if (!isset($this->attributes[$class])) {
         continue;
       }
-      $attributes[$class] = array('name' => $this->tabObject->by_name[$class], 'attrs' => array());
+      $ret[$class] = array('name' => $this->tabObject->by_name[$class], 'attrs' => array());
       foreach ($this->attributes[$class] as $attr) {
-        $plugin->attributesAccess[$attr]->serializeAttribute($attributes[$class]['attrs'], FALSE);
+        $plugin->attributesAccess[$attr]->serializeAttribute($ret[$class]['attrs'], FALSE);
       }
-      $attributes[$class]['attrs_order'] = array_keys($attributes[$class]['attrs']);
+      $ret[$class]['attrs_order'] = array_keys($ret[$class]['attrs']);
     }
 
-    return $attributes;
+    return $ret;
   }
 
   function deserialize($values)
@@ -197,19 +197,19 @@ class template
           return $dialogResult;
         }
       }
-      $attributes = array();
+      $attributesRendered = array();
       foreach ($this->attributes[$class] as $attr) {
         if ($plugin->attributesAccess[$attr]->getAclInfo() !== FALSE) {
           // We assign ACLs so that attributes can use them in their template code
           $smarty->assign($plugin->attributesAccess[$attr]->getAcl().'ACL', $plugin->aclGetPermissions($plugin->attributesAccess[$attr]->getAcl()));
         }
-        $plugin->attributesAccess[$attr]->renderAttribute($attributes, FALSE);
+        $plugin->attributesAccess[$attr]->renderAttribute($attributesRendered, FALSE);
       }
 
       $smarty->assign('section', $class);
       $smarty->assign('sectionId', $class);
       $smarty->assign('sectionClasses', ' fullwidth');
-      $smarty->assign('attributes', $attributes);
+      $smarty->assign('attributes', $attributesRendered);
 
       $posted[]   = $class.'_posted';
       $sections[] = $smarty->fetch(get_template_path('simpleplugin_section.tpl'));
diff --git a/include/class_tests.inc b/include/class_tests.inc
index 5cbfc410bef399e777dc2be1fac0c25a067a0e35..2dc73fdf88cad21f6b6555f86b64dacc2ff8bcc0 100644
--- a/include/class_tests.inc
+++ b/include/class_tests.inc
@@ -268,16 +268,10 @@ class tests
    */
   public static function is_email($address)
   {
-    if ($address == "") {
-      return TRUE;
-    }
-    if (filter_var($address, FILTER_VALIDATE_EMAIL) !== FALSE) {
-      return TRUE;
-    } elseif (filter_var($address.'.com', FILTER_VALIDATE_EMAIL) !== FALSE) {
-      /* this is to allow addresses like example@localhost, which are refused by some PHP version */
-      return TRUE;
-    }
-    return FALSE;
+    /* last test is to allow addresses like example@localhost, which are refused by some PHP version */
+    return (($address == '')
+      || (filter_var($address, FILTER_VALIDATE_EMAIL) !== FALSE)
+      || (filter_var($address.'.com', FILTER_VALIDATE_EMAIL) !== FALSE));
   }
 
 
@@ -293,12 +287,8 @@ class tests
     global $config;
     $reservedNames = array();
     foreach ($config->data['OBJECTS'] as $infos) {
-      if (isset($infos['ou'])) {
-        if ($infos['ou'] != '') {
-          if (preg_match('/ou=([^,]+),$/', $infos['ou'], $m)) {
-            $reservedNames[] = $m[1];
-          }
-        }
+      if (isset($infos['ou']) && preg_match('/ou=([^,]+),$/', $infos['ou'], $m)) {
+        $reservedNames[] = $m[1];
       }
     }
 
diff --git a/include/class_userinfo.inc b/include/class_userinfo.inc
index 53cc3d77151b4e21d9fa8531d084a9f6fa4750c8..7663f3441699224cdf1f648ea3c39505c04c3d0a 100644
--- a/include/class_userinfo.inc
+++ b/include/class_userinfo.inc
@@ -900,27 +900,20 @@ class userinfo
     // Check if the account has reached its kick off limitations.
     // ----------------------------------------------------------
     // Once the accout reaches the kick off limit it has expired.
-    if ($sambaKickoffTime !== NULL) {
-      if (time() >= $sambaKickoffTime) {
-        return POSIX_ACCOUNT_EXPIRED;
-      }
+    if (($sambaKickoffTime !== NULL) && (time() >= $sambaKickoffTime)) {
+      return POSIX_ACCOUNT_EXPIRED;
     }
 
     // Check if the account has expired.
     // ---------------------------------
-    // An account is locked/expired once its expiration date has reached (shadowExpire).
+    // An account is locked/expired once its expiration date was reached (shadowExpire).
     // If the optional attribute (shadowInactive) is set, we've to postpone
     //  the account expiration by the amount of days specified in (shadowInactive).
-    if (($shadowExpire != NULL) && ($shadowExpire <= $current)) {
-
-      // The account seems to be expired, but we've to check 'shadowInactive' additionally.
-      // ShadowInactive specifies an amount of days we've to reprieve the user.
-      // It some kind of x days' grace.
-      if (($shadowInactive == NULL) || $current > $shadowExpire + $shadowInactive) {
-
-        // Finally we've detect that the account is deactivated.
-        return POSIX_ACCOUNT_EXPIRED;
-      }
+    // ShadowInactive specifies an amount of days we've to reprieve the user.
+    // It some kind of x days' grace.
+    if (($shadowExpire != NULL) && ($shadowExpire <= $current)
+      && (($shadowInactive == NULL) || ($current > $shadowExpire + $shadowInactive))) {
+      return POSIX_ACCOUNT_EXPIRED;
     }
 
     // The users password is going to expire.
@@ -930,18 +923,12 @@ class userinfo
     // The user has to be warned, if the days left till expiration, match the
     //  configured warning period (shadowWarning)
     // --> shadowWarning: Warn x days before account expiration.
-    if (($shadowExpire != NULL) && ($shadowWarning != NULL)) {
-
-      // Check if the account is still active and not already expired.
-      if ($shadowExpire >= $current) {
-
-        // Check if we've to warn the user by comparing the remaining
-        //  number of days till expiration with the configured amount
-        //  of days in shadowWarning.
-        if (($shadowExpire - $current) <= $shadowWarning) {
-          return POSIX_WARN_ABOUT_EXPIRATION;
-        }
-      }
+    // Check if the account is still active and not already expired.
+    // Check if we've to warn the user by comparing the remaining
+    //  number of days till expiration with the configured amount of days in shadowWarning.
+    if (($shadowExpire != NULL) && ($shadowWarning != NULL)
+      && ($shadowExpire >= $current) && ($shadowExpire <= $current + $shadowWarning)) {
+      return POSIX_WARN_ABOUT_EXPIRATION;
     }
 
     // -- I guess this is the correct detection, isn't it?
@@ -959,11 +946,10 @@ class userinfo
     // The age of the current password (shadowLastChange) plus the maximum
     //  amount amount of days (shadowMax) has to be smaller than the
     //  current timestamp.
-    if (($shadowLastChange != NULL) && ($shadowMax != NULL)) {
-      // Check if we've an outdated password.
-      if ($current >= ($shadowLastChange + $shadowMax)) {
-        return POSIX_FORCE_PASSWORD_CHANGE;
-      }
+    // Check if we've an outdated password.
+    if (($shadowLastChange != NULL) && ($shadowMax != NULL)
+      && ($current >= $shadowLastChange + $shadowMax)) {
+      return POSIX_FORCE_PASSWORD_CHANGE;
     }
 
     // Check if we've to freeze the users password.
@@ -971,11 +957,10 @@ class userinfo
     // Once a user has changed his password, he cannot change it again
     //  for a given amount of days (shadowMin).
     // We should not allow to change the password within FusionDirectory too.
-    if (($shadowLastChange != NULL) && ($shadowMin != NULL)) {
-      // Check if we've an outdated password.
-      if (($shadowLastChange + $shadowMin) >= $current) {
-        return POSIX_DISALLOW_PASSWORD_CHANGE;
-      }
+    // Check if we've an outdated password.
+    if (($shadowLastChange != NULL) && ($shadowMin != NULL)
+      && ($shadowLastChange + $shadowMin >= $current)) {
+      return POSIX_DISALLOW_PASSWORD_CHANGE;
     }
 
     return 0;
diff --git a/include/functions.inc b/include/functions.inc
index 9cee2767f0cb0c2c0fc20a5b60a0625b776ed31c..d95f36666d5df3245c4e0aa96cbfd082e985aeac 100644
--- a/include/functions.inc
+++ b/include/functions.inc
@@ -1029,8 +1029,7 @@ function get_ou($name)
   if ($config->get_cfg_value($name, '_not_set_') != '_not_set_') {
     $ou = $config->get_cfg_value($name);
   } elseif (isset($map[$name])) {
-    $ou = $map[$name];
-    return $ou;
+    return $map[$name];
   } else {
     return NULL;
   }
@@ -2365,9 +2364,7 @@ function isIpInNet($ip, $net, $mask)
 function expandIPv6 ($ip)
 {
   $hex  = unpack('H*hex', inet_pton($ip));
-  $ip   = substr(preg_replace('/([A-f0-9]{4})/', "$1:", $hex['hex']), 0, -1);
-
-  return $ip;
+  return substr(preg_replace('/([A-f0-9]{4})/', "$1:", $hex['hex']), 0, -1);
 }
 
 /* Mark the occurance of a string with a span */
diff --git a/include/functions_debug.inc b/include/functions_debug.inc
index d7447e3c2ca68b3752c18ad8f02bc09c78ff3bdf..76d2803dcd38379afc2021862534c0307b006e2f 100644
--- a/include/functions_debug.inc
+++ b/include/functions_debug.inc
@@ -151,10 +151,6 @@ class printAClass {
         case 'array':
           break;
 
-        case 'object':
-          $key_style = 'color:#FF9B2F;';
-          break;
-
         case 'integer':
           $value_style = 'color:green;';
           break;
@@ -182,6 +178,11 @@ class printAClass {
             $value        = nl2br(htmlspecialchars($value));
           }
           break;
+
+        case 'object':
+        default:
+          $key_style = 'color:#FF9B2F;';
+          break;
       }
 
       $this->output .= '<tr>';
@@ -260,11 +261,10 @@ function _script_globals()
   $varcount = 0;
 
   foreach ($GLOBALS as $GLOBALS_current_key => $GLOBALS_current_value) {
-    if (++$varcount > $GLOBALS_initial_count) {
-      /* die wollen wir nicht! */
-      if ($GLOBALS_current_key != 'HTTP_SESSION_VARS' && $GLOBALS_current_key != '_SESSION') {
-        $script_GLOBALS[$GLOBALS_current_key] = $GLOBALS_current_value;
-      }
+    if ((++$varcount > $GLOBALS_initial_count)
+      && ($GLOBALS_current_key != 'HTTP_SESSION_VARS')
+      && ($GLOBALS_current_key != '_SESSION')) {
+      $script_GLOBALS[$GLOBALS_current_key] = $GLOBALS_current_value;
     }
   }
 
diff --git a/include/management/class_management.inc b/include/management/class_management.inc
index b79416f5f4bb6b4a24a0aa97ed5266252ea564b9..43fa5ef8b11b2dbf4d7675ce329f9f855a1c561a 100644
--- a/include/management/class_management.inc
+++ b/include/management/class_management.inc
@@ -731,10 +731,9 @@ class management
     // Open object
     $this->openTabObject(objects::open($this->dn, $entry->getTemplatedType()), $this->dn);
     @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->dn, 'Edit entry initiated');
-    if (isset($action['subaction'])) {
-      if ($this->handleSubAction($action) === FALSE) {
-        trigger_error('Was not able to handle subaction: '.$action['subaction']);
-      }
+    if (isset($action['subaction'])
+      && ($this->handleSubAction($action) === FALSE)) {
+      trigger_error('Was not able to handle subaction: '.$action['subaction']);
     }
   }
 
diff --git a/include/management/columns/class_Column.inc b/include/management/columns/class_Column.inc
index 66b0e9de33d73bddff0622fa98fddad2f9a38bf1..5833b0a49cddaf06ee05e69f471c1e426eb60503 100644
--- a/include/management/columns/class_Column.inc
+++ b/include/management/columns/class_Column.inc
@@ -106,12 +106,12 @@ class Column
 
   function renderCell(ListingEntry $entry)
   {
-    $attribute = $this->attribute;
+    $attr = $this->attribute;
     if (isset($this->templateAttribute) && $entry->isTemplate()) {
-      $attribute = $this->templateAttribute;
+      $attr = $this->templateAttribute;
     }
-    if (isset($attribute) && isset($entry[$attribute])) {
-      return htmlentities($entry[$attribute], ENT_COMPAT, 'UTF-8');
+    if (isset($attr) && isset($entry[$attr])) {
+      return htmlentities($entry[$attr], ENT_COMPAT, 'UTF-8');
     } else {
       return '&nbsp;';
     }
@@ -119,12 +119,12 @@ class Column
 
   function getRawExportValue(ListingEntry $entry)
   {
-    $attribute = $this->attribute;
+    $attr = $this->attribute;
     if (isset($this->templateAttribute) && $entry->isTemplate()) {
-      $attribute = $this->templateAttribute;
+      $attr = $this->templateAttribute;
     }
-    if (isset($attribute) && isset($entry[$attribute])) {
-      return $entry[$attribute];
+    if (isset($attr) && isset($entry[$attr])) {
+      return $entry[$attr];
     } else {
       return '';
     }
@@ -158,11 +158,6 @@ class Column
 
     // Take a look at the several types
     switch ($this->type) {
-      // Sort for string by default
-      default:
-      case 'string':
-        return strcoll($a, $b);
-
       case 'department':
         return strnatcmp($a, $b);
 
@@ -191,6 +186,11 @@ class Column
           }
         }
         return 0;
+
+      // Sort for string by default
+      case 'string':
+      default:
+        return strcoll($a, $b);
     }
   }
 }
diff --git a/include/management/columns/class_PropertiesColumn.inc b/include/management/columns/class_PropertiesColumn.inc
index 502b701e5a136c7b59a1c6c991a1774745ea0888..a3ff9aae7052a6c0c8f2d1aa707939ce035d132b 100644
--- a/include/management/columns/class_PropertiesColumn.inc
+++ b/include/management/columns/class_PropertiesColumn.inc
@@ -54,8 +54,8 @@ class PropertiesColumn extends Column
 
   function fillNeededAttributes(array &$attrs)
   {
-    foreach ($this->tabs as $type => $tabs) {
-      foreach ($tabs as $class) {
+    foreach ($this->tabs as $classes) {
+      foreach ($classes as $class) {
         $class::fillAccountAttrsNeeded($attrs);
       }
     }
diff --git a/include/password-methods/class_password-methods-smd5.inc b/include/password-methods/class_password-methods-smd5.inc
index 96d56b3b68a58699a9b53b91e5ee33a7afd6027b..de2ed413a8c6fa9f0ee9a6acc406f89d0b0a096c 100644
--- a/include/password-methods/class_password-methods-smd5.inc
+++ b/include/password-methods/class_password-methods-smd5.inc
@@ -58,8 +58,7 @@ class passwordMethodsmd5 extends passwordMethod
     mt_srand(microtime() * 10000000);
     $salt0  = substr(pack('h*', md5(mt_rand())), 0, 8);
     $salt   = substr(pack('H*', md5($salt0 . $pwd)), 0, 4);
-    $hash   = '{SMD5}'.base64_encode(pack('H*', md5($pwd . $salt)) . $salt);
-    return $hash;
+    return '{SMD5}'.base64_encode(pack('H*', md5($pwd . $salt)) . $salt);
   }
 
   function checkPassword($pwd, $hash)
diff --git a/include/password-methods/class_password-methods-ssha.inc b/include/password-methods/class_password-methods-ssha.inc
index fa386d7aacf82f5beda9bb6a372d58c9c6504ebc..0f2bd5cb4e0e8956b4ef306db8e4ca4cb865f4f1 100644
--- a/include/password-methods/class_password-methods-ssha.inc
+++ b/include/password-methods/class_password-methods-ssha.inc
@@ -59,7 +59,6 @@ class passwordMethodssha extends passwordMethod
       $salt = substr(pack('h*', md5(mt_rand())), 0, 8);
       $salt = substr(pack('H*', sha1($salt.$pwd)), 0, 4);
       $pwd  = '{SSHA}'.base64_encode(pack('H*', sha1($pwd.$salt)).$salt);
-      return $pwd;
     } elseif (function_exists('mhash')) {
       $salt = mhash_keygen_s2k(MHASH_SHA1, $pwd, substr(pack('h*', md5(mt_rand())), 0, 8), 4);
       $pwd  = '{SSHA}'.base64_encode(mhash(MHASH_SHA1, $pwd.$salt).$salt);
diff --git a/include/password-methods/class_password-methods.inc b/include/password-methods/class_password-methods.inc
index efbf1a11905066500def07677f54c7132003cd42..8bb4a12ce12aa0f29343e0fcc8734da42bfa4508 100644
--- a/include/password-methods/class_password-methods.inc
+++ b/include/password-methods/class_password-methods.inc
@@ -29,7 +29,6 @@
  */
 class passwordMethod
 {
-  var $attrs    = array();
   var $display  = FALSE;
   var $hash     = '';
 
@@ -95,8 +94,6 @@ class passwordMethod
       if (isset($attrs['userPassword'][0])) {
         $pwd = $attrs['userPassword'][0];
       }
-    } elseif (isset($this->attrs['userPassword'][0])) {
-      $pwd = $this->attrs['userPassword'][0];
     }
     return preg_match("/^[^\}]*+\}!/", $pwd);
   }
@@ -138,17 +135,16 @@ class passwordMethod
     }
 
     /* Get current password hash */
-    $attrs  = $this->attrs;
     $pwd    = '';
     $ldap   = $config->get_ldap_link();
     $ldap->cd($config->current['BASE']);
     if (!empty($dn)) {
       $ldap->cat($dn);
       $attrs = $ldap->fetch();
-    }
-    if (isset($attrs['userPassword'][0])) {
-      $pwd = $attrs['userPassword'][0];
-      $dn  = $attrs['dn'];
+      if (isset($attrs['userPassword'][0])) {
+        $pwd = $attrs['userPassword'][0];
+        $dn  = $attrs['dn'];
+      }
     }
 
     /* We can only lock/unlock non-empty passwords */
diff --git a/include/php_setup.inc b/include/php_setup.inc
index 2cc4a09bc401f0a6e396a1a29722caca8dc0bda7..3bb7ba0b907ea1ed9f7823b29f8cf4abc9856b74 100644
--- a/include/php_setup.inc
+++ b/include/php_setup.inc
@@ -179,11 +179,9 @@ function gosaRaiseError($errno, $errstr, $errfile, $errline)
   }
 
   /* Hide ldap size limit messages */
-  if (preg_match('/ldap_error/', $errstr)) {
-    if (preg_match('/sizelimit/', $errstr)) {
-      set_error_handler('gosaRaiseError', E_WARNING | E_NOTICE | E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE | E_STRICT);
-      return;
-    }
+  if (preg_match('/ldap_error/', $errstr) && preg_match('/sizelimit/', $errstr)) {
+    set_error_handler('gosaRaiseError', E_WARNING | E_NOTICE | E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE | E_STRICT);
+    return;
   }
 
   /* Error messages are hidden in FusionDirectory, so we only send them to the logging class and abort here */
diff --git a/include/simpleplugin/attributes/class_CompositeAttribute.inc b/include/simpleplugin/attributes/class_CompositeAttribute.inc
index 22f06fadb19deb38aa89f8ec34b3d84b43b94d2f..03bae4ca5d707c228ce624b5a56c8e49e4342caa 100644
--- a/include/simpleplugin/attributes/class_CompositeAttribute.inc
+++ b/include/simpleplugin/attributes/class_CompositeAttribute.inc
@@ -188,14 +188,13 @@ class CompositeAttribute extends Attribute
 
   function getArrayValue ()
   {
-    $values = array_map(
+    return array_map(
       function ($a)
       {
         return $a->displayValue($a->getValue());
       },
       $this->attributes
     );
-    return $values;
   }
 
   function check ()
diff --git a/include/simpleplugin/attributes/class_FileAttribute.inc b/include/simpleplugin/attributes/class_FileAttribute.inc
index 181f2dfa7329a7688a46fe4714478ccf3e2fdee6..e3b11b58a5599bf63800442a4af43192065e6221 100644
--- a/include/simpleplugin/attributes/class_FileAttribute.inc
+++ b/include/simpleplugin/attributes/class_FileAttribute.inc
@@ -182,7 +182,7 @@ class FileDownloadAttribute extends FileAttribute
 
   function renderAttribute(array &$attributes, $readOnly)
   {
-    if ($this->upload == FALSE) {
+    if ($this->upload === FALSE) {
       parent::renderAttribute($attributes, FALSE);
     } else {
       parent::renderAttribute($attributes, $readOnly);
@@ -289,11 +289,9 @@ class ImageAttribute extends FileAttribute
     $id = $this->getHtmlId();
     if (!$this->disabled && $this->isVisible()) {
       foreach (array_keys($_POST) as $name) {
-        if (!$this->isRequired()) {
-          if (preg_match('/^'.$id.'_remove_/', $name)) {
-            $this->setPostValue('');
-            break;
-          }
+        if (!$this->isRequired() && preg_match('/^'.$id.'_remove_/', $name)) {
+          $this->setPostValue('');
+          break;
         }
         if (preg_match('/^'.$id.'_upload_/', $name)) {
           parent::loadPostValue();
diff --git a/include/simpleplugin/attributes/class_SetAttribute.inc b/include/simpleplugin/attributes/class_SetAttribute.inc
index f0210f3836614ef61c0f1b416423e66894144bca..330239bfdf303285391c69275964d09938d39ed5 100644
--- a/include/simpleplugin/attributes/class_SetAttribute.inc
+++ b/include/simpleplugin/attributes/class_SetAttribute.inc
@@ -583,13 +583,11 @@ class OrderedArrayAttribute extends SetAttribute
         return TRUE;
       }
     }
-    if ($this->edit_enabled) {
-      if (preg_match('/^'.$id.'_edit_/', $postValue)) {
-        $key = preg_replace('/^'.$id.'_edit_/', '', $postValue);
-        $key = preg_replace('/_[xy]$/', '', $key);
-        $this->handleEdit($key);
-        return TRUE;
-      }
+    if ($this->edit_enabled && preg_match('/^'.$id.'_edit_/', $postValue)) {
+      $key = preg_replace('/^'.$id.'_edit_/', '', $postValue);
+      $key = preg_replace('/_[xy]$/', '', $key);
+      $this->handleEdit($key);
+      return TRUE;
     }
     if (preg_match('/^'.$id.'_del_/', $postValue)) {
       $key = preg_replace('/^'.$id.'_del_/', '', $postValue);
diff --git a/include/simpleplugin/class_simpleTabs.inc b/include/simpleplugin/class_simpleTabs.inc
index 13247b4228f1744f028451a5322945c2ceda27b0..7ac980eafdf66998923c85558d979f5f33f86cf7 100644
--- a/include/simpleplugin/class_simpleTabs.inc
+++ b/include/simpleplugin/class_simpleTabs.inc
@@ -203,16 +203,15 @@ class simpleTabs
     }
     unset($obj);
 
+    /* Build tab line */
+    $display = $this->gen_tabs($this->dialogOpened());
+
     /* Show object */
-    $display = '<div class="tab-content">'."\n";
+    $display .= '<div class="tab-content">'."\n";
 
     $display .= $this->by_object[$this->current]->execute();
 
-    /* Build tab line */
-    $tabs   = $this->gen_tabs($this->dialogOpened());
-
-    /* Footer for tabbed dialog */
-    $display = $tabs.$display.'</div>';
+    $display .= '</div>';
 
     return $display;
   }
@@ -254,11 +253,9 @@ class simpleTabs
     $style    = array('tab-left', 'tab-active', 'tab-right');
     foreach ($this->by_name as $class => $name) {
 
-      /* Activate right tabs with style "tab-right" */
-      if ($index == 1) {
-        $index++;
-      } elseif ($class == $this->current) {
-        /* Activate current tab with style "tab-active " */
+      /* Activate right tabs with style "tab-right"
+       * Activate current tab with style "tab-active " */
+      if (($index == 1) || ($class == $this->current)) {
         $index++;
       }
 
diff --git a/plugins/addons/dashboard/class_dashBoardUsers.inc b/plugins/addons/dashboard/class_dashBoardUsers.inc
index 3a3f72c9517baee79e79805e21f7bf3062c13697..9bff36861047d630020c11f000ae885540398991 100644
--- a/plugins/addons/dashboard/class_dashBoardUsers.inc
+++ b/plugins/addons/dashboard/class_dashBoardUsers.inc
@@ -122,9 +122,9 @@ class dashboardUsers extends simplePlugin
         sprintf(_('Group statistics could not be computed because of the following LDAP error: %s'), $e->getMessage()),
         ERROR_DIALOG
       );
-      $nb_groups          = 0;
-      $nb_mail_groups     = 0;
-      $nb_samba_accounts  = 0;
+      $nb_groups        = 0;
+      $nb_mail_groups   = 0;
+      $nb_samba_groups  = 0;
     }
 
     return array(
diff --git a/plugins/admin/departments/class_department.inc b/plugins/admin/departments/class_department.inc
index 319f1fc74ae5b760894c8d613cf9ee4669d91827..ddf29b1774cb88aa20d5e94f2ab35ac7d05f96e2 100644
--- a/plugins/admin/departments/class_department.inc
+++ b/plugins/admin/departments/class_department.inc
@@ -168,10 +168,8 @@ class department extends simplePlugin
 
     $namingAttr = static::$namingAttr;
 
-    if ($namingAttr == 'ou') {
-      if (tests::is_department_name_reserved($this->$namingAttr)) {
-        $message[] = msgPool::reserved(_('Name'));
-      }
+    if (($namingAttr == 'ou') && tests::is_department_name_reserved($this->$namingAttr)) {
+      $message[] = msgPool::reserved(_('Name'));
     }
 
     return $message;
diff --git a/plugins/admin/users/class_userManagement.inc b/plugins/admin/users/class_userManagement.inc
index ca7d2351afa5f7e9025c472dbaca427feff8d735..8632dcff0cb4b0a75446947d27d6c09b1e2149a3 100644
--- a/plugins/admin/users/class_userManagement.inc
+++ b/plugins/admin/users/class_userManagement.inc
@@ -36,11 +36,7 @@ class LockAction extends Action
   function isLocked(ListingEntry $entry)
   {
     if (isset($entry['userPassword']) && preg_match('/^\{[^\}]/', $entry['userPassword'])) {
-      if (preg_match('/^[^\}]*+\}!/', $entry['userPassword'])) {
-        return TRUE;
-      } else {
-        return FALSE;
-      }
+      return preg_match('/^[^\}]*+\}!/', $entry['userPassword']);
     }
     return NULL;
   }
diff --git a/plugins/personal/generic/class_user.inc b/plugins/personal/generic/class_user.inc
index 30d80ddc1fd8cbf229c2927119b337c1a1fcd4aa..575196e5ec42e03cc9d85971c060b0ce1019e0f6 100644
--- a/plugins/personal/generic/class_user.inc
+++ b/plugins/personal/generic/class_user.inc
@@ -532,9 +532,9 @@ class user extends simplePlugin
   function compute_dn()
   {
     global $config;
+
     if ($this->is_template) {
-      $dn = 'cn='.ldap_escape_dn($this->_template_cn).',ou=templates,'.get_ou('userRDN').$this->base;
-      return $dn;
+      return 'cn='.ldap_escape_dn($this->_template_cn).',ou=templates,'.get_ou('userRDN').$this->base;
     }
 
     $this->update_cn();
@@ -683,10 +683,8 @@ class user extends simplePlugin
           return sprintf(_('You must wait %d seconds before changing your password again'), $policy['pwdMinAge'][0] - ($now->getTimeStamp() - $date->getTimeStamp()));
         }
       }
-      if (isset($policy['pwdSafeModify'][0]) && ($policy['pwdSafeModify'][0] == 'FALSE')) {
-        if (empty($current_password)) {
-          $current_password = NULL;
-        }
+      if (isset($policy['pwdSafeModify'][0]) && ($policy['pwdSafeModify'][0] == 'FALSE') && empty($current_password)) {
+        $current_password = NULL;
       }
       if (isset($attrs['pwdHistory'][0])) {
         unset($attrs['pwdHistory']['count']);
diff --git a/setup/class_setup.inc b/setup/class_setup.inc
index 10f15707a4f6b9691d11c829ae459f701cc7db38..e153c9a98fe06c43825f793122c30841b8227d20 100644
--- a/setup/class_setup.inc
+++ b/setup/class_setup.inc
@@ -90,8 +90,7 @@ class setup
     $smarty->assign('usePrototype', 'true');
     $this->o_steps[$this->i_previous]->set_active(FALSE);
     $this->o_steps[$this->i_current]->set_active();
-    $content = $this->o_steps[$this->i_current]->execute();
-    return $content;
+    return $this->o_steps[$this->i_current]->execute();
   }
 
 
diff --git a/setup/class_setupStepConfig.inc b/setup/class_setupStepConfig.inc
index 55a472f168262a17266536076f5f994f94aaa7a5..6f823dea2695dc918b32ba759887cb62f5de704a 100644
--- a/setup/class_setupStepConfig.inc
+++ b/setup/class_setupStepConfig.inc
@@ -72,8 +72,7 @@ class setupStepConfig extends configInLdap
 
   function get_title()
   {
-    $infos = parent::plInfo();
-    return $infos['plDescription'];
+    return $this->get_description();
   }
 
   function get_description()