diff --git a/html/index.php b/html/index.php
index dcbfeb0d5e269ae669f8888475161822e179d07b..e0fec91d6f742ca9204fe8e19c3eae309f8d9b14 100644
--- a/html/index.php
+++ b/html/index.php
@@ -31,6 +31,12 @@ header('X-XSS-Protection: 1; mode=block');
 header('X-Content-Type-Options: nosniff');
 header('X-Frame-Options: deny');
 
+/**
+ * @var Smarty $smarty    Defined in php_setup.inc
+ * @var string $BASE_DIR  Defined in php_setup.inc
+ * @var string $ssl       Defined in php_setup.inc
+ */
+
 /*****************************************************************************
  *                               M   A   I   N                               *
  *****************************************************************************/
@@ -51,7 +57,7 @@ if (isset($_REQUEST['signout']) && $_REQUEST['signout']) {
       phpCAS::client(
         CAS_VERSION_2_0,
         $config->get_cfg_value('casHost', 'localhost'),
-        (int)($config->get_cfg_value('casPort', 443)),
+        $config->get_cfg_value('casPort', '443'),
         $config->get_cfg_value('casContext', '')
       );
       // Set the CA certificate that is the issuer of the cert
@@ -108,20 +114,20 @@ session::un_set('plist');
 unset($plist);
 
 /* Set template compile directory */
-$smarty->compile_dir = $config->get_cfg_value('templateCompileDirectory', SPOOL_DIR);
+$smarty->setCompileDir($config->get_cfg_value('templateCompileDirectory', SPOOL_DIR));
 
 /* Check for compile directory */
-if (!(is_dir($smarty->compile_dir) && is_writable($smarty->compile_dir))) {
+if (!(is_dir($smarty->getCompileDir()) && is_writable($smarty->getCompileDir()))) {
   throw new FatalError(
     htmlescape(sprintf(
       _('Directory "%s" specified as compile directory is not accessible!'),
-      $smarty->compile_dir
+      $smarty->getCompileDir()
     ))
   );
 }
 
 /* Check for old files in compile directory */
-clean_smarty_compile_dir($smarty->compile_dir);
+clean_smarty_compile_dir($smarty->getCompileDir());
 
 Language::init();
 
diff --git a/html/main.php b/html/main.php
index d5ac9e11c411dad7cc4be53ff08453f21939054c..f0c5ac8b9fed62da076cb44278da9f1aaf59be45 100644
--- a/html/main.php
+++ b/html/main.php
@@ -19,6 +19,14 @@
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 */
 
+/**
+ * @var Smarty $smarty                  Defined in php_setup.inc
+ * @var string $BASE_DIR                Defined in php_setup.inc
+ * @var string $ssl                     Defined in php_setup.inc
+ * @var string $error_collector         Defined in php_setup.inc
+ * @var string $error_collector_mailto  Defined in php_setup.inc
+ */
+
 /* Basic setup, remove eventually registered sessions */
 require_once("../include/php_setup.inc");
 require_once("functions.inc");
@@ -89,12 +97,15 @@ session::set('_LAST_PAGE_REQUEST', time());
 logging::debug(DEBUG_CONFIG, __LINE__, __FUNCTION__, __FILE__, $config->data, "config");
 
 /* Set template compile directory */
-$smarty->compile_dir = $config->get_cfg_value("templateCompileDirectory", SPOOL_DIR);
+$smarty->setCompileDir($config->get_cfg_value('templateCompileDirectory', SPOOL_DIR));
 
 Language::init();
 
 /* Prepare plugin list */
 pluglist::load();
+/**
+ * @var pluglist $plist built by pluglist::load
+ */
 
 /* Check previous plugin index */
 if (session::is_set('plugin_index')) {
@@ -215,6 +226,9 @@ if (($_SERVER['REQUEST_METHOD'] == 'POST')
 
 /* Load plugin */
 pluglist::runMainInc($plugin_index);
+/**
+ * @var string $display Filled by pluglist::runMainInc
+ */
 
 /* Print_out last ErrorMessage repeated string. */
 $smarty->assign("msg_dialogs", msg_dialog::get_dialogs());
diff --git a/html/secondfactor.php b/html/secondfactor.php
index 5b6f833d6a59800fe4387e19cf0dd6d0244183dd..8d70273c595b69f7a1e152de1dc72d9f654d269e 100644
--- a/html/secondfactor.php
+++ b/html/secondfactor.php
@@ -19,6 +19,14 @@
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 */
 
+/**
+ * @var Smarty $smarty                  Defined in php_setup.inc
+ * @var string $BASE_DIR                Defined in php_setup.inc
+ * @var string $ssl                     Defined in php_setup.inc
+ * @var string $error_collector         Defined in php_setup.inc
+ * @var string $error_collector_mailto  Defined in php_setup.inc
+ */
+
 /* Basic setup, remove eventually registered sessions */
 require_once("../include/php_setup.inc");
 require_once("functions.inc");
@@ -96,7 +104,7 @@ foreach (LoginPost::$secondFactorMethods as $secondFactorMethod) {
 session::set('DEBUGLEVEL', $config->get_cfg_value('DEBUGLEVEL'));
 
 /* Set template compile directory */
-$smarty->compile_dir = $config->get_cfg_value('templateCompileDirectory', SPOOL_DIR);
+$smarty->setCompileDir($config->get_cfg_value('templateCompileDirectory', SPOOL_DIR));
 
 Language::init();
 
diff --git a/html/setup.php b/html/setup.php
index c405c8582a0b8b1aeaf96619fda0653255ddf462..093ba5a36b498cfc0a0f4b97dea189300823e583 100644
--- a/html/setup.php
+++ b/html/setup.php
@@ -41,6 +41,14 @@ header('X-XSS-Protection: 1; mode=block');
 header('X-Content-Type-Options: nosniff');
 header('X-Frame-Options: deny');
 
+/**
+ * @var Smarty $smarty                  Defined in php_setup.inc
+ * @var string $BASE_DIR                Defined in php_setup.inc
+ * @var string $ssl                     Defined in php_setup.inc
+ * @var string $error_collector         Defined in php_setup.inc
+ * @var string $error_collector_mailto  Defined in php_setup.inc
+ */
+
 /* Set cookie lifetime to one day (The parameter is in seconds ) */
 session_set_cookie_params(24 * 60 * 60);
 // default cache_expire is 180
@@ -57,14 +65,14 @@ CSRFProtection::check();
 reset_errors();
 
 /* Set template compile directory */
-$smarty->compile_dir = SPOOL_DIR;
+$smarty->setCompileDir(SPOOL_DIR);
 
 /* Check for compile directory */
-if (!(is_dir($smarty->compile_dir) && is_writable($smarty->compile_dir))) {
+if (!(is_dir($smarty->getCompileDir()) && is_writable($smarty->getCompileDir()))) {
   throw new FatalError(
     htmlescape(sprintf(
       _('Directory "%s" specified as compile directory is not accessible!'),
-      $smarty->compile_dir
+      $smarty->getCompileDir()
     ))
   );
 }
@@ -104,6 +112,9 @@ IconTheme::loadThemes('themes');
 $ui = new userinfoNoAuth('setup');
 /* Call setup */
 setup::mainInc();
+/**
+ * @var string $display filled by setup::mainInc
+ */
 
 $focus = '<script type="text/javascript">';
 $focus .= 'next_msg_dialog();';
diff --git a/include/class_config.inc b/include/class_config.inc
index 41083da99eedea9c1794b408427099d269a49aee..dd70d2bb42ac6932dbeb32e92fb0eb99acd28e92 100644
--- a/include/class_config.inc
+++ b/include/class_config.inc
@@ -361,13 +361,14 @@ class config
       }
       asort($servers);
       reset($servers);
-    }
 
-    /* SERVER not defined? Load the one with the shortest base */
-    if (!isset($this->current['SERVER'])) {
-      $this->current['SERVER'] = key($servers);
+      /* SERVER not defined? Load the one with the shortest base */
+      if (!isset($this->current['SERVER'])) {
+        $this->current['SERVER'] = key($servers);
+      }
     }
 
+
     /* Parse LDAP referral informations */
     if (!isset($this->current['ADMINDN']) || !isset($this->current['ADMINPASSWORD'])) {
       $this->current['BASE']          = $this->current['REFERRAL'][$this->current['SERVER']]['BASE'];
diff --git a/include/class_ldapMultiplexer.inc b/include/class_ldapMultiplexer.inc
index 6cb5c86d3ba7b682c3249400b90b94b9e6d06c42..fc745583ee78a06c2fdcc91cc84c7c8c2c0810c8 100644
--- a/include/class_ldapMultiplexer.inc
+++ b/include/class_ldapMultiplexer.inc
@@ -25,8 +25,18 @@
  * Source code for class ldapMultiplexer
  */
 
- /*!
-  * \brief This class contains all function to manage ldap multiplexer
+ /**
+  * This class contains all function to manage ldap multiplexer
+  * @method void set_size_limit ($size)
+  * @method void cd ($dir)
+  * @method boolean|resource modify_batch (array $changes)
+  * @method string get_error ($details = TRUE)
+  * @method array get_objectclasses ($force_reload = FALSE)
+  * @method string|array fetch (bool $cleanUpNumericIndices = FALSE)
+  * @method string|resource search ($filter, $attrs = [], $scope = 'subtree', array $controls = NULL)
+  * @method string|resource cat ($dn, $attrs = ["*"], $filter = "(objectclass=*)")
+  * @method int count ()
+  * @method bool success ()
   */
 class ldapMultiplexer
 {
diff --git a/include/class_pluglist.inc b/include/class_pluglist.inc
index 78d652011fa213284b7255f06e3d6480f3273fb2..c87279fcd86ac59bf3b9cad3755dc14f5bd5a34a 100644
--- a/include/class_pluglist.inc
+++ b/include/class_pluglist.inc
@@ -572,7 +572,7 @@ class pluglist
       if (is_file("$plugin_dir/main.inc")) {
         $display = '';
         require("$plugin_dir/main.inc");
-      } elseif (is_callable([$plugin, 'mainInc'])) {
+      } elseif (is_callable([get_class($plugin), 'mainInc'])) {
         $plugin::mainInc();
       } else {
         throw new FatalError(
diff --git a/include/functions.inc b/include/functions.inc
index 5646e059132e60cef9353a276c450576f49bd889..64388aaa91be975d3f6d01e41dd82c9bb77f9bc4 100644
--- a/include/functions.inc
+++ b/include/functions.inc
@@ -32,27 +32,6 @@ require_once(CACHE_DIR.'/'.CLASS_CACHE);
 require_once('functions_debug.inc');
 require_once('accept-to-gettext.inc');
 
-/* Define constants for debugging */
-define('DEBUG_TRACE',    1); /*! Debug level for tracing of common actions (save, check, etc.) */
-define('DEBUG_LDAP',     2); /*! Debug level for LDAP queries */
-define('DEBUG_DB',       4); /*! Debug level for database operations */
-define('DEBUG_SHELL',    8); /*! Debug level for shell commands */
-define('DEBUG_POST',     16); /*! Debug level for POST content */
-define('DEBUG_SESSION',  32); /*! Debug level for SESSION content */
-define('DEBUG_CONFIG',   64); /*! Debug level for CONFIG information */
-define('DEBUG_ACL',      128); /*! Debug level for ACL infos */
-define('DEBUG_SI',       256); /*! Debug level for communication with Argonaut */
-define('DEBUG_MAIL',     512); /*! Debug level for all about mail (mailAccounts, imap, sieve etc.) */
-define('DEBUG_FAI',      1024); /* FAI (incomplete) */
-
-/* Define constants for LDAP operations */
-define('LDAP_READ',   1);
-define('LDAP_ADD',    2);
-define('LDAP_MOD',    3);
-define('LDAP_DEL',    4);
-define('LDAP_SEARCH', 5);
-define('LDAP_AUTH',   6);
-
 /*!
  * \brief Does autoloading for classes used in FusionDirectory.
  *
diff --git a/include/management/class_management.inc b/include/management/class_management.inc
index a0b3b0f8d322a3280be2dd611a2f00de3b195a2a..0e62eb456e7ebba03db60ce24cf2c605ec89d996 100644
--- a/include/management/class_management.inc
+++ b/include/management/class_management.inc
@@ -50,6 +50,9 @@ class management implements FusionDirectoryDialog
   protected $previousDns  = [];
 
   // The opened object.
+  /**
+   * @var ?simpleTabs
+   */
   protected $tabObject    = NULL;
   protected $dialogObject = NULL;
 
diff --git a/include/php_setup.inc b/include/php_setup.inc
index 6e0ad8434e12ffffde81124c73c14d1e320fae06..1fb24c02736249f9fc1889a37fbbfa32a103040a 100644
--- a/include/php_setup.inc
+++ b/include/php_setup.inc
@@ -351,8 +351,8 @@ require(SMARTY);
 
 $smarty = new Smarty;
 
-$smarty->template_dir = $BASE_DIR.'/ihtml/';
-$smarty->caching      = FALSE;
+$smarty->setTemplateDir($BASE_DIR.'/ihtml/');
+$smarty->caching      = Smarty::CACHING_OFF;
 $smarty->assign('css_files', []);
 $smarty->assign('js_files', []);
 
diff --git a/include/simpleplugin/interface_SimpleTab.inc b/include/simpleplugin/interface_SimpleTab.inc
index 404fe925cc7f440d9e88e7cd0c2c52e384dde6e8..456636f0d7f51db4f26fb038aa507402d7a04868 100644
--- a/include/simpleplugin/interface_SimpleTab.inc
+++ b/include/simpleplugin/interface_SimpleTab.inc
@@ -27,18 +27,16 @@
 /*! \brief This interface is implemented by classes intended to be used as tabs, mainly simplePlugin itself.
  */
 
+/**
+ * @property bool $is_account
+ * @property string $dn
+ * @property bool $is_template
+ * @property string $_template_cn (only for main tab of templates)
+ * @property array $attributesAccess (only for main tab of templates)
+ * @property simpleTabs $parent
+ */
 interface SimpleTab extends FusionDirectoryDialog
 {
-  /*
-   * Public vars expected as well by classes implementing this interface:
-   * bool $is_account
-   * string $dn
-   * bool $is_template
-   * string $_template_cn (only for main tab of templates)
-   * array $attributesAccess (only for main tab of templates)
-   * simpleTabs $parent
-   */
-
   /*
    * Public methods needed in some cases:
    * compute_dn (): string (only for main tab)
diff --git a/include/variables_common.inc b/include/variables_common.inc
index f79605da8624944e9e09a00d7b589c7370fd02d9..3621e95267b1155552c7cb7078f03709016a87bc 100644
--- a/include/variables_common.inc
+++ b/include/variables_common.inc
@@ -79,3 +79,24 @@ define('PHP_MIN_VERSION', '7.0.0');
  * \brief Toggle crashing on PHP error, used for test suites
  */
 define('PHP_ERROR_FATAL', 'FALSE');
+
+/* Define constants for debugging */
+define('DEBUG_TRACE',    1); /*! Debug level for tracing of common actions (save, check, etc.) */
+define('DEBUG_LDAP',     2); /*! Debug level for LDAP queries */
+define('DEBUG_DB',       4); /*! Debug level for database operations */
+define('DEBUG_SHELL',    8); /*! Debug level for shell commands */
+define('DEBUG_POST',     16); /*! Debug level for POST content */
+define('DEBUG_SESSION',  32); /*! Debug level for SESSION content */
+define('DEBUG_CONFIG',   64); /*! Debug level for CONFIG information */
+define('DEBUG_ACL',      128); /*! Debug level for ACL infos */
+define('DEBUG_SI',       256); /*! Debug level for communication with Argonaut */
+define('DEBUG_MAIL',     512); /*! Debug level for all about mail (mailAccounts, imap, sieve etc.) */
+define('DEBUG_FAI',      1024); /* FAI (incomplete) */
+
+/* Define constants for LDAP operations */
+define('LDAP_READ',   1);
+define('LDAP_ADD',    2);
+define('LDAP_MOD',    3);
+define('LDAP_DEL',    4);
+define('LDAP_SEARCH', 5);
+define('LDAP_AUTH',   6);
diff --git a/phpstan.neon b/phpstan.neon
deleted file mode 100644
index ea0e6fbb9894647eb2a1dd77ce61daeee4a4510d..0000000000000000000000000000000000000000
--- a/phpstan.neon
+++ /dev/null
@@ -1,20 +0,0 @@
-includes:
-  - phpstan-baseline.neon
-
-parameters:
-  bootstrapFiles:
-    - include/php_setup.inc
-    - include/class_msg_dialog.inc
-    - include/class_userinfo.inc
-  scanDirectories:
-    - /usr/share/php
-  fileExtensions:
-    - php
-    - inc
-  universalObjectCratesClasses:
-    - simplePlugin
-  excludes_analyse:
-    - */class_sieve*.inc
-    - */localfiles/*
-    - */vendor/*
-    - */test/*
diff --git a/plugins/generic/welcome/main.inc b/plugins/generic/welcome/main.inc
index 72ca1db7f8a899f9190e702ed2d9f22984728567..26ea89dcaef66eedd7ad687c7602ea659eb59e62 100644
--- a/plugins/generic/welcome/main.inc
+++ b/plugins/generic/welcome/main.inc
@@ -19,6 +19,13 @@
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
 */
 
+/**
+ * @var Smarty $smarty
+ * @var pluglist $plist
+ * @var userinfo $ui
+ * @var bool $cleanup
+ */
+
 if (!$cleanup) {
   $smarty->assign('iconmenu',       $plist->show_iconmenu());
   $smarty->assign('headline',       sprintf(_('Welcome %s!'), $ui->cn));