浏览代码

Clean code

Laurent Destailleur 3 年之前
父节点
当前提交
d6852c31b8

+ 3 - 2
ChangeLog

@@ -21,11 +21,12 @@ For developers:
 ---------------
 
 NEW: 
+
+
  
 Following changes may create regressions for some external modules, but were necessary to make Dolibarr better:
 * verifCond('stringtoevaluate') now return false when string contains a bad syntax content instead of true. 
-
-
+* The deprecated mdethod thirdparty_doc_create() has been removed. You can use the generateDocument() instead.
 
 
 

+ 8 - 10
htdocs/core/modules/product/modules_product.class.php

@@ -43,20 +43,18 @@ abstract class ModelePDFProduct extends CommonDocGenerator
 	/**
 	 *  Return list of active generation modules
 	 *
-	 *  @param	DoliDB	$db     			Database handler
+	 *  @param	DoliDB	$dbs     			Database handler
 	 *  @param  integer	$maxfilenamelength  Max length of value to show
 	 *  @return	array						List of templates
 	 */
-	public static function liste_modeles($db, $maxfilenamelength = 0)
+	public static function liste_modeles($dbs, $maxfilenamelength = 0)
 	{
 		// phpcs:enable
-		global $conf;
-
 		$type = 'product';
 		$list = array();
 
 		include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
-		$list = getListOfModels($db, $type, $maxfilenamelength);
+		$list = getListOfModels($dbs, $type, $maxfilenamelength);
 		return $list;
 	}
 }
@@ -156,22 +154,22 @@ abstract class ModeleProductCode
 	/**
 	 *  Renvoi la liste des modeles de numérotation
 	 *
-	 *  @param	DoliDB	$db     			Database handler
+	 *  @param	DoliDB	$dbs     			Database handler
 	 *  @param  integer	$maxfilenamelength  Max length of value to show
 	 *  @return	array						List of numbers
 	 */
