Clean code
This commit is contained in:
parent
6e298a2cb4
commit
d6852c31b8
@ -22,10 +22,11 @@ For developers:
|
|||||||
|
|
||||||
NEW:
|
NEW:
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Following changes may create regressions for some external modules, but were necessary to make Dolibarr better:
|
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.
|
* 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.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -43,20 +43,18 @@ abstract class ModelePDFProduct extends CommonDocGenerator
|
|||||||
/**
|
/**
|
||||||
* Return list of active generation modules
|
* 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
|
* @param integer $maxfilenamelength Max length of value to show
|
||||||
* @return array List of templates
|
* @return array List of templates
|
||||||
*/
|
*/
|
||||||
public static function liste_modeles($db, $maxfilenamelength = 0)
|
public static function liste_modeles($dbs, $maxfilenamelength = 0)
|
||||||
{
|
{
|
||||||
// phpcs:enable
|
// phpcs:enable
|
||||||
global $conf;
|
|
||||||
|
|
||||||
$type = 'product';
|
$type = 'product';
|
||||||
$list = array();
|
$list = array();
|
||||||
|
|
||||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
|
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
|
||||||
$list = getListOfModels($db, $type, $maxfilenamelength);
|
$list = getListOfModels($dbs, $type, $maxfilenamelength);
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -156,22 +154,22 @@ abstract class ModeleProductCode
|
|||||||
/**
|
/**
|
||||||
* Renvoi la liste des modeles de numérotation
|
* 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
|
* @param integer $maxfilenamelength Max length of value to show
|
||||||
* @return array List of numbers
|
* @return array List of numbers
|
||||||
*/
|
*/
|
||||||
public static function liste_modeles($db, $maxfilenamelength = 0)
|
public static function liste_modeles($dbs, $maxfilenamelength = 0)
|
||||||
{
|
{
|
||||||
// phpcs:enable
|
// phpcs:enable
|
||||||
$list = array();
|
$list = array();
|
||||||
$sql = "";
|
$sql = "";
|
||||||
|
|
||||||
$resql = $db->query($sql);
|
$resql = $dbs->query($sql);
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
$num = $db->num_rows($resql);
|
$num = $dbs->num_rows($resql);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
while ($i < $num) {
|
while ($i < $num) {
|
||||||
$row = $db->fetch_row($resql);
|
$row = $dbs->fetch_row($resql);
|
||||||
$list[$row[0]] = $row[1];
|
$list[$row[0]] = $row[1];
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -41,20 +41,19 @@ abstract class ModeleThirdPartyDoc extends CommonDocGenerator
|
|||||||
/**
|
/**
|
||||||
* Return list of active generation modules
|
* 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
|
* @param integer $maxfilenamelength Max length of value to show
|
||||||
* @return array List of templates
|
* @return array List of templates
|
||||||
*/
|
*/
|
||||||
public static function liste_modeles($db, $maxfilenamelength = 0)
|
public static function liste_modeles($dbs, $maxfilenamelength = 0)
|
||||||
{
|
{
|
||||||
// phpcs:enable
|
// phpcs:enable
|
||||||
global $conf;
|
|
||||||
|
|
||||||
$type = 'company';
|
$type = 'company';
|
||||||
$list = array();
|
$list = array();
|
||||||
|
|
||||||
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
|
include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
|
||||||
$list = getListOfModels($db, $type, $maxfilenamelength);
|
$list = getListOfModels($dbs, $type, $maxfilenamelength);
|
||||||
|
|
||||||
return $list;
|
return $list;
|
||||||
}
|
}
|
||||||
@ -161,22 +160,22 @@ abstract class ModeleThirdPartyCode
|
|||||||
/**
|
/**
|
||||||
* Renvoie la liste des modeles de numérotation
|
* 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
|
* @param integer $maxfilenamelength Max length of value to show
|
||||||
* @return array|int List of numbers
|
* @return array|int List of numbers
|
||||||
*/
|
*/
|
||||||
public static function liste_modeles($db, $maxfilenamelength = 0)
|
public static function liste_modeles($dbs, $maxfilenamelength = 0)
|
||||||
{
|
{
|
||||||
// phpcs:enable
|
// phpcs:enable
|
||||||
$list = array();
|
$list = array();
|
||||||
$sql = "";
|
$sql = "";
|
||||||
|
|
||||||
$resql = $db->query($sql);
|
$resql = $dbs->query($sql);
|
||||||
if ($resql) {
|
if ($resql) {
|
||||||
$num = $db->num_rows($resql);
|
$num = $dbs->num_rows($resql);
|
||||||
$i = 0;
|
$i = 0;
|
||||||
while ($i < $num) {
|
while ($i < $num) {
|
||||||
$row = $db->fetch_row($resql);
|
$row = $dbs->fetch_row($resql);
|
||||||
$list[$row[0]] = $row[1];
|
$list[$row[0]] = $row[1];
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
@ -401,26 +400,3 @@ abstract class ModeleAccountancyCode
|
|||||||
return $langs->trans("NotAvailable");
|
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);
|
|
||||||
}
|
|
||||||
|
|||||||
@ -493,20 +493,20 @@ class MultiCurrency extends CommonObject
|
|||||||
/**
|
/**
|
||||||
* Get id of currency from code
|
* Get id of currency from code
|
||||||
*
|
*
|
||||||
* @param DoliDB $db object db
|
* @param DoliDB $dbs object db
|
||||||
* @param string $code code value search
|
* @param string $code code value search
|
||||||
*
|
*
|
||||||
* @return int 0 if not found, >0 if OK
|
* @return int 0 if not found, >0 if OK
|
||||||
*/
|
*/
|
||||||
public static function getIdFromCode($db, $code)
|
public static function getIdFromCode($dbs, $code)
|
||||||
{
|
{
|
||||||
global $conf;
|
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);
|
dol_syslog(__METHOD__, LOG_DEBUG);
|
||||||
$resql = $db->query($sql);
|
$resql = $dbs->query($sql);
|
||||||
if ($resql && $obj = $db->fetch_object($resql)) {
|
if ($resql && $obj = $dbs->fetch_object($resql)) {
|
||||||
return $obj->rowid;
|
return $obj->rowid;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
@ -516,38 +516,38 @@ class MultiCurrency extends CommonObject
|
|||||||
/**
|
/**
|
||||||
* Get id and rate of currency from code
|
* 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 string $code Code value search
|
||||||
* @param integer $date_document Date from document (propal, order, invoice, ...)
|
* @param integer $date_document Date from document (propal, order, invoice, ...)
|
||||||
*
|
*
|
||||||
* @return array [0] => id currency
|
* @return array [0] => id currency
|
||||||
* [1] => rate
|
* [1] => rate
|
||||||
*/
|
*/
|
||||||
public static function getIdAndTxFromCode($db, $code, $date_document = '')
|
public static function getIdAndTxFromCode($dbs, $code, $date_document = '')
|
||||||
{
|
{
|
||||||
global $conf;
|
global $conf;
|
||||||
|
|
||||||
$sql1 = "SELECT m.rowid, mc.rate FROM ".MAIN_DB_PREFIX."multicurrency m";
|
$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 .= ' 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').")";
|
$sql1 .= " AND m.entity IN (".getEntity('multicurrency').")";
|
||||||
$sql2 = '';
|
$sql2 = '';
|
||||||
if (!empty($conf->global->MULTICURRENCY_USE_RATE_ON_DOCUMENT_DATE) && !empty($date_document)) { // Use last known rate compared to document date
|
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);
|
$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";
|
$sql3 = " ORDER BY mc.date_sync DESC LIMIT 1";
|
||||||
|
|
||||||
dol_syslog(__METHOD__, LOG_DEBUG);
|
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);
|
return array($obj->rowid, $obj->rate);
|
||||||
} else {
|
} else {
|
||||||
if (!empty($conf->global->MULTICURRENCY_USE_RATE_ON_DOCUMENT_DATE)) {
|
if (!empty($conf->global->MULTICURRENCY_USE_RATE_ON_DOCUMENT_DATE)) {
|
||||||
$resql = $db->query($sql1.$sql3);
|
$resql = $dbs->query($sql1.$sql3);
|
||||||
if ($resql && $obj = $db->fetch_object($resql)) {
|
if ($resql && $obj = $dbs->fetch_object($resql)) {
|
||||||
return array($obj->rowid, $obj->rate);
|
return array($obj->rowid, $obj->rate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -746,7 +746,7 @@ class CurrencyRate extends CommonObjectLine
|
|||||||
*/
|
*/
|
||||||
public function __construct(DoliDB $db)
|
public function __construct(DoliDB $db)
|
||||||
{
|
{
|
||||||
$this->db = &$db;
|
$this->db = $db;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -207,11 +207,8 @@ class CodingPhpTest extends PHPUnit\Framework\TestCase
|
|||||||
'html.formmail.class.php',
|
'html.formmail.class.php',
|
||||||
'translate.class.php',
|
'translate.class.php',
|
||||||
'utils.class.php',
|
'utils.class.php',
|
||||||
'modules_product.class.php',
|
|
||||||
'modules_societe.class.php',
|
|
||||||
'TraceableDB.php',
|
'TraceableDB.php',
|
||||||
'multicurrency.class.php',
|
'multicurrency.class.php',
|
||||||
'reception.class.php',
|
|
||||||
'infobox.class.php'
|
'infobox.class.php'
|
||||||
))) {
|
))) {
|
||||||
// Must not find $db->
|
// Must not find $db->
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user