From eefe123dcb4b30fae29a34da77d108922169e454 Mon Sep 17 00:00:00 2001 From: MDW Date: Mon, 11 Mar 2024 23:42:45 +0100 Subject: [PATCH] fixup! fix phpstan (#28727) --- .../barcode/mod_barcode_product_standard.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/htdocs/core/modules/barcode/mod_barcode_product_standard.php b/htdocs/core/modules/barcode/mod_barcode_product_standard.php index c2df3f7c3a0..9e830faa4c2 100644 --- a/htdocs/core/modules/barcode/mod_barcode_product_standard.php +++ b/htdocs/core/modules/barcode/mod_barcode_product_standard.php @@ -4,6 +4,7 @@ * Copyright (C) 2007-2012 Regis Houssin * Copyright (C) 2011 Juanjo Menent * Copyright (C) 2024 Frédéric France + * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -157,14 +158,19 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode /** * Return next value * - * @param Product $objproduct Object product - * @param string $type Type of barcode (EAN, ISBN, ...) + * @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 */ public function getNextValue($objproduct, $type = '') { global $db, $conf; + if (!$objproduct instanceof Product) { + dol_syslog(get_class($this)."::getNextValue used on incompatible".get_class($objproduct), LOG_ERR); + return -1; + } + 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) @@ -192,19 +198,19 @@ class mod_barcode_product_standard extends ModeleNumRefBarCode $numFinal = get_next_value($db, $mask, 'product', $field, $where, '', $now); //Begin barcode with key: for barcode with key (EAN13...) calculate and substitute the last character (* or ?) used in the mask by the key - if ((substr($numFinal, -1)=='*') or (substr($numFinal, -1)=='?')) { // if last mask character is * or ? a joker, probably we have to calculate a key as last character (EAN13...) + if ((substr($numFinal, -1) == '*') or (substr($numFinal, -1) == '?')) { // if last mask character is * or ? a joker, probably we have to calculate a key as last character (EAN13...) $literaltype = ''; $literaltype = $this->literalBarcodeType($db, $type);//get literal_Barcode_Type switch ($literaltype) { case 'EAN13': //EAN13 rowid = 2 - if (strlen($numFinal)==13) {// be sure that the mask length is correct for EAN13 + if (strlen($numFinal) == 13) {// be sure that the mask length is correct for EAN13 $ean = substr($numFinal, 0, 12); //take first 12 digits - $eansum = barcode_gen_ean_sum($ean); + $eansum = barcode_gen_ean_sum($ean); $ean .= $eansum; //substitute the las character by the key $numFinal = $ean; } break; - // Other barcode cases with key could be written here + // Other barcode cases with key could be written here default: break; }