From e5c0150be4992b1d31322783049255ad7747e276 Mon Sep 17 00:00:00 2001 From: thibdrev Date: Tue, 13 Aug 2024 22:50:31 +0200 Subject: [PATCH] qual: avoid double negations by introducing getDolGlobalBool() (#30618) * Update index.php * Update api.class.php * Update pdf_eratosthene.modules.php * Update pdf_sponge.modules.php * Update pdf_cyan.modules.php * Update partnershiputils.class.php * Update paypalfunctions.lib.php * Update societe.class.php * Update functions.lib.php - create getDolGlobalBool() * Update index.php * Update api.class.php * Update pdf_eratosthene.modules.php * Update pdf_sponge.modules.php * Update pdf_cyan.modules.php * Update partnershiputils.class.php * Update paypalfunctions.lib.php * Update societe.class.php * Update functions.lib.php --------- Co-authored-by: Laurent Destailleur --- htdocs/api/admin/index.php | 4 ++-- htdocs/api/class/api.class.php | 2 +- htdocs/core/lib/functions.lib.php | 22 +++++++++++++++---- .../commande/doc/pdf_eratosthene.modules.php | 2 +- .../facture/doc/pdf_sponge.modules.php | 2 +- .../modules/propale/doc/pdf_cyan.modules.php | 2 +- htdocs/paypal/lib/paypalfunctions.lib.php | 2 +- htdocs/societe/class/societe.class.php | 12 +++++----- 8 files changed, 31 insertions(+), 17 deletions(-) diff --git a/htdocs/api/admin/index.php b/htdocs/api/admin/index.php index 83c20b77116..2ee3bdb6ea4 100644 --- a/htdocs/api/admin/index.php +++ b/htdocs/api/admin/index.php @@ -117,7 +117,7 @@ print ""; print ''; print ''.$langs->trans("ApiProductionMode").''; -$production_mode = !(!getDolGlobalString('API_PRODUCTION_MODE')); +$production_mode = getDolGlobalBool('API_PRODUCTION_MODE'); if ($production_mode) { print ''; print img_picto($langs->trans("Activated"), 'switch_on'); @@ -132,7 +132,7 @@ print ''; print ''; print ''.$langs->trans("API_DISABLE_COMPRESSION").''; -$disable_compression = !(!getDolGlobalString('API_DISABLE_COMPRESSION')); +$disable_compression = getDolGlobalBool('API_DISABLE_COMPRESSION'); if ($disable_compression) { print ''; print img_picto($langs->trans("Activated"), 'switch_on'); diff --git a/htdocs/api/class/api.class.php b/htdocs/api/class/api.class.php index e516ed44ba2..c3c74cd9e69 100644 --- a/htdocs/api/class/api.class.php +++ b/htdocs/api/class/api.class.php @@ -55,7 +55,7 @@ class DolibarrApi Defaults::$cacheDirectory = $cachedir; $this->db = $db; - $production_mode = !(!getDolGlobalString('API_PRODUCTION_MODE')); + $production_mode = getDolGlobalBool('API_PRODUCTION_MODE'); $this->r = new Restler($production_mode, $refreshCache); $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 08207add827..8386268e1d7 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -205,7 +205,7 @@ function getMultidirVersion($object, $module = '', $forobject = 0) /** - * Return dolibarr global constant string value + * Return a Dolibarr global constant string value * * @param string $key Key to return value, return $default if not set * @param string|int|float $default Value to return if not defined @@ -222,9 +222,9 @@ function getDolGlobalString($key, $default = '') * Return a Dolibarr global constant int value. * The constants $conf->global->xxx are loaded by the script master.inc.php included at begin of any PHP page. * - * @param string $key key to return value, return 0 if not set - * @param int $default value to return - * @return int + * @param string $key Key to return value, return $default if not set + * @param int $default Value to return if not defined + * @return int Value returned * @see getDolUserInt() */ function getDolGlobalInt($key, $default = 0) @@ -233,6 +233,20 @@ function getDolGlobalInt($key, $default = 0) return (int) (isset($conf->global->$key) ? $conf->global->$key : $default); } +/** + * Return a Dolibarr global constant boolean value. + * The constants $conf->global->xxx are loaded by the script master.inc.php included at begin of any PHP page. + * + * @param string $key Key to return value, return $default if not set + * @param bool $default Value to return if not defined + * @return bool Value returned + */ +function getDolGlobalBool($key, $default = false) +{ + global $conf; + return (bool) ($conf->global->$key ?? $default); +} + /** * Return Dolibarr user constant string value * diff --git a/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php b/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php index 28f35d2a4be..42ac7d00046 100644 --- a/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php +++ b/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php @@ -1926,7 +1926,7 @@ class pdf_eratosthene extends ModelePDFCommandes $this->cols['totalincltax'] = array( 'rank' => $rank, 'width' => 26, // in mm - 'status' => !(!getDolGlobalString('PDF_ORDER_SHOW_PRICE_INCL_TAX')), + 'status' => getDolGlobalBool('PDF_ORDER_SHOW_PRICE_INCL_TAX'), 'title' => array( 'textkey' => 'TotalTTCShort' ), diff --git a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php index 3183e69484a..13285e9aa25 100644 --- a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php @@ -2708,7 +2708,7 @@ class pdf_sponge extends ModelePDFFactures $this->cols['totalincltax'] = array( 'rank' => $rank, 'width' => 26, // in mm - 'status' => !(!getDolGlobalString('PDF_PROPAL_SHOW_PRICE_INCL_TAX')), + 'status' => getDolGlobalBool('PDF_PROPAL_SHOW_PRICE_INCL_TAX'), 'title' => array( 'textkey' => 'TotalTTCShort' ), diff --git a/htdocs/core/modules/propale/doc/pdf_cyan.modules.php b/htdocs/core/modules/propale/doc/pdf_cyan.modules.php index 9819d3e7c1e..1296c735070 100644 --- a/htdocs/core/modules/propale/doc/pdf_cyan.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_cyan.modules.php @@ -2050,7 +2050,7 @@ class pdf_cyan extends ModelePDFPropales $this->cols['totalincltax'] = array( 'rank' => $rank, 'width' => 26, // in mm - 'status' => !(!getDolGlobalString('PDF_PROPAL_SHOW_PRICE_INCL_TAX')), + 'status' => getDolGlobalBool('PDF_PROPAL_SHOW_PRICE_INCL_TAX'), 'title' => array( 'textkey' => 'TotalTTCShort' ), diff --git a/htdocs/paypal/lib/paypalfunctions.lib.php b/htdocs/paypal/lib/paypalfunctions.lib.php index 36130b3cc67..b3a714489a2 100644 --- a/htdocs/paypal/lib/paypalfunctions.lib.php +++ b/htdocs/paypal/lib/paypalfunctions.lib.php @@ -79,4 +79,4 @@ $PROXY_HOST = getDolGlobalString('MAIN_PROXY_HOST'); $PROXY_PORT = getDolGlobalString('MAIN_PROXY_PORT'); $PROXY_USER = getDolGlobalString('MAIN_PROXY_USER'); $PROXY_PASS = getDolGlobalString('MAIN_PROXY_PASS'); -$USE_PROXY = !(!getDolGlobalString('MAIN_PROXY_USE')); +$USE_PROXY = getDolGlobalBool('MAIN_PROXY_USE'); diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 68a6518c7d3..97054dcf2e7 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -3778,22 +3778,22 @@ class Societe extends CommonObject switch ($idprof) { case 1: - $ret = !(!getDolGlobalString('SOCIETE_IDPROF1_UNIQUE')); + $ret = getDolGlobalBool('SOCIETE_IDPROF1_UNIQUE'); break; case 2: - $ret = !(!getDolGlobalString('SOCIETE_IDPROF2_UNIQUE')); + $ret = getDolGlobalBool('SOCIETE_IDPROF2_UNIQUE'); break; case 3: - $ret = !(!getDolGlobalString('SOCIETE_IDPROF3_UNIQUE')); + $ret = getDolGlobalBool('SOCIETE_IDPROF3_UNIQUE'); break; case 4: - $ret = !(!getDolGlobalString('SOCIETE_IDPROF4_UNIQUE')); + $ret = getDolGlobalBool('SOCIETE_IDPROF4_UNIQUE'); break; case 5: - $ret = !(!getDolGlobalString('SOCIETE_IDPROF5_UNIQUE')); + $ret = getDolGlobalBool('SOCIETE_IDPROF5_UNIQUE'); break; case 6: - $ret = !(!getDolGlobalString('SOCIETE_IDPROF6_UNIQUE')); + $ret = getDolGlobalBool('SOCIETE_IDPROF6_UNIQUE'); break; default: $ret = false;