-	public static function liste_modeles($db, $maxfilenamelength = 0)
+	public static function liste_modeles($dbs, $maxfilenamelength = 0)
 	{
 		// phpcs:enable
 		$list = array();
 		$sql = "";
 
-		$resql = $db->query($sql);
+		$resql = $dbs->query($sql);
 		if ($resql) {
-			$num = $db->num_rows($resql);
+			$num = $dbs->num_rows($resql);
 			$i = 0;
 			while ($i < $num) {
-				$row = $db->fetch_row($resql);
+				$row = $dbs->fetch_row($resql);
 				$list[$row[0]] = $row[1];
 				$i++;
 			}

+ 8 - 32
htdocs/core/modules/societe/modules_societe.class.php

@@ -41,20 +41,19 @@ abstract class ModeleThirdPartyDoc extends CommonDocGenerator
 	/**
 	 *  Return list of active generation modules
 	 *
-	 * 	@param	DoliDB		$db					Database handler
+	 * 	@param	DoliDB		$dbs				Database handler
 	 *  @param	integer		$maxfilenamelength  Max length of value to show
 	 * 	@return	array							List of templates
 	 */
-	public static function liste_modeles($db, $maxfilenamelength = 0)
+	public static function liste_modeles($dbs, $maxfilenamelength = 0)
 	{
 		// phpcs:enable
-		global $conf;
 
 		$type = 'company';
 		$list = array();
 
 		include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
-		$list = getListOfModels($db, $type, $maxfilenamelength);
+		$list = getListOfModels($dbs, $type, $maxfilenamelength);
 
 		return $list;
 	}
@@ -161,22 +160,22 @@ abstract class ModeleThirdPartyCode
 	/**
 	 *  Renvoie la liste des modeles de numérotation
 	 *
-	 *  @param	DoliDB	$db     			Database handler
+	 *  @param	DoliDB	$dbs     			Database handler
 	 *  @param  integer	$maxfilenamelength  Max length of value to show
 	 *  @return	array|int					List of numbers
 	 */
-	public static function liste_modeles($db, $maxfilenamelength = 0)
+	public static function liste_modeles($dbs, $maxfilenamelength = 0)
 	{
 		// phpcs:enable
 		$list = array();
 		$sql = "";
 
-		$resql = $db->query($sql);
+		$resql = $dbs->query($sql);
 		if ($resql) {
-			$num = $db->num_rows($resql);
+			$num = $dbs->num_rows($resql);
 			$i = 0;
 			while ($i < $num) {
-				$row = $db->fetch_row($resql);
+				$row = $dbs->fetch_row($resql);
 				$list[$row[0]] = $row[1];
 				$i++;
 			}
@@ -401,26 +400,3 @@ abstract class ModeleAccountancyCode
 		return $langs->trans("NotAvailable");
 	}
 }
-
-
-/**
- *  Create a document onto disk according to template module.
- *
- *	@param	DoliDB		$db  			Database handler
- *	@param  Facture		$object			Object invoice
- *  @param  string      $message        Message (not used, deprecated)
- *	@param	string		$modele			Force template to use ('' to not force)
- *	@param	Translate	$outputlangs	objet lang a utiliser pour traduction
- *  @param  int			$hidedetails    Hide details of lines
- *  @param  int			$hidedesc       Hide description
- *  @param  int			$hideref        Hide ref
- *	@return int        					<0 if KO, >0 if OK
- *  @deprecated Use the new function generateDocument of Objects class
- *  @see Societe::generateDocument()
- */
-function thirdparty_doc_create(DoliDB $db, Societe $object, $message, $modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0)
-{
-	dol_syslog(__METHOD__." is deprecated", LOG_WARNING);
-
-	return $object->generateDocument($modele, $outputlangs, $hidedetails, $hidedesc, $hideref);
-}

+ 14 - 14
htdocs/multicurrency/class/multicurrency.class.php

@@ -493,20 +493,20 @@ class MultiCurrency extends CommonObject
 	 /**
 	  * Get id of currency from code
 	  *
-	  * @param  DoliDB	$db		    object db
+	  * @param  DoliDB	$dbs	    object db
 	  * @param  string	$code	    code value search
 	  *
 	  * @return int                 0 if not found, >0 if OK
 	  */
-	public static function getIdFromCode($db, $code)
+	public static function getIdFromCode($dbs, $code)
 	{
 		global $conf;
 
-		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."multicurrency WHERE code = '".$db->escape($code)."' AND entity = ".$conf->entity;
+		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."multicurrency WHERE code = '".$dbs->escape($code)."' AND entity = ".((int) $conf->entity);
 
 		dol_syslog(__METHOD__, LOG_DEBUG);
-		$resql = $db->query($sql);
-		if ($resql && $obj = $db->fetch_object($resql)) {
+		$resql = $dbs->query($sql);
+		if ($resql && $obj = $dbs->fetch_object($resql)) {
 			return $obj->rowid;
 		} else {
 			return 0;
@@ -516,38 +516,38 @@ class MultiCurrency extends CommonObject
 	 /**
 	  * Get id and rate of currency from code
 	  *
-	  * @param DoliDB	$db		        Object db
+	  * @param DoliDB	$dbs	        Object db
 	  * @param string	$code	        Code value search
 	  * @param integer	$date_document	Date from document (propal, order, invoice, ...)
 	  *
 	  * @return 	array	[0] => id currency
 	  *						[1] => rate
 	  */
-	public static function getIdAndTxFromCode($db, $code, $date_document = '')
+	public static function getIdAndTxFromCode($dbs, $code, $date_document = '')
 	{
 		global $conf;
 
 		$sql1 = "SELECT m.rowid, mc.rate FROM ".MAIN_DB_PREFIX."multicurrency m";
 
 		$sql1 .= ' LEFT JOIN '.MAIN_DB_PREFIX.'multicurrency_rate mc ON (m.rowid = mc.fk_multicurrency)';
-		$sql1 .= " WHERE m.code = '".$db->escape($code)."'";
+		$sql1 .= " WHERE m.code = '".$dbs->escape($code)."'";
 		$sql1 .= " AND m.entity IN (".getEntity('multicurrency').")";
 		$sql2 = '';
 		if (!empty($conf->global->MULTICURRENCY_USE_RATE_ON_DOCUMENT_DATE) && !empty($date_document)) {	// Use last known rate compared to document date
 			$tmparray = dol_getdate($date_document);
-			$sql2 .= " AND mc.date_sync <= '".$db->idate(dol_mktime(23, 59, 59, $tmparray['mon'], $tmparray['mday'], $tmparray['year'], true))."'";
+			$sql2 .= " AND mc.date_sync <= '".$dbs->idate(dol_mktime(23, 59, 59, $tmparray['mon'], $tmparray['mday'], $tmparray['year'], true))."'";
 		}
 		$sql3 = " ORDER BY mc.date_sync DESC LIMIT 1";
 
 		dol_syslog(__METHOD__, LOG_DEBUG);
-		$resql = $db->query($sql1.$sql2.$sql3);
+		$resql = $dbs->query($sql1.$sql2.$sql3);
 
-		if ($resql && $obj = $db->fetch_object($resql)) {
+		if ($resql && $obj = $dbs->fetch_object($resql)) {
 			return array($obj->rowid, $obj->rate);
 		} else {
 			if (!empty($conf->global->MULTICURRENCY_USE_RATE_ON_DOCUMENT_DATE)) {
-				$resql = $db->query($sql1.$sql3);
-				if ($resql && $obj = $db->fetch_object($resql)) {
+				$resql = $dbs->query($sql1.$sql3);
+				if ($resql && $obj = $dbs->fetch_object($resql)) {
 					return array($obj->rowid, $obj->rate);
 				}
 			}
@@ -746,7 +746,7 @@ class CurrencyRate extends CommonObjectLine
 	 */
 	public function __construct(DoliDB $db)
 	{
-		$this->db = &$db;
+		$this->db = $db;
 
 		return 1;
 	}

+ 0 - 3
test/phpunit/CodingPhpTest.php

@@ -207,11 +207,8 @@ class CodingPhpTest extends PHPUnit\Framework\TestCase
 					'html.formmail.class.php',
 					'translate.class.php',
 					'utils.class.php',
-					'modules_product.class.php',
-					'modules_societe.class.php',
 					'TraceableDB.php',
 					'multicurrency.class.php',
-					'reception.class.php',
 					'infobox.class.php'
 				))) {
 					// Must not find $db->