From fc732b1be5f479ed55ee4e3fff238b4d4ff220ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20France?= Date: Tue, 12 Mar 2024 18:49:29 +0100 Subject: [PATCH] fix mod barcode product --- .../barcode/mod_barcode_product_standard.php | 27 ++++++++--------- .../mod_barcode_thirdparty_standard.php | 30 ++++++++----------- .../modules/barcode/modules_barcode.class.php | 8 ++--- phpstan.neon.dist | 1 - 4 files changed, 28 insertions(+), 38 deletions(-) diff --git a/htdocs/core/modules/barcode/mod_barcode_product_standard.php b/htdocs/core/modules/barcode/mod_barcode_product_standard.php index ea68cd1810a..31859eb4ead 100644 --- a/htdocs/core/modules/barcode/mod_barcode_product_standard.php +++ b/htdocs/core/modules/barcode/mod_barcode_product_standard.php @@ -109,10 +109,10 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode * Return an example of result returned by getNextValue * * @param Translate $langs Object langs - * @param Product $objproduct Object product + * @param ?Product $objproduct Object product * @return string Return string example */ - public function getExample($langs, $objproduct = 0) + public function getExample($langs, $objproduct = null) { $examplebarcode = $this->getNextValue($objproduct, ''); if (!$examplebarcode) { @@ -155,18 +155,19 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode return $out; } + /** * Return next value * - * @param CommonObject $objproduct Object product - * @param string $type Type of barcode (EAN, ISBN, ...) - * @return string Value if OK, '' if module not configured, <0 if KO + * @param ?CommonObject $objproduct Object product (not used) + * @param string $type Type of barcode (EAN, ISBN, ...) + * @return string Value if OK, '' if module not configured, <0 if KO */ - public function getNextValue($objproduct, $type = '') + public function getNextValue($objproduct = null, $type = '') { - global $db, $conf; + global $db; - if (!$objproduct instanceof Product) { + if (is_object($objproduct) && !$objproduct instanceof Product) { dol_syslog(get_class($this)."::getNextValue used on incompatible".get_class($objproduct), LOG_ERR); return -1; } @@ -178,13 +179,8 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode $type = getDolGlobalString('PRODUIT_DEFAULT_BARCODE_TYPE'); } //get barcode type configuration for products if $type not set - // TODO - // Get Mask value - $mask = ''; - if (getDolGlobalString('BARCODE_STANDARD_PRODUCT_MASK')) { - $mask = getDolGlobalString('BARCODE_STANDARD_PRODUCT_MASK'); - } + $mask = getDolGlobalString('BARCODE_STANDARD_PRODUCT_MASK'); if (empty($mask)) { $this->error = 'NotConfigured'; @@ -216,7 +212,8 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode } } //End barcode with key - return $numFinal; + + return $numFinal; } diff --git a/htdocs/core/modules/barcode/mod_barcode_thirdparty_standard.php b/htdocs/core/modules/barcode/mod_barcode_thirdparty_standard.php index a0e94fd69a1..0113e7dfb39 100644 --- a/htdocs/core/modules/barcode/mod_barcode_thirdparty_standard.php +++ b/htdocs/core/modules/barcode/mod_barcode_thirdparty_standard.php @@ -72,10 +72,11 @@ class mod_barcode_thirdparty_standard extends ModeleNumRefBarCode } - /** Return description of module + /** + * Return description of module * - * @param Translate $langs Object langs - * @return string Description of module + * @param Translate $langs Object langs + * @return string Description of module */ public function info($langs) { @@ -120,10 +121,10 @@ class mod_barcode_thirdparty_standard extends ModeleNumRefBarCode * Return an example of result returned by getNextValue * * @param Translate $langs Object langs - * @param Societe $objthirdparty Object third-party + * @param ?Societe $objthirdparty Object third-party * @return string Return string example */ - public function getExample($langs, $objthirdparty = 0) + public function getExample($langs, $objthirdparty = null) { $examplebarcode = $this->getNextValue($objthirdparty, ''); if (!$examplebarcode) { @@ -169,13 +170,13 @@ class mod_barcode_thirdparty_standard extends ModeleNumRefBarCode /** * Return next value * - * @param CommonObject $objthirdparty Object third-party + * @param ?CommonObject $objthirdparty Object third-party * @param string $type Type of barcode (EAN, ISBN, ...) * @return string Value if OK, '' if module not configured, <0 if KO */ - public function getNextValue($objthirdparty, $type = '') + public function getNextValue($objthirdparty = null, $type = '') { - global $db, $conf; + global $db; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/barcode.lib.php'; // to be able to call function barcode_gen_ean_sum($ean) @@ -184,13 +185,8 @@ class mod_barcode_thirdparty_standard extends ModeleNumRefBarCode $type = getDolGlobalString('GENBARCODE_BARCODETYPE_THIRDPARTY'); } //get barcode type configuration for companies if $type not set - // TODO - // Get Mask value - $mask = ''; - if (getDolGlobalString('BARCODE_STANDARD_THIRDPARTY_MASK')) { - $mask = getDolGlobalString('BARCODE_STANDARD_THIRDPARTY_MASK'); - } + $mask = getDolGlobalString('BARCODE_STANDARD_THIRDPARTY_MASK'); if (empty($mask)) { $this->error = 'NotConfigured'; @@ -222,6 +218,7 @@ class mod_barcode_thirdparty_standard extends ModeleNumRefBarCode } } //End barcode with key + return $numFinal; } @@ -242,10 +239,6 @@ class mod_barcode_thirdparty_standard extends ModeleNumRefBarCode */ public function verif($db, &$code, $thirdparty, $thirdparty_type, $type) { - global $conf; - - //var_dump($code.' '.$thirdparty->ref.' '.$thirdparty_type);exit; - require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; $result = 0; @@ -273,6 +266,7 @@ class mod_barcode_thirdparty_standard extends ModeleNumRefBarCode } dol_syslog(get_class($this)."::verif type=".$thirdparty_type." result=".$result); + return $result; } diff --git a/htdocs/core/modules/barcode/modules_barcode.class.php b/htdocs/core/modules/barcode/modules_barcode.class.php index e037b9e0a09..7a283f5189f 100644 --- a/htdocs/core/modules/barcode/modules_barcode.class.php +++ b/htdocs/core/modules/barcode/modules_barcode.class.php @@ -62,11 +62,11 @@ abstract class ModeleNumRefBarCode extends CommonNumRefGenerator /** * Return next value available * - * @param CommonObject $objcommon Object Product, Thirdparty - * @param string $type Type of barcode (EAN, ISBN, ...) - * @return string Value + * @param ?CommonObject $objcommon Object Product, Thirdparty + * @param string $type Type of barcode (EAN, ISBN, ...) + * @return string Value */ - public function getNextValue($objcommon, $type = '') + public function getNextValue($objcommon = null, $type = '') { global $langs; return $langs->trans("Function_getNextValue_InModuleNotWorking"); diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 78867274e30..c354dfd5d84 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -54,7 +54,6 @@ parameters: - '#(\$force_dolibarr_lib|\$dolibarr_main_db).*in empty\(\) is never defined.#' - '#Sprain\\SwissQrBill\\#' - '#Constructor of class .* has an unused parameter #' - - '#Default value of the parameter#' internalErrorsCountLimit: 50 cache: nodesByFileCountMax: 512