From 28e78d6cb463d9591a09e2d3d181f86ebdb7da96 Mon Sep 17 00:00:00 2001 From: MDW Date: Fri, 25 Oct 2024 14:18:17 +0200 Subject: [PATCH] Qual: Fix phan/stan notices for conferenceorbooth, facture-re, productcustomerprice (#31541) --- dev/tools/phan/baseline.txt | 3 +- htdocs/comm/propal/class/propal.class.php | 6 +- htdocs/commande/card.php | 4 +- htdocs/core/lib/date.lib.php | 2 +- htdocs/core/lib/functions.lib.php | 2 +- .../class/conferenceorboothattendee.class.php | 73 ++++++++- htdocs/fourn/facture/card-rec.php | 2 +- .../class/productcustomerprice.class.php | 145 ++++++++++++++---- phpstan.neon.dist | 1 + 9 files changed, 195 insertions(+), 43 deletions(-) diff --git a/dev/tools/phan/baseline.txt b/dev/tools/phan/baseline.txt index b180a5d9434..07b109590d9 100644 --- a/dev/tools/phan/baseline.txt +++ b/dev/tools/phan/baseline.txt @@ -491,7 +491,7 @@ return [ 'htdocs/emailcollector/class/emailcollector.class.php' => ['PhanPossiblyUndeclaredVariable', 'PhanUndeclaredProperty'], 'htdocs/emailcollector/class/emailcollectoraction.class.php' => ['PhanPluginUnknownPropertyType'], 'htdocs/emailcollector/class/emailcollectorfilter.class.php' => ['PhanPluginUnknownPropertyType'], - 'htdocs/eventorganization/class/conferenceorboothattendee.class.php' => ['PhanPluginUnknownPropertyType', 'PhanPossiblyNullTypeMismatchProperty', 'PhanUndeclaredMethod', 'PhanUndeclaredProperty'], + 'htdocs/eventorganization/class/conferenceorboothattendee.class.php' => ['PhanUndeclaredMethod', 'PhanUndeclaredProperty'], 'htdocs/eventorganization/conferenceorbooth_card.php' => ['PhanUndeclaredGlobalVariable'], 'htdocs/eventorganization/conferenceorbooth_contact.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanUndeclaredGlobalVariable'], 'htdocs/eventorganization/conferenceorbooth_list.php' => ['PhanTypeMismatchArgumentProbablyReal'], @@ -639,7 +639,6 @@ return [ 'htdocs/product/class/html.formproduct.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanTypeMismatchArgumentProbablyReal', 'PhanUndeclaredProperty'], 'htdocs/product/class/product.class.php' => ['PhanPluginUnknownArrayMethodParamType'], 'htdocs/product/class/productbatch.class.php' => ['PhanPluginEmptyStatementIf', 'PhanPluginUnknownPropertyType'], - 'htdocs/product/class/productcustomerprice.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownPropertyType'], 'htdocs/product/class/productfournisseurprice.class.php' => ['PhanUndeclaredMethod', 'PhanUndeclaredProperty'], 'htdocs/product/class/propalmergepdfproduct.class.php' => ['PhanPluginUnknownPropertyType'], 'htdocs/product/document.php' => ['PhanPossiblyNullTypeMismatchProperty', 'PhanPossiblyUndeclaredGlobalVariable'], diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index f84defd8390..8a5c4eecf01 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -483,7 +483,7 @@ class Propal extends CommonObject $productdesc = $prod->description; - $tva_tx = get_default_tva($mysoc, $this->thirdparty, $prod->id); + $tva_tx = (string) get_default_tva($mysoc, $this->thirdparty, $prod->id); $tva_npr = get_default_npr($mysoc, $this->thirdparty, $prod->id); if (empty($tva_tx)) { $tva_npr = 0; @@ -1488,14 +1488,14 @@ class Propal extends CommonObject if ($res > 0) { if ($update_prices === true) { $pu_ht = $prod->price; - $tva_tx = get_default_tva($mysoc, $objsoc, $prod->id); + $tva_tx = (string) get_default_tva($mysoc, $objsoc, $prod->id); $remise_percent = $objsoc->remise_percent; if (getDolGlobalString('PRODUIT_MULTIPRICES') && $objsoc->price_level > 0) { $pu_ht = $prod->multiprices[$objsoc->price_level]; if (getDolGlobalString('PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL')) { // using this option is a bug. kept for backward compatibility if (isset($prod->multiprices_tva_tx[$objsoc->price_level])) { - $tva_tx = $prod->multiprices_tva_tx[$objsoc->price_level]; + $tva_tx = (string) $prod->multiprices_tva_tx[$objsoc->price_level]; } } } elseif (getDolGlobalString('PRODUIT_CUSTOMER_PRICES')) { diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index efdb20a4e24..1ad68e6a87a 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -859,7 +859,7 @@ if (empty($reshook)) { $price_min_ttc = price($prodcustprice->lines[0]->price_min_ttc); $price_base_type = $prodcustprice->lines[0]->price_base_type; $tva_tx = $prodcustprice->lines[0]->tva_tx; - if ($prodcustprice->lines[0]->default_vat_code && !preg_match('/\(.*\)/', $tva_tx)) { + if ($prodcustprice->lines[0]->default_vat_code && !preg_match('/\(.*\)/', (string) $tva_tx)) { $tva_tx .= ' ('.$prodcustprice->lines[0]->default_vat_code.')'; } $tva_npr = $prodcustprice->lines[0]->recuperableonly; @@ -871,7 +871,7 @@ if (empty($reshook)) { setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors'); } - if ( !$pricebycustomerexist && !empty($object->thirdparty->price_level)) { //// If price per segment + if (!$pricebycustomerexist && !empty($object->thirdparty->price_level)) { //// If price per segment $pu_ht = $prod->multiprices[$object->thirdparty->price_level]; $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level]; $price_min = $prod->multiprices_min[$object->thirdparty->price_level]; diff --git a/htdocs/core/lib/date.lib.php b/htdocs/core/lib/date.lib.php index df027a28200..54d3cdee980 100644 --- a/htdocs/core/lib/date.lib.php +++ b/htdocs/core/lib/date.lib.php @@ -115,7 +115,7 @@ function getServerTimeZoneInt($refgmtdate = 'now') /** * Add a delay to a date * - * @param int $time Date timestamp (or string with format YYYY-MM-DD) + * @param int|string $time Date timestamp (or string with format YYYY-MM-DD) * @param float $duration_value Value of delay to add * @param string $duration_unit Unit of added delay (d, m, y, w, h, i) * @param int $ruleforendofmonth Change the behavior of PHP over data-interval, 0 or 1 diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 8774edfe176..fbc7515b421 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -12700,7 +12700,7 @@ function dolGetButtonAction($label, $text = '', $actionType = 'default', $url = * An function to complete dropdown url in dolGetButtonAction * * @param string $url the Url to complete - * @param array|array $params params of dolGetButtonAction function + * @param array $params params of dolGetButtonAction function * @param bool $addDolUrlRoot to add root url * @return string */ diff --git a/htdocs/eventorganization/class/conferenceorboothattendee.class.php b/htdocs/eventorganization/class/conferenceorboothattendee.class.php index 4d2fa64efcd..e7f834a623c 100644 --- a/htdocs/eventorganization/class/conferenceorboothattendee.class.php +++ b/htdocs/eventorganization/class/conferenceorboothattendee.class.php @@ -54,6 +54,9 @@ class ConferenceOrBoothAttendee extends CommonObject */ public $picto = 'contact'; + /** + * @var int<0,1> + */ public $paid = 0; const STATUS_DRAFT = 0; @@ -116,25 +119,85 @@ class ConferenceOrBoothAttendee extends CommonObject 'ip' => array('type' => 'varchar(250)', 'label' => 'IPAddress', 'enabled' => 1, 'position' => 900, 'notnull' => -1, 'visible' => -2,), 'status' => array('type' => 'smallint', 'label' => 'Status', 'enabled' => 1, 'position' => 1000, 'default' => '0', 'notnull' => 1, 'visible' => 1, 'index' => 1, 'arrayofkeyval' => array('0' => 'Draft', '1' => 'Validated', '9' => 'Canceled'),), ); + /** + * @var int + */ public $rowid; + /** + * @var string + */ public $ref; + /** + * @var int + */ public $fk_actioncomm; + /** + * @var int + */ public $fk_project; + /** + * @var string + */ public $email; + /** + * @var string + */ public $firstname; + /** + * @var string + */ public $lastname; + /** + * @var int + */ public $fk_soc; + /** + * @var string + */ public $email_company; + /** + * @var int|string + */ public $date_subscription; + /** + * @var int + */ public $fk_invoice; + /** + * @var string|float (Price) + */ public $amount; + /** + * @var string + */ public $note_public; + /** + * @var string + */ public $note_private; + /** + * @var int + */ public $fk_user_creat; + /** + * @var int + */ public $fk_user_modif; + /** + * @var string + */ public $last_main_doc; + /** + * @var string + */ public $import_key; + /** + * @var string + */ public $model_pdf; + /** + * @var int + */ public $status; // END MODULEBUILDER PROPERTIES @@ -556,12 +619,12 @@ class ConferenceOrBoothAttendee extends CommonObject $this->db->begin(); // Define new ref - if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life + $num = (string) $this->ref; + if (!$error && (preg_match('/^[\(]?PROV/i', $num) || empty($num))) { // empty should not happened, but when it occurs, the test saves life $num = $this->getNextNumRef(); - } else { - $num = $this->ref; } - $this->newref = $num; + + $this->newref = (string) $num; if (!empty($num)) { // Validate @@ -1108,7 +1171,7 @@ class ConferenceOrBoothAttendee extends CommonObject * * @param Translate $langs Language object for translation of civility (used only if option is 1) * @param int $option 0=No option - * @param int $nameorder -1=Auto, 0=Lastname+Firstname, 1=Firstname+Lastname, 2=Firstname, 3=Firstname if defined else lastname, 4=Lastname, 5=Lastname if defined else firstname + * @param int<-1,5> $nameorder -1=Auto, 0=Lastname+Firstname, 1=Firstname+Lastname, 2=Firstname, 3=Firstname if defined else lastname, 4=Lastname, 5=Lastname if defined else firstname * @param int $maxlen Maximum length * @return string String with full name */ diff --git a/htdocs/fourn/facture/card-rec.php b/htdocs/fourn/facture/card-rec.php index ed3abc8e23b..46a6cd42067 100644 --- a/htdocs/fourn/facture/card-rec.php +++ b/htdocs/fourn/facture/card-rec.php @@ -204,7 +204,7 @@ if (empty($reshook)) { $object->note_private = GETPOST('note_private', 'restricthtml'); $object->note_public = GETPOST('note_public', 'restricthtml'); $object->model_pdf = GETPOST('modelpdf', 'alpha'); - $object->usenewprice = GETPOST('usenewprice', 'alpha'); + $object->usenewprice = GETPOSTINT('usenewprice'); $object->frequency = $frequency; $object->unit_frequency = GETPOST('unit_frequency', 'alpha'); diff --git a/htdocs/product/class/productcustomerprice.class.php b/htdocs/product/class/productcustomerprice.class.php index 8e9a7d13da3..28316407537 100644 --- a/htdocs/product/class/productcustomerprice.class.php +++ b/htdocs/product/class/productcustomerprice.class.php @@ -64,6 +64,9 @@ class ProductCustomerPrice extends CommonObject */ public $entity; + /** + * @var string + */ public $datec = ''; /** @@ -81,18 +84,57 @@ class ProductCustomerPrice extends CommonObject */ public $ref_customer; + /** + * @var float|'' + */ public $price; + /** + * @var float|'' + */ public $price_ttc; + /** + * @var float|string|'' + */ public $price_min; + /** + * @var float|string|'' + */ public $price_min_ttc; + /** + * @var string + */ public $price_base_type; + /** + * @var string + */ public $default_vat_code; + /** + * @var string + */ public $tva_tx; + /** + * @var int|string + */ public $recuperableonly; + /** + * @var string + */ public $localtax1_type; + /** + * @var float|'' + */ public $localtax1_tx; + /** + * @var string + */ public $localtax2_type; + /** + * @var float|'' + */ public $localtax2_tx; + /** + * @var string + */ public $price_label; /** @@ -159,7 +201,7 @@ class ProductCustomerPrice extends CommonObject $this->price_base_type = trim($this->price_base_type); } if (isset($this->tva_tx)) { - $this->tva_tx = (float) $this->tva_tx; + $this->tva_tx = trim($this->tva_tx); } if (isset($this->recuperableonly)) { $this->recuperableonly = trim($this->recuperableonly); @@ -184,14 +226,15 @@ class ProductCustomerPrice extends CommonObject // Put here code to add control on parameters values if ($this->price != '' || $this->price == 0) { + $vatRate = (float) $this->tva_tx; if ($this->price_base_type == 'TTC') { $this->price_ttc = price2num($this->price, 'MU'); - $this->price = (float) price2num($this->price) / (1 + ($this->tva_tx / 100)); + $this->price = (float) price2num($this->price) / (1 + ($vatRate / 100)); $this->price = price2num($this->price, 'MU'); if ($this->price_min != '' || $this->price_min == 0) { $this->price_min_ttc = price2num($this->price_min, 'MU'); - $this->price_min = (float) price2num($this->price_min) / (1 + ($this->tva_tx / 100)); + $this->price_min = (float) price2num($this->price_min) / (1 + ($vatRate / 100)); $this->price_min = price2num($this->price_min, 'MU'); } else { $this->price_min = 0; @@ -199,12 +242,12 @@ class ProductCustomerPrice extends CommonObject } } else { $this->price = price2num($this->price, 'MU'); - $this->price_ttc = ($this->recuperableonly != 1) ? (float) price2num($this->price) * (1 + ($this->tva_tx / 100)) : $this->price; + $this->price_ttc = ($this->recuperableonly != 1) ? (float) price2num($this->price) * (1 + ($vatRate / 100)) : $this->price; $this->price_ttc = price2num($this->price_ttc, 'MU'); if ($this->price_min != '' || $this->price_min == 0) { $this->price_min = price2num($this->price_min, 'MU'); - $this->price_min_ttc = (float) price2num($this->price_min) * (1 + ($this->tva_tx / 100)); + $this->price_min_ttc = (float) price2num($this->price_min) * (1 + ($vatRate / 100)); $this->price_min_ttc = price2num($this->price_min_ttc, 'MU'); // print 'X'.$newminprice.'-'.$price_min; } else { @@ -383,7 +426,7 @@ class ProductCustomerPrice extends CommonObject * @param string $sortfield Sort field * @param int $limit Limit page * @param int $offset offset - * @param string|array $filter Filter USF. + * @param string|array $filter Filter USF. * @return int Return integer <0 if KO, >0 if OK * @since dolibarr v17 */ @@ -513,12 +556,12 @@ class ProductCustomerPrice extends CommonObject /** * Load all objects in memory from database * - * @param string $sortorder order - * @param string $sortfield field - * @param int $limit page - * @param int $offset offset - * @param array $filter Filter for sql request - * @return int Return integer <0 if KO, >0 if OK + * @param string $sortorder order + * @param string $sortfield field + * @param int $limit page + * @param int $offset offset + * @param array $filter Filter for sql request + * @return int Return integer <0 if KO, >0 if OK */ public function fetchAllLog($sortorder, $sortfield, $limit, $offset, $filter = array()) { @@ -622,10 +665,10 @@ class ProductCustomerPrice extends CommonObject /** * Update object into database * - * @param User $user that modifies - * @param int $notrigger triggers after, 1=disable triggers - * @param int $forceupdateaffiliate update price on each soc child - * @return int Return integer <0 if KO, >0 if OK + * @param User $user User making modification + * @param int<0,1> $notrigger Triggers after, 1=disable triggers + * @param int<0,1> $forceupdateaffiliate Update price on each soc child + * @return int Return integer <0 if KO, >0 if OK */ public function update(User $user, $notrigger = 0, $forceupdateaffiliate = 0) { @@ -647,31 +690,31 @@ class ProductCustomerPrice extends CommonObject $this->ref_customer = trim($this->ref_customer); } if (isset($this->price)) { - $this->price = trim($this->price); + $this->price = trim((string) $this->price); } if (isset($this->price_ttc)) { - $this->price_ttc = trim($this->price_ttc); + $this->price_ttc = trim((string) $this->price_ttc); } if (isset($this->price_min)) { - $this->price_min = trim($this->price_min); + $this->price_min = trim((string) $this->price_min); } if (isset($this->price_min_ttc)) { - $this->price_min_ttc = trim($this->price_min_ttc); + $this->price_min_ttc = trim((string) $this->price_min_ttc); } if (isset($this->price_base_type)) { $this->price_base_type = trim($this->price_base_type); } if (isset($this->tva_tx)) { - $this->tva_tx = (float) $this->tva_tx; + $this->tva_tx = trim($this->tva_tx); } if (isset($this->recuperableonly)) { - $this->recuperableonly = trim($this->recuperableonly); + $this->recuperableonly = trim((string) $this->recuperableonly); } if (isset($this->localtax1_tx)) { - $this->localtax1_tx = trim($this->localtax1_tx); + $this->localtax1_tx = trim((string) $this->localtax1_tx); } if (isset($this->localtax2_tx)) { - $this->localtax2_tx = trim($this->localtax2_tx); + $this->localtax2_tx = trim((string) $this->localtax2_tx); } if (isset($this->fk_user)) { $this->fk_user = (int) $this->fk_user; @@ -687,14 +730,15 @@ class ProductCustomerPrice extends CommonObject // Put here code to add a control on parameters values if ($this->price != '' || $this->price == 0) { + $vatRate = (float) $this->tva_tx; if ($this->price_base_type == 'TTC') { $this->price_ttc = price2num($this->price, 'MU'); - $this->price = (float) price2num($this->price) / (1 + ($this->tva_tx / 100)); + $this->price = (float) price2num($this->price) / (1 + ($vatRate / 100)); $this->price = price2num($this->price, 'MU'); if ($this->price_min != '' || $this->price_min == 0) { $this->price_min_ttc = price2num($this->price_min, 'MU'); - $this->price_min = (float) price2num($this->price_min) / (1 + ($this->tva_tx / 100)); + $this->price_min = (float) price2num($this->price_min) / (1 + ($vatRate / 100)); $this->price_min = price2num($this->price_min, 'MU'); } else { $this->price_min = 0; @@ -702,12 +746,12 @@ class ProductCustomerPrice extends CommonObject } } else { $this->price = price2num($this->price, 'MU'); - $this->price_ttc = ($this->recuperableonly != 1) ? (float) price2num($this->price) * (1 + ($this->tva_tx / 100)) : $this->price; + $this->price_ttc = ($this->recuperableonly != 1) ? (float) price2num($this->price) * (1 + ($vatRate / 100)) : $this->price; $this->price_ttc = price2num($this->price_ttc, 'MU'); if ($this->price_min != '' || $this->price_min == 0) { $this->price_min = price2num($this->price_min, 'MU'); - $this->price_min_ttc = (float) price2num($this->price_min) * (1 + ($this->tva_tx / 100)); + $this->price_min_ttc = (float) price2num($this->price_min) * (1 + ($vatRate / 100)); $this->price_min_ttc = price2num($this->price_min_ttc, 'MU'); // print 'X'.$newminprice.'-'.$price_min; } else { @@ -1083,6 +1127,9 @@ class PriceByCustomerLine extends CommonObjectLine */ public $entity; + /** + * @var string|int + */ public $datec = ''; /** @@ -1100,24 +1147,66 @@ class PriceByCustomerLine extends CommonObjectLine */ public $fk_soc; + /** + * @var float + */ public $price; + /** + * @var float + */ public $price_ttc; + /** + * @var float + */ public $price_min; + /** + * @var float + */ public $price_min_ttc; + /** + * @var string + */ public $price_base_type; + /** + * @var string + */ public $default_vat_code; + /** + * @var string + */ public $tva_tx; + /** + * @var int|string + */ public $recuperableonly; + /** + * @var float + */ public $localtax1_tx; + /** + * @var float + */ public $localtax2_tx; /** * @var int User ID */ public $fk_user; + /** + * @var string + */ public $price_label; + /** + * @var string + */ public $import_key; + /** + * @var string + */ public $socname; + /** + * @var string + */ public $prodref; } diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 47b8469f211..fc705135638 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -47,6 +47,7 @@ parameters: reportMagicProperties: false treatPhpDocTypesAsCertain: false ignoreErrors: + - '#Unable to resolve the template type T#' - '#Offset .* (?:isset\(\)) always exists and is not nullable#' - '#(?:Variable \$(?:_(?:FILES|POST|SERVER)|array_propal_object|baseUri|current_fiscal_period|d(?:b_create_(?:database|user)|olibarr_main_(?:db_prefix|url_root)|raftchecked)|erreur_ajout_date|isImageValid|keyforstripeterminalbank|(?:lo|mar)gin|max|n(?:ewProperty|um)|p(?:ermsgroupbyentitypluszero|ro(?:gressCalculated|parrayofkeyval)|ublic)|t(?:(?:itl|otal_tim)e|va_tx)|var)) in isset\(\) always exists and is not nullable#' - '#(?:Property CommonOrderLine::\$multicurrency_subprice \(float\) on left side of \?\?|isset\(\)) is not nullable#'