From ccaae7ab247f9341287f46b51f59cffad9a61074 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 5 Jan 2024 03:41:22 +0100 Subject: [PATCH] Clean code --- .../rector/src/Renaming/GlobalToFunction.php | 4 +-- htdocs/admin/agenda_extsites.php | 2 +- htdocs/admin/compta.php | 2 +- htdocs/admin/contract.php | 2 +- htdocs/admin/system/dolibarr.php | 2 +- htdocs/core/class/translate.class.php | 4 +-- htdocs/core/lib/functions.lib.php | 2 +- htdocs/core/lib/memory.lib.php | 4 +-- htdocs/datapolicy/admin/setup.php | 2 +- htdocs/datapolicy/admin/setupmail.php | 2 +- htdocs/datapolicy/class/datapolicy.class.php | 24 ++++++------- htdocs/dav/dav.lib.php | 4 +-- .../class/DataCollector/DolibarrCollector.php | 2 +- .../class/conferenceorboothattendee.class.php | 35 ++----------------- htdocs/externalsite/frames.php | 4 +-- htdocs/fichinter/agenda.php | 1 - .../class/fournisseur.commande.class.php | 2 +- htdocs/fourn/commande/card.php | 2 +- htdocs/fourn/facture/card.php | 4 +-- htdocs/fourn/facture/index.php | 4 +-- htdocs/hrm/class/evaluation.class.php | 2 +- htdocs/hrm/class/evaluationdet.class.php | 2 +- htdocs/hrm/class/job.class.php | 2 +- htdocs/hrm/class/position.class.php | 2 +- htdocs/hrm/class/skill.class.php | 2 +- htdocs/hrm/class/skilldet.class.php | 2 +- htdocs/hrm/class/skillrank.class.php | 2 +- htdocs/index.php | 9 ++--- htdocs/main.inc.php | 8 ++--- htdocs/master.inc.php | 4 +-- 30 files changed, 53 insertions(+), 90 deletions(-) diff --git a/dev/tools/rector/src/Renaming/GlobalToFunction.php b/dev/tools/rector/src/Renaming/GlobalToFunction.php index ea5b2718f8c..e5515f336aa 100644 --- a/dev/tools/rector/src/Renaming/GlobalToFunction.php +++ b/dev/tools/rector/src/Renaming/GlobalToFunction.php @@ -123,7 +123,7 @@ class GlobalToFunction extends AbstractRector if ($node instanceof FuncCall) { $tmpfunctionname = $this->getName($node); // If function is ok. We must avoid a lot of cases like isset(), empty() - if (in_array($tmpfunctionname, array('dol_escape_htmltag', 'dol_hash', 'make_substitutions', 'min', 'max', 'explode'))) { + if (in_array($tmpfunctionname, array('dol_escape_htmltag', 'dol_hash', 'explode', 'length_accountg', 'length_accounta', 'make_substitutions', 'min', 'max', 'trunc', 'urlencode', 'yn'))) { //print "tmpfunctionname=".$tmpfunctionname."\n"; $args = $node->getArgs(); $nbofparam = count($args); @@ -153,7 +153,7 @@ class GlobalToFunction extends AbstractRector if ($node instanceof MethodCall) { $tmpmethodname = $this->getName($node->name); // If function is ok. We must avoid a lot of cases - if (in_array($tmpmethodname, array('idate'))) { + if (in_array($tmpmethodname, array('idate', 'sanitize', 'select_language'))) { //print "tmpmethodname=".$tmpmethodname."\n"; $expr = $node->var; $args = $node->getArgs(); diff --git a/htdocs/admin/agenda_extsites.php b/htdocs/admin/agenda_extsites.php index 1abdeab9733..c63c2124751 100644 --- a/htdocs/admin/agenda_extsites.php +++ b/htdocs/admin/agenda_extsites.php @@ -161,7 +161,7 @@ if (preg_match('/set_(.*)/', $action, $reg)) { if (!getDolGlobalString('AGENDA_EXT_NB')) { $conf->global->AGENDA_EXT_NB = 5; } - $MAXAGENDA = !getDolGlobalString('AGENDA_EXT_NB') ? 5 : $conf->global->AGENDA_EXT_NB; + $MAXAGENDA = getDolGlobalInt('AGENDA_EXT_NB', 5); } if (!$error) { diff --git a/htdocs/admin/compta.php b/htdocs/admin/compta.php index a8b6f7bb04b..36a635b0fd3 100644 --- a/htdocs/admin/compta.php +++ b/htdocs/admin/compta.php @@ -56,7 +56,7 @@ $list = array( * Actions */ -$accounting_mode = !getDolGlobalString('ACCOUNTING_MODE') ? 'RECETTES-DEPENSES' : $conf->global->ACCOUNTING_MODE; +$accounting_mode = getDolGlobalString('ACCOUNTING_MODE', 'RECETTES-DEPENSES'); if ($action == 'update') { $error = 0; diff --git a/htdocs/admin/contract.php b/htdocs/admin/contract.php index c3970014a4e..36b98d52059 100644 --- a/htdocs/admin/contract.php +++ b/htdocs/admin/contract.php @@ -512,7 +512,7 @@ print ''."\n"; print ''; print ''.$langs->trans("HideClosedServiceByDefault").''; print ''; -print $form->selectyesno("activate_hideClosedServiceByDefault", (getDolGlobalString('CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT') ? $conf->global->CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT : 0), 1); +print $form->selectyesno("activate_hideClosedServiceByDefault", getDolGlobalInt('CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT', 0), 1); print ''; print ''; diff --git a/htdocs/admin/system/dolibarr.php b/htdocs/admin/system/dolibarr.php index c7f07ad0040..e804bd1c871 100644 --- a/htdocs/admin/system/dolibarr.php +++ b/htdocs/admin/system/dolibarr.php @@ -194,7 +194,7 @@ print '
'; // Shmop -if (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) { +if (getDolGlobalInt('MAIN_OPTIMIZE_SPEED') & 0x02) { $shmoparray = dol_listshmop(); print '
'; diff --git a/htdocs/core/class/translate.class.php b/htdocs/core/class/translate.class.php index c5388f367b1..c5ce86c4e8c 100644 --- a/htdocs/core/class/translate.class.php +++ b/htdocs/core/class/translate.class.php @@ -281,7 +281,7 @@ class Translate // Using a memcached server if (isModEnabled('memcached') && getDolGlobalString('MEMCACHED_SERVER')) { $usecachekey = $newdomain . '_' . $langofdir . '_' . md5($file_lang); // Should not contains special chars - } elseif (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) { + } elseif (getDolGlobalInt('MAIN_OPTIMIZE_SPEED') & 0x02) { // Using cache with shmop. Speed gain: 40ms - Memory overusage: 200ko (Size of session cache file) $usecachekey = $newdomain; } @@ -473,7 +473,7 @@ class Translate // Using a memcached server if (isModEnabled('memcached') && getDolGlobalString('MEMCACHED_SERVER')) { $usecachekey = $newdomain . '_' . $langofdir; // Should not contains special chars - } elseif (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) { + } elseif (getDolGlobalInt('MAIN_OPTIMIZE_SPEED') & 0x02) { // Using cache with shmop. Speed gain: 40ms - Memory overusage: 200ko (Size of session cache file) $usecachekey = $newdomain; } diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index b706c895368..afcf18ceebd 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -10349,7 +10349,7 @@ function printCommonFooter($zone = 'private') if (getDolGlobalString('MEMCACHED_SERVER')) { print 'MEMCACHED_SERVER=' . getDolGlobalString('MEMCACHED_SERVER').' - '; } - print 'MAIN_OPTIMIZE_SPEED='.(isset($conf->global->MAIN_OPTIMIZE_SPEED) ? $conf->global->MAIN_OPTIMIZE_SPEED : 'off'); + print 'MAIN_OPTIMIZE_SPEED=' . getDolGlobalString('MAIN_OPTIMIZE_SPEED', 'off'); if (!empty($micro_start_time)) { // Works only if MAIN_SHOW_TUNING_INFO is defined at $_SERVER level. Not in global variable. $micro_end_time = microtime(true); print ' - Build time: '.ceil(1000 * ($micro_end_time - $micro_start_time)).' ms'; diff --git a/htdocs/core/lib/memory.lib.php b/htdocs/core/lib/memory.lib.php index c4d7ddac7e9..54b3bdeffd3 100644 --- a/htdocs/core/lib/memory.lib.php +++ b/htdocs/core/lib/memory.lib.php @@ -118,7 +118,7 @@ function dol_setcache($memoryid, $data, $expire = 0) } else { return -1; } - } elseif (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) { // This is a really not reliable cache ! Use Memcached instead. + } elseif (getDolGlobalInt('MAIN_OPTIMIZE_SPEED') & 0x02) { // This is a really not reliable cache ! Use Memcached instead. // Using shmop $result = dol_setshmop($memoryid, $data, $expire); } else { @@ -194,7 +194,7 @@ function dol_getcache($memoryid) } else { return null; // There is no way to make a difference between NOTFOUND and error when using Memcache. So do not use it, use Memcached instead. } - } elseif (isset($conf->global->MAIN_OPTIMIZE_SPEED) && ($conf->global->MAIN_OPTIMIZE_SPEED & 0x02)) { // This is a really not reliable cache ! Use Memcached instead. + } elseif (getDolGlobalInt('MAIN_OPTIMIZE_SPEED') & 0x02) { // This is a really not reliable cache ! Use Memcached instead. // Using shmop $data = dol_getshmop($memoryid); return $data; diff --git a/htdocs/datapolicy/admin/setup.php b/htdocs/datapolicy/admin/setup.php index fe4b0632781..e094f9ac53a 100644 --- a/htdocs/datapolicy/admin/setup.php +++ b/htdocs/datapolicy/admin/setup.php @@ -145,7 +145,7 @@ if ($action == 'edit') { print ''; print '