瀏覽代碼

Several bug fixes using phpstan

Laurent Destailleur 6 年之前
父節點
當前提交
4a69541419

+ 15 - 0
build/phpstan/bootstrap.php

@@ -0,0 +1,15 @@
+<?php
+// Example to use PHPStan
+// cd git/dolibarr
+// /usr/bin/php7.2 ../phpstan.phar -l1 analyze htdocs/societe/website.php --memory-limit 2G
+
+// Defined some constants and load Dolibarr env to reduce PHPStan bootstrap that fails to load a lot of things.
+define('DOL_DOCUMENT_ROOT', __DIR__ . '/../../htdocs');
+define('DOL_DATA_ROOT', __DIR__ . '/../../documents');
+define('DOL_URL_ROOT', '/');
+
+// Load the main.inc.php file to have finctions llx_Header and llx_Footer defined
+if (! defined("NOLOGIN")) define("NOLOGIN",'1');
+global $conf, $langs, $user, $db;
+include_once __DIR__ . '/../../htdocs/main.inc.php';
+

+ 11 - 8
htdocs/core/lib/functions.lib.php

@@ -660,16 +660,19 @@ function dol_buildpath($path, $type = 0, $returnemptyifnotfound = 0)
 	if (empty($type))	// For a filesystem path
 	{
 		$res = DOL_DOCUMENT_ROOT.'/'.$path;		// Standard default path
-		foreach ($conf->file->dol_document_root as $key => $dirroot)	// ex: array("main"=>"/home/main/htdocs", "alt0"=>"/home/dirmod/htdocs", ...)
+		if (is_array($conf->file->dol_document_root))
 		{
-			if ($key == 'main')
-			{
-				continue;
-			}
-			if (file_exists($dirroot.'/'.$path))
+			foreach ($conf->file->dol_document_root as $key => $dirroot)	// ex: array("main"=>"/home/main/htdocs", "alt0"=>"/home/dirmod/htdocs", ...)
 			{
-				$res=$dirroot.'/'.$path;
-				return $res;
+				if ($key == 'main')
+				{
+					continue;
+				}
+				if (file_exists($dirroot.'/'.$path))
+				{
+					$res=$dirroot.'/'.$path;
+					return $res;
+				}
 			}
 		}
 		if ($returnemptyifnotfound)								// Not found into alternate dir

+ 2 - 2
htdocs/main.inc.php

@@ -1152,7 +1152,7 @@ function top_httphead($contenttype = 'text/html', $forcenocache = 0)
 		$contentsecuritypolicy = $conf->global->MAIN_HTTP_CONTENT_SECURITY_POLICY;
 
 		if (! is_object($hookmanager)) $hookmanager = new HookManager($db);
-		$hookmanager->initHooks("main");
+		$hookmanager->initHooks(array("main"));
 
 		$parameters=array('contentsecuritypolicy'=>$contentsecuritypolicy);
 		$result=$hookmanager->executeHooks('setContentSecurityPolicy', $parameters);    // Note that $action and $object may have been modified by some hooks
@@ -1212,7 +1212,7 @@ function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arr
 	if (empty($disablehead))
 	{
 	    if (! is_object($hookmanager)) $hookmanager = new HookManager($db);
-	    $hookmanager->initHooks("main");
+	    $hookmanager->initHooks(array("main"));
 
 	    $ext='layout='.$conf->browser->layout.'&version='.urlencode(DOL_VERSION);
 

+ 1 - 1
htdocs/societe/class/societeaccount.class.php

@@ -20,7 +20,7 @@
  */
 
 /**
- * \file        class/societeaccount.class.php
+ * \file        societe/class/societeaccount.class.php
  * \ingroup     societe
  * \brief       This file is a CRUD class file for SocieteAccount (Create/Read/Update/Delete)
  */

+ 10 - 4
htdocs/societe/website.php

@@ -37,6 +37,12 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
 
 $langs->loadLangs(array("companies","website"));
 
+$action     = GETPOST('action', 'aZ09')?GETPOST('action', 'aZ09'):'view';				// The action 'add', 'create', 'edit', 'update', 'view', ...
+$show_files = GETPOST('show_files', 'int');
+$contextpage= GETPOST('contextpage', 'aZ')?GETPOST('contextpage', 'aZ'):'myobjectlist';   // To manage different context of search
+$backtopage = GETPOST('backtopage', 'alpha');											// Go back to a dedicated page
+$optioncss  = GETPOST('optioncss', 'aZ');												// Option for the css output (always '' except when 'print')
+
 $search_status=GETPOST('search_status');
 
 // Security check
@@ -340,14 +346,14 @@ $objecttmp=new SocieteAccount($db);
 $trackid='thi'.$object->id;
 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
 
-if ($sall)
+/*if ($sall)
 {
 	foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
 	print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall) . join(', ', $fieldstosearchall).'</div>';
-}
+}*/
 
-/*$moreforfilter = '';
-$moreforfilter.='<div class="divsearchfield">';
+$moreforfilter = '';
+/*$moreforfilter.='<div class="divsearchfield">';
 $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
 $moreforfilter.= '</div>';*/
 

+ 31 - 4
phpstan.neon

@@ -1,8 +1,27 @@
 parameters:
-	bootstrap: null
+	bootstrap: %currentWorkingDirectory%/build/phpstan/bootstrap.php
 	excludes_analyse: 
-		- %rootDir%/htdocs/includes/*
-	autoload_directories: []
+		- %currentWorkingDirectory%/htdocs/includes/*
+	autoload_directories:
+		- %currentWorkingDirectory%/htdocs/accountancy/class
+		- %currentWorkingDirectory%/htdocs/adherents/class
+		- %currentWorkingDirectory%/htdocs/api/class
+		- %currentWorkingDirectory%/htdocs/asset/class
+		- %currentWorkingDirectory%/htdocs/blockedlog/class
+		- %currentWorkingDirectory%/htdocs/bom/class
+		- %currentWorkingDirectory%/htdocs/bookmarks/class
+		- %currentWorkingDirectory%/htdocs/cashdesk/class
+		- %currentWorkingDirectory%/htdocs/categories/class
+		- %currentWorkingDirectory%/htdocs/comm/action/class
+		- %currentWorkingDirectory%/htdocs/comm/propal/class
+		- %currentWorkingDirectory%/htdocs/commande/class
+		- %currentWorkingDirectory%/htdocs/compta/bank/class
+		- %currentWorkingDirectory%/htdocs/conf
+		- %currentWorkingDirectory%/htdocs/contact/class
+		- %currentWorkingDirectory%/htdocs/contrat/class
+		- %currentWorkingDirectory%/htdocs/core/class
+		- %currentWorkingDirectory%/htdocs/societe/class
+		- %currentWorkingDirectory%/htdocs/user/class
 	autoload_files: []
 	featureToggles:
 		subtractableTypes: false
@@ -30,7 +49,15 @@ parameters:
 	polluteCatchScopeWithTryAssignments: false
 	reportMagicMethods: false
 	reportMagicProperties: false
-	ignoreErrors: []
+	ignoreErrors:
+		- 
+			message: '#Call to an undefined method abcdef#'
+			path: %currentWorkingDirectory%/dirtoignoreerror/*
+		- '#Undefined variable: \$langs#'
+		- '#Undefined variable: \$user#'
+		- '#Undefined variable: \$db#'
+		- '#Undefined variable: \$conf#'
+		- '#Undefined variable: \$hookmanager#'
 	internalErrorsCountLimit: 50
 	cache:
 	    nodesByFileCountMax: 512