From e81d5378cd98e24c1772303bfeadf5a6dbfc9b64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 10 Sep 2025 11:13:18 +0200 Subject: [PATCH] clean code contract class (#35245) * clean code contract class * clean code contract class * clean code contract class * clean code contract class * clean code contract class * clean code contract class * clean code contract class * clean code contract class * clean code contract class * clean code contract class * clean code contract class * clean code contract class * clean code contract class * clean code contract class * clean code contract class * clean code * clean code * clean code * clean code * clean code * fix typo * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix --- dev/build/phpstan/phpstan-baseline.neon | 102 --------------- .../class/accountancyexport.class.php | 8 +- .../class/accountingaccount.class.php | 6 +- htdocs/asset/card.php | 2 +- htdocs/asset/class/asset.class.php | 2 +- htdocs/bom/bom_card.php | 6 +- htdocs/bom/class/bom.class.php | 2 +- htdocs/bookcal/class/availabilities.class.php | 4 +- htdocs/bookcal/class/calendar.class.php | 2 +- htdocs/comm/propal/card.php | 2 +- htdocs/comm/propal/class/propal.class.php | 2 +- htdocs/commande/card.php | 2 +- htdocs/commande/class/commande.class.php | 2 +- htdocs/compta/facture/card.php | 2 +- htdocs/compta/facture/class/facture.class.php | 2 +- htdocs/contrat/card.php | 2 +- htdocs/contrat/class/contrat.class.php | 119 +++++++++--------- htdocs/contrat/class/contratligne.class.php | 14 +-- htdocs/contrat/index.php | 8 +- htdocs/core/class/commonobject.class.php | 10 +- htdocs/core/class/html.formticket.class.php | 2 +- htdocs/core/class/notify.class.php | 2 +- htdocs/core/class/timespent.class.php | 14 +-- .../stocktransfer/doc/pdf_eagle.modules.php | 3 +- htdocs/delivery/class/delivery.class.php | 2 +- htdocs/ecm/class/ecmdirectory.class.php | 4 +- htdocs/expedition/card.php | 2 +- htdocs/expedition/class/expedition.class.php | 2 +- .../class/expensereport.class.php | 2 +- htdocs/fichinter/card.php | 2 +- htdocs/fichinter/class/fichinter.class.php | 2 +- .../class/fournisseur.commande.class.php | 6 +- .../fourn/class/fournisseur.facture.class.php | 2 +- .../fourn/class/fournisseur.product.class.php | 2 +- htdocs/fourn/facture/card.php | 2 +- htdocs/holiday/class/holiday.class.php | 2 +- htdocs/hrm/class/evaluation.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/hrm/evaluation_card.php | 2 +- .../class/knowledgerecord.class.php | 2 +- .../template/class/myobject.class.php | 2 +- htdocs/mrp/class/mo.class.php | 2 +- htdocs/mrp/mo_card.php | 2 +- htdocs/mrp/mo_production.php | 2 +- .../partnership/class/partnership.class.php | 4 +- htdocs/product/class/product.class.php | 2 +- .../class/productfournisseurprice.class.php | 2 +- .../class/stocktransfer.class.php | 2 +- .../class/stocktransferline.class.php | 2 +- .../product/stock/tpl/stockcorrection.tpl.php | 4 +- .../product/stock/tpl/stocktransfer.tpl.php | 4 +- htdocs/projet/class/project.class.php | 2 +- htdocs/projet/tasks/task.php | 4 +- htdocs/public/website/index.php | 4 +- htdocs/reception/card.php | 2 +- htdocs/reception/class/reception.class.php | 4 +- .../class/recruitmentcandidature.class.php | 2 +- .../class/recruitmentjobposition.class.php | 2 +- htdocs/supplier_proposal/card.php | 2 +- .../class/supplier_proposal.class.php | 2 +- htdocs/variants/combinations.php | 4 +- htdocs/webhook/class/target.class.php | 2 +- .../class/html.formwebportal.class.php | 11 +- 67 files changed, 166 insertions(+), 269 deletions(-) diff --git a/dev/build/phpstan/phpstan-baseline.neon b/dev/build/phpstan/phpstan-baseline.neon index dd11b0999f6..e86882deb1d 100644 --- a/dev/build/phpstan/phpstan-baseline.neon +++ b/dev/build/phpstan/phpstan-baseline.neon @@ -5418,108 +5418,6 @@ parameters: count: 1 path: ../../../htdocs/contrat/card.php - - - message: '#^Call to function method_exists\(\) with \$this\(Contrat\) and ''getLibStatut'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: ../../../htdocs/contrat/class/contrat.class.php - - - - message: '#^Call to function method_exists\(\) with \$this\(Contrat\) and ''getNomUrl'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: ../../../htdocs/contrat/class/contrat.class.php - - - - message: '#^Call to function property_exists\(\) with \$this\(Contrat\) and ''date_contrat'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: ../../../htdocs/contrat/class/contrat.class.php - - - - message: '#^Negated boolean expression is always true\.$#' - identifier: booleanNot.alwaysTrue - count: 4 - path: ../../../htdocs/contrat/class/contrat.class.php - - - - message: '#^Property CommonObject\:\:\$ref \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: ../../../htdocs/contrat/class/contrat.class.php - - - - message: '#^Property CommonObject\:\:\$ref_ext \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: ../../../htdocs/contrat/class/contrat.class.php - - - - message: '#^Property Contrat\:\:\$fk_commercial_signature \(int\|string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: ../../../htdocs/contrat/class/contrat.class.php - - - - message: '#^Property Contrat\:\:\$fk_commercial_suivi \(int\|string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: ../../../htdocs/contrat/class/contrat.class.php - - - - message: '#^Property Contrat\:\:\$ref_customer \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: ../../../htdocs/contrat/class/contrat.class.php - - - - message: '#^Property Contrat\:\:\$ref_supplier \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: ../../../htdocs/contrat/class/contrat.class.php - - - - message: '#^Property Contrat\:\:\$socid \(int\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/contrat/class/contrat.class.php - - - - message: '#^Property Contrat\:\:\$status \(int\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: ../../../htdocs/contrat/class/contrat.class.php - - - - message: '#^Property Contrat\:\:\$statut \(int\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/contrat/class/contrat.class.php - - - - message: '#^Variable \$sql might not be defined\.$#' - identifier: variable.undefined - count: 1 - path: ../../../htdocs/contrat/class/contrat.class.php - - - - message: '#^Negated boolean expression is always true\.$#' - identifier: booleanNot.alwaysTrue - count: 1 - path: ../../../htdocs/contrat/class/contratligne.class.php - - - - message: '#^Offset ''label'' on array\{label\: non\-falsy\-string\} in empty\(\) always exists and is not falsy\.$#' - identifier: empty.offset - count: 1 - path: ../../../htdocs/contrat/class/contratligne.class.php - - - - message: '#^Variable \$label in empty\(\) always exists and is not falsy\.$#' - identifier: empty.variable - count: 1 - path: ../../../htdocs/contrat/class/contratligne.class.php - - message: '#^Variable \$mesg might not be defined\.$#' identifier: variable.undefined diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index 00569bcfab6..2c6fe91ac33 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -1412,14 +1412,14 @@ class AccountancyExport $invoice = new Facture($this->db); $invoice->fetch($line->fk_doc); - $refInvoice = $invoice->ref; + $refInvoice = (string) $invoice->ref; } elseif ($line->doc_type == 'supplier_invoice') { // Supplier invoice require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; $invoice = new FactureFournisseur($this->db); $invoice->fetch($line->fk_doc); - $refInvoice = $invoice->ref_supplier; + $refInvoice = (string) $invoice->ref_supplier; } $tab = array(); @@ -1632,14 +1632,14 @@ class AccountancyExport $invoice = new Facture($this->db); $invoice->fetch($line->fk_doc); - $refInvoice = $invoice->ref; + $refInvoice = (string) $invoice->ref; } elseif ($line->doc_type == 'supplier_invoice') { // Supplier invoice require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; $invoice = new FactureFournisseur($this->db); $invoice->fetch($line->fk_doc); - $refInvoice = $invoice->ref_supplier; + $refInvoice = (string) $invoice->ref_supplier; } $tab = array(); diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php index edba5a85afd..97960271195 100644 --- a/htdocs/accountancy/class/accountingaccount.class.php +++ b/htdocs/accountancy/class/accountingaccount.class.php @@ -4,7 +4,7 @@ * Copyright (C) 2013-2021 Florian Henry * Copyright (C) 2014 Juanjo Menent * Copyright (C) 2015 Ari Elbaz (elarifr) - * Copyright (C) 2018-2024 Frédéric France + * Copyright (C) 2018-2025 Frédéric France * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify @@ -889,7 +889,7 @@ class AccountingAccount extends CommonObject return -1; } - $code_l = $accountdeposittoventilated->ref; + $code_l = (string) $accountdeposittoventilated->ref; $code_p = ''; $code_t = ''; $suggestedid = $accountdeposittoventilated->rowid; @@ -908,7 +908,7 @@ class AccountingAccount extends CommonObject } elseif ($type == 'supplier') { $accountdeposittoventilated->fetch(0, getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT'), 1); } - $code_l = $accountdeposittoventilated->ref; + $code_l = (string) $accountdeposittoventilated->ref; $code_p = ''; $code_t = ''; $suggestedid = $accountdeposittoventilated->rowid; diff --git a/htdocs/asset/card.php b/htdocs/asset/card.php index c153e3ecb98..e611f09628b 100644 --- a/htdocs/asset/card.php +++ b/htdocs/asset/card.php @@ -279,7 +279,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea if ($ref == 'PROV') { $numref = $object->getNextNumRef(); } else { - $numref = $object->ref; + $numref = (string) $object->ref; } $text = $langs->trans('ConfirmValidateAsset', $numref); diff --git a/htdocs/asset/class/asset.class.php b/htdocs/asset/class/asset.class.php index a8c2dcf146c..ac6c11b4932 100644 --- a/htdocs/asset/class/asset.class.php +++ b/htdocs/asset/class/asset.class.php @@ -1726,7 +1726,7 @@ class Asset extends CommonObject if (/* !$error && */ (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef(); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = dol_sanitizeFileName($num); diff --git a/htdocs/bom/bom_card.php b/htdocs/bom/bom_card.php index 0f97efcc59b..7a252c9a4d3 100644 --- a/htdocs/bom/bom_card.php +++ b/htdocs/bom/bom_card.php @@ -1,6 +1,6 @@ - * Copyright (C) 2019-2024 Frédéric France + * Copyright (C) 2019-2025 Frédéric France * Copyright (C) 2023 Charlene Benke * Copyright (C) 2024-2025 MDW * @@ -319,7 +319,7 @@ $form = new Form($db); $formfile = new FormFile($db); if ($object->id > 0) { - $title = $object->ref; + $title = (string) $object->ref; } else { $title = $langs->trans('BOM'); } @@ -409,7 +409,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea $object->fetch_product(); $numref = $object->getNextNumRef($object->product); } else { - $numref = $object->ref; + $numref = (string) $object->ref; } $text = $langs->trans('ConfirmValidateBom', $numref); diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php index 2cf64b08ef1..fbb1d69bb3b 100644 --- a/htdocs/bom/class/bom.class.php +++ b/htdocs/bom/class/bom.class.php @@ -940,7 +940,7 @@ class BOM extends CommonObject $this->fetch_product(); $num = $this->getNextNumRef($this->product); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = dol_sanitizeFileName($num); diff --git a/htdocs/bookcal/class/availabilities.class.php b/htdocs/bookcal/class/availabilities.class.php index f7d1e1ea7c4..630f63a58cc 100644 --- a/htdocs/bookcal/class/availabilities.class.php +++ b/htdocs/bookcal/class/availabilities.class.php @@ -26,8 +26,6 @@ // Put here all includes required by your class file require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; -//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; -//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; /** * Class for Availabilities @@ -556,7 +554,7 @@ class Availabilities extends CommonObject if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef(); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = $num; diff --git a/htdocs/bookcal/class/calendar.class.php b/htdocs/bookcal/class/calendar.class.php index b52aa462b13..f58721b0034 100644 --- a/htdocs/bookcal/class/calendar.class.php +++ b/htdocs/bookcal/class/calendar.class.php @@ -510,7 +510,7 @@ class Calendar extends CommonObject if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef(); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = $num; diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index e480d8b8f41..5f2fb7e508b 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -2926,7 +2926,7 @@ if ($action == 'create') { setEventMessages($object->error, $object->errors, 'errors'); } } else { - $numref = $object->ref; + $numref = (string) $object->ref; } $text = $langs->trans('ConfirmValidateProp', $numref); diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 455089aa706..fc0137ef334 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -2111,7 +2111,7 @@ class Propal extends CommonObject if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef($soc); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = dol_sanitizeFileName($num); diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 3e96d198089..e0eca5ac480 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -2633,7 +2633,7 @@ if ($action == 'create' && $usercancreate) { setEventMessages($object->error, $object->errors, 'errors'); } } else { - $numref = $object->ref; + $numref = (string) $object->ref; } $text = $langs->trans('ConfirmValidateOrder', $numref); diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index f1cb50a5366..f5b4c19e901 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -541,7 +541,7 @@ class Commande extends CommonOrder if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef($soc); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = dol_sanitizeFileName($num); diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index fdc919d273c..914643f7c9c 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -4904,7 +4904,7 @@ if ($action == 'create') { $numref = $object->getNextNumRef($soc); // $object->date=$savdate; } else { - $numref = $object->ref; + $numref = (string) $object->ref; } $text = $langs->trans('ConfirmValidateBill', $numref); diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 457f6710879..ef855d7845e 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -3672,7 +3672,7 @@ class Facture extends CommonInvoice } $num = $this->getNextNumRef($this->thirdparty); } else { - $num = $this->ref; + $num = (string) $this->ref; } if (!$num) { diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 25fbdeb7d0c..a9c5756e8b5 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -1394,7 +1394,7 @@ if ($action == 'create') { if ($ref == 'PROV' && !empty($modCodeContract->code_auto)) { $numref = $object->getNextNumRef($object->thirdparty); } else { - $numref = $object->ref; + $numref = (string) $object->ref; } $text = $langs->trans('ConfirmValidateContract', $numref); $formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id, $langs->trans("ValidateAContract"), $text, "confirm_valid", '', 0, 1); diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index ef3802c69d7..5e063581326 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -88,7 +88,7 @@ class Contrat extends CommonObject /** * Customer reference of the contract - * @var string + * @var ?string */ public $ref_customer; @@ -99,7 +99,7 @@ class Contrat extends CommonObject /** * Supplier reference of the contract - * @var string + * @var ?string */ public $ref_supplier; @@ -123,13 +123,14 @@ class Contrat extends CommonObject /** * Status of the contract - * @var int + * @var ?int * @deprecated */ public $statut = 0; + /** * Status of the contract (0=Draft, 1=Validated) - * @var int + * @var ?int */ public $status = 0; @@ -168,28 +169,27 @@ class Contrat extends CommonObject public $date_contrat; /** - * @var int + * @var ?int */ public $commercial_signature_id; - /** - * @var int|string - */ - public $fk_commercial_signature; - /** - * @var int - */ - public $commercial_suivi_id; - /** - * @var int|string - */ - public $fk_commercial_suivi; /** - * @var int - * @deprecated Use fk_project instead - * @see $fk_project + * @var ?int + * @deprecated */ - public $fk_projet; + public $fk_commercial_signature; + + /** + * @var ?int + */ + public $commercial_suivi_id; + + /** + * @var ?int + * @deprecated Use $commercial_suivi_id instead + * @see $commercial_suivi_id + */ + public $fk_commercial_suivi; /** * @var array (Encoded as JSON in database) @@ -337,6 +337,7 @@ class Contrat extends CommonObject $obj = new $classname(); '@phan-var-force ModelNumRefContracts $obj'; + /** @var ModelNumRefContracts $obj */ $numref = $obj->getNextValue($soc, $this); if ($numref != "") { @@ -548,10 +549,10 @@ class Contrat extends CommonObject // Define new ref if ($force_number) { $num = $force_number; - } elseif (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life + } elseif (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef($this->thirdparty); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = dol_sanitizeFileName($num); @@ -948,7 +949,7 @@ class Contrat extends CommonObject //$line->date_fin_prevue = $this->db->jdate($objp->date_fin_validite); //$line->date_fin_reel = $this->db->jdate($objp->date_cloture); - $line->rang = $objp->rang; + $line->rang = $objp->rang; // Retrieve all extrafields for contract line // fetch optionals attributes and labels @@ -1075,7 +1076,8 @@ class Contrat extends CommonObject $result = dol_include_once('/core/modules/contract/'.$module.'.php'); if ($result > 0) { $modCodeContract = new $module(); - '@phan-var-force ModelNumRefContracts $modCodeContrat'; + '@phan-var-force ModelNumRefContracts $modCodeContract'; + /** @var ModelNumRefContracts $modCodeContract */ if (!empty($modCodeContract->code_auto)) { // Force the ref to a draft value if numbering module is an automatic numbering @@ -1088,15 +1090,13 @@ class Contrat extends CommonObject } } - if (!$error) { - $result = $this->insertExtraFields(); - if ($result < 0) { - $error++; - } + $result = $this->insertExtraFields(); + if ($result < 0) { + $error++; } // Insert business contacts ('SALESREPSIGN','contrat') - if (!$error) { + if (!$error && !empty($this->commercial_signature_id)) { $result = $this->add_contact($this->commercial_signature_id, 'SALESREPSIGN', 'internal'); if ($result < 0) { $error++; @@ -1104,7 +1104,7 @@ class Contrat extends CommonObject } // Insert business contacts ('SALESREPFOLL','contrat') - if (!$error) { + if (!$error && !empty($this->commercial_suivi_id)) { $result = $this->add_contact($this->commercial_suivi_id, 'SALESREPFOLL', 'internal'); if ($result < 0) { $error++; @@ -1117,7 +1117,7 @@ class Contrat extends CommonObject } // Add object linked - if (!$error && $this->id && !empty($this->linked_objects) && is_array($this->linked_objects)) { + if ($this->id && !empty($this->linked_objects) && is_array($this->linked_objects)) { foreach ($this->linked_objects as $origin => $tmp_origin_id) { if (is_array($tmp_origin_id)) { // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...)) foreach ($tmp_origin_id as $origin_id) { @@ -1369,14 +1369,14 @@ class Contrat extends CommonObject if (isset($this->status)) { $this->status = (int) $this->status; } - if (isset($this->socid)) { + if ((int) $this->socid > 0) { $this->socid = (int) $this->socid; } if (isset($this->fk_commercial_signature)) { - $this->fk_commercial_signature = trim($this->fk_commercial_signature); + $this->fk_commercial_signature = (int) $this->fk_commercial_signature; } if (isset($this->fk_commercial_suivi)) { - $this->fk_commercial_suivi = trim($this->fk_commercial_suivi); + $this->fk_commercial_suivi = (int) $this->fk_commercial_suivi; } if (isset($this->note_private)) { $this->note_private = trim($this->note_private); @@ -1487,7 +1487,7 @@ class Contrat extends CommonObject return -1; } - if ($this->statut >= 0) { + if ($this->status >= 0) { // Clean parameters $pu_ht = price2num($pu_ht); $pu_ttc = price2num($pu_ttc); @@ -1640,16 +1640,14 @@ class Contrat extends CommonObject if ($resql) { $contractlineid = $this->db->last_insert_id(MAIN_DB_PREFIX."contratdet"); - if (!$error) { - $contractline = new ContratLigne($this->db); - $contractline->array_options = $array_options; - $contractline->id = $contractlineid; - $result = $contractline->insertExtraFields(); - if ($result < 0) { - $this->errors = array_merge($this->errors, $contractline->errors); - $this->error = $contractline->error; - $error++; - } + $contractline = new ContratLigne($this->db); + $contractline->array_options = $array_options; + $contractline->id = $contractlineid; + $result = $contractline->insertExtraFields(); + if ($result < 0) { + $this->errors = array_merge($this->errors, $contractline->errors); + $this->error = $contractline->error; + $error++; } if (empty($error)) { @@ -2261,8 +2259,8 @@ class Contrat extends CommonObject /** * Load indicators for dashboard (this->nbtodo and this->nbtodolate) * - * @param User $user Object user - * @param string $mode "inactive" pour services a activer, "expired" pour services expires + * @param User $user Object user + * @param 'inactive'|'expired'|'active' $mode "inactive" pour services a activer, "expired" pour services expires * @return WorkboardResponse|int Return integer <0 if KO, WorkboardResponse if OK */ public function load_board($user, $mode) @@ -2298,6 +2296,8 @@ class Contrat extends CommonObject $sql .= " AND cd.statut = 4"; //$datetouse = dol_now(); //$sql.= " AND cd.date_fin_validite < '".$this->db->idate($datetouse)."'"; + } else { + return -1; } $sql .= " AND c.fk_soc = s.rowid"; $sql .= " AND c.entity = ".((int) $conf->entity); @@ -2617,6 +2617,7 @@ class Contrat extends CommonObject // Clean data $clonedObj->statut = 0; + $clonedObj->status = 0; // Clean extrafields if (is_array($clonedObj->array_options) && count($clonedObj->array_options) > 0) { $extrafields->fetch_name_optionals_label($this->table_element); @@ -2641,6 +2642,7 @@ class Contrat extends CommonObject $obj = getDolGlobalString('CONTRACT_ADDON'); $modContract = new $obj(); '@phan-var-force ModelNumRefContracts $modContract'; + /** @var ModelNumRefContracts $modContract */ $clonedObj->ref = $modContract->getNextValue($objsoc, $clonedObj); // get extrafields so they will be clone @@ -2653,8 +2655,7 @@ class Contrat extends CommonObject $result = $clonedObj->create($user); if ($result < 0) { $error++; - $this->error = $clonedObj->error; - $this->errors[] = $clonedObj->error; + $this->setErrorsFromObject($clonedObj); } else { // copy external contacts if same company if ($this->socid == $clonedObj->socid) { @@ -2679,8 +2680,8 @@ class Contrat extends CommonObject // Hook of thirdparty module if (is_object($hookmanager)) { $parameters = array( - 'objFrom' => $this, - 'clonedObj' => $clonedObj + 'objFrom' => $this, + 'clonedObj' => $clonedObj ); $action = ''; $reshook = $hookmanager->executeHooks('createFrom', $parameters, $clonedObj, $action); // Note that $action and $object may have been modified by some hooks @@ -2916,21 +2917,17 @@ class Contrat extends CommonObject $return .= img_picto('', $this->picto); $return .= ''; $return .= '
'; - $return .= ''.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).''; + $return .= '' . $this->getNomUrl() . ''; if ($selected >= 0) { $return .= ''; } - if (!empty($arraydata['thirdparty'])) { + if (!empty($arraydata['thirdparty']) && $arraydata['thirdparty'] instanceof Societe) { $tmpthirdparty = $arraydata['thirdparty']; '@phan-var-force Societe $tmpthirdparty'; $return .= '
'.$tmpthirdparty->getNomUrl(1).'
'; } - if (property_exists($this, 'date_contrat')) { - $return .= '
'.$langs->trans("DateContract").' : '.dol_print_date($this->date_contrat, 'day').''; - } - if (method_exists($this, 'getLibStatut')) { - $return .= '
'.$this->getLibStatut(7).'
'; - } + $return .= '
'.$langs->trans("DateContract").' : '.dol_print_date($this->date_contrat, 'day').''; + $return .= '
'.$this->getLibStatut(7).'
'; $return .= '
'; $return .= ''; $return .= ''; diff --git a/htdocs/contrat/class/contratligne.class.php b/htdocs/contrat/class/contratligne.class.php index e99cec57a2e..8f6b10b85e3 100644 --- a/htdocs/contrat/class/contratligne.class.php +++ b/htdocs/contrat/class/contratligne.class.php @@ -395,7 +395,7 @@ class ContratLigne extends CommonObjectLine $datas = []; $datas['label'] = $langs->trans("ShowContractOfService").': '.$this->label; - if (empty($datas['label'])) { + if (empty($this->label)) { $datas['label'] = $this->description; } @@ -415,7 +415,7 @@ class ContratLigne extends CommonObjectLine $result = ''; $label = $langs->trans("ShowContractOfService").': '.$this->label; - if (empty($label)) { + if (empty($this->label)) { $label = $this->description; } $classfortooltip = 'classfortooltip'; @@ -877,12 +877,10 @@ class ContratLigne extends CommonObjectLine $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'contratdet'); // Insert of extrafields - if (!$error) { - $result = $this->insertExtraFields(); - if ($result < 0) { - $this->db->rollback(); - return -1; - } + $result = $this->insertExtraFields(); + if ($result < 0) { + $this->db->rollback(); + return -1; } if (!$notrigger) { diff --git a/htdocs/contrat/index.php b/htdocs/contrat/index.php index db41c5cbd44..007a9f0fcd1 100644 --- a/htdocs/contrat/index.php +++ b/htdocs/contrat/index.php @@ -6,7 +6,7 @@ * Copyright (C) 2019 Nicolas ZABOURI * Copyright (C) 2024-2025 MDW * Copyright (C) 2024 Alexandre Spangaro - * Copyright (C) 2024 Frédéric France + * Copyright (C) 2024-2025 Frédéric France * * 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 @@ -183,6 +183,12 @@ if ($resql) { $colorseries = array(); include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php'; +/** + * @var string $badgeStatus0 + * @var string $badgeStatus1 + * @var string $badgeStatus4 + * @var string $badgeStatus6 + */ print '
'; print ''; diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index afb4bdae217..322f5539ffd 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -325,12 +325,12 @@ abstract class CommonObject /** - * @var string The object's reference + * @var ?string The object's reference */ public $ref; /** - * @var string An external reference to the object + * @var ?string An external reference to the object */ public $ref_ext; @@ -345,7 +345,7 @@ abstract class CommonObject public $ref_next; /** - * @var string Ref to store on object to save the new ref to use for example when making a validate() of an object + * @var ?string Ref to store on object to save the new ref to use for example when making a validate() of an object */ public $newref; @@ -2428,7 +2428,7 @@ abstract class CommonObject if ($fieldid == 'rowid') { $sql .= " WHERE te.".$fieldid." < ".((int) $this->id); } else { - $sql .= " WHERE te.".$fieldid." < '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) + $sql .= " WHERE te.".$fieldid." < '".$this->db->escape((string) $this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) } if ($restrictiononfksoc == 1 && !$user->hasRight('societe', 'client', 'voir') && !$socid) { $sql .= " AND sc.fk_user = ".((int) $user->id); @@ -2507,7 +2507,7 @@ abstract class CommonObject if ($fieldid == 'rowid') { $sql .= " WHERE te.".$fieldid." > ".((int) $this->id); } else { - $sql .= " WHERE te.".$fieldid." > '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) + $sql .= " WHERE te.".$fieldid." > '".$this->db->escape((string) $this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) } if ($restrictiononfksoc == 1 && !$user->hasRight('societe', 'client', 'voir') && !$socid) { $sql .= " AND (sc.fk_user = ".((int) $user->id); diff --git a/htdocs/core/class/html.formticket.class.php b/htdocs/core/class/html.formticket.class.php index 7efa64cdd8e..3d1224c3d31 100644 --- a/htdocs/core/class/html.formticket.class.php +++ b/htdocs/core/class/html.formticket.class.php @@ -326,7 +326,7 @@ class FormTicket $defaultref = $ticketstat->getDefaultRef(); if ($mode == 'edit') { - $defaultref = $object->ref; + $defaultref = (string) $object->ref; } print '
'.$langs->trans("Ref").''; print ''; diff --git a/htdocs/core/class/notify.class.php b/htdocs/core/class/notify.class.php index 88348ba8f21..0bce2df7ebf 100644 --- a/htdocs/core/class/notify.class.php +++ b/htdocs/core/class/notify.class.php @@ -1070,7 +1070,7 @@ class Notify } // Check notification using fixed email - // TODO Move vars NOTIFICATION_FIXEDEMAIL into table llx_notify_def and inclulde the case into previous loop of sql result + // TODO Move vars NOTIFICATION_FIXEDEMAIL into table llx_notify_def and include the case into previous loop of sql result if (!$error) { foreach ($conf->global as $key => $val) { $reg = array(); diff --git a/htdocs/core/class/timespent.class.php b/htdocs/core/class/timespent.class.php index 39d39c027c5..4287e3af7bd 100644 --- a/htdocs/core/class/timespent.class.php +++ b/htdocs/core/class/timespent.class.php @@ -1,8 +1,8 @@ - * Copyright (C) 2023-2025 Frédéric France - * Copyright (C) 2023 Gauthier VERDOL - * Copyright (C) 2024 MDW +/* Copyright (C) 2017 Laurent Destailleur + * Copyright (C) 2023-2025 Frédéric France + * Copyright (C) 2023 Gauthier VERDOL + * 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 @@ -26,8 +26,6 @@ // Put here all includes required by your class file require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; -//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; -//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php'; /** * Class for TimeSpent @@ -520,7 +518,7 @@ class TimeSpent extends CommonObject if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef(); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = $num; @@ -556,7 +554,7 @@ class TimeSpent extends CommonObject } if (!$error) { - $this->oldref = $this->ref; + $this->oldref = (string) $this->ref; // Rename directory if dir was a temporary ref if (preg_match('/^[\(]?PROV/i', $this->ref)) { diff --git a/htdocs/core/modules/stocktransfer/doc/pdf_eagle.modules.php b/htdocs/core/modules/stocktransfer/doc/pdf_eagle.modules.php index 77b6299e775..8612a7df36f 100644 --- a/htdocs/core/modules/stocktransfer/doc/pdf_eagle.modules.php +++ b/htdocs/core/modules/stocktransfer/doc/pdf_eagle.modules.php @@ -1125,12 +1125,13 @@ class pdf_eagle extends ModelePDFStockTransfer $classname = ucfirst($origin); $linkedobject = new $classname($this->db); '@phan-var-force CommonObject $linkedobject'; + /** @var CommonObject $linkedobject */ $result = $linkedobject->fetch($origin_id); if ($result >= 0) { //$linkedobject->fetchObjectLinked() Get all linked object to the $linkedobject (commonly order) into $linkedobject->linkedObjects $pdf->SetFont('', '', $default_font_size - 2); - $text = $linkedobject->ref; + $text = (string) $linkedobject->ref; if (isset($linkedobject->ref_client) && !empty($linkedobject->ref_client)) { $text .= ' ('.$linkedobject->ref_client.')'; } diff --git a/htdocs/delivery/class/delivery.class.php b/htdocs/delivery/class/delivery.class.php index cca245c94fb..b0747a6b590 100644 --- a/htdocs/delivery/class/delivery.class.php +++ b/htdocs/delivery/class/delivery.class.php @@ -435,7 +435,7 @@ class Delivery extends CommonObject if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life $numref = $objMod->getNextValue($soc, $this); } else { - $numref = $this->ref; + $numref = (string) $this->ref; } $this->newref = dol_sanitizeFileName($numref); diff --git a/htdocs/ecm/class/ecmdirectory.class.php b/htdocs/ecm/class/ecmdirectory.class.php index fba424ffa96..7c332610de6 100644 --- a/htdocs/ecm/class/ecmdirectory.class.php +++ b/htdocs/ecm/class/ecmdirectory.class.php @@ -1,7 +1,7 @@ * Copyright (C) 2008-2012 Regis Houssin - * Copyright (C) 2024 Frédéric France + * Copyright (C) 2024-2025 Frédéric France * Copyright (C) 2024-2025 MDW * * This program is free software; you can redistribute it and/or modify @@ -484,7 +484,7 @@ class EcmDirectory extends CommonObject $result = ''; //$newref=str_replace('_',' ',$this->ref); - $newref = $this->ref; + $newref = (string) $this->ref; $label = img_picto('', $this->picto, '', 0, 0, 0, '', 'paddingrightonly') . $langs->trans("ShowECMSection") . ': ' . $newref; $linkclose = '"'.($more ? ' '.$more : '').' title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index 3ef3809c240..19310398f90 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -2107,7 +2107,7 @@ if ($action == 'create') { if ($objectref == 'PROV') { $numref = $object->getNextNumRef($soc); } else { - $numref = $object->ref; + $numref = (string) $object->ref; } $text = $langs->trans("ConfirmValidateSending", $numref); diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index fe3a76efc65..05b24463507 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -990,7 +990,7 @@ class Expedition extends CommonObject if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life $numref = $this->getNextNumRef($soc); } elseif (!empty($this->ref)) { - $numref = $this->ref; + $numref = (string) $this->ref; } else { $numref = "EXP".$this->id; } diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index 1404b78877e..474f0616fbd 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -1349,7 +1349,7 @@ class ExpenseReport extends CommonObject if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef(); } else { - $num = $this->ref; + $num = (string) $this->ref; } if (empty($num) || $num < 0) { return -1; diff --git a/htdocs/fichinter/card.php b/htdocs/fichinter/card.php index ab4e4fbdcbf..429caf08a04 100644 --- a/htdocs/fichinter/card.php +++ b/htdocs/fichinter/card.php @@ -1210,7 +1210,7 @@ if ($action == 'create') { setEventMessages($object->error, $object->errors, 'errors'); } } else { - $numref = $object->ref; + $numref = (string) $object->ref; } $text = $langs->trans('ConfirmValidateIntervention', $numref); if (isModEnabled('notification')) { diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index 6ff73e295fa..e2eb3255e38 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -639,7 +639,7 @@ class Fichinter extends CommonObject if ((preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef($this->thirdparty); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = dol_sanitizeFileName($num); diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 6783194903e..b11e046f0c0 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -796,7 +796,7 @@ class CommandeFournisseur extends CommonOrder if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef($soc); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = dol_sanitizeFileName($num); @@ -1291,7 +1291,7 @@ class CommandeFournisseur extends CommonOrder if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef($soc); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = dol_sanitizeFileName($num); @@ -2964,7 +2964,7 @@ class CommandeFournisseur extends CommonOrder $ref = ''; if ($prod->fetch($comclient->lines[$i]->fk_product) > 0) { $label = $prod->label; - $ref = $prod->ref; + $ref = (string) $prod->ref; } $sql = "INSERT INTO ".$this->db->prefix()."commande_fournisseurdet"; diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index a3ef6222988..65283c5c2b8 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -1893,7 +1893,7 @@ class FactureFournisseur extends CommonInvoice } elseif (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef($this->thirdparty); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = dol_sanitizeFileName($num); diff --git a/htdocs/fourn/class/fournisseur.product.class.php b/htdocs/fourn/class/fournisseur.product.class.php index 3a2a5af9887..779abdee8ca 100644 --- a/htdocs/fourn/class/fournisseur.product.class.php +++ b/htdocs/fourn/class/fournisseur.product.class.php @@ -1320,7 +1320,7 @@ class ProductFournisseur extends Product $result = ''; $label = ''; - $newref = $this->ref; + $newref = (string) $this->ref; if ($maxlength) { $newref = dol_trunc($newref, $maxlength, 'middle'); } diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index aa798ee72d5..783093cc694 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -3082,7 +3082,7 @@ if ($action == 'create') { // empty should not happened, but when it occurs, the test save life $numref = $object->getNextNumRef($societe); } else { - $numref = $object->ref; + $numref = (string) $object->ref; } if ($numref < 0) { diff --git a/htdocs/holiday/class/holiday.class.php b/htdocs/holiday/class/holiday.class.php index ccce593c959..547913c984b 100644 --- a/htdocs/holiday/class/holiday.class.php +++ b/htdocs/holiday/class/holiday.class.php @@ -789,7 +789,7 @@ class Holiday extends CommonObject if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref) || $this->ref == $this->id)) { $num = $this->getNextNumRef(null); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = dol_sanitizeFileName($num); diff --git a/htdocs/hrm/class/evaluation.class.php b/htdocs/hrm/class/evaluation.class.php index d6a3e5876e6..42e21641671 100644 --- a/htdocs/hrm/class/evaluation.class.php +++ b/htdocs/hrm/class/evaluation.class.php @@ -542,7 +542,7 @@ class Evaluation extends CommonObject if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef(); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = $num; diff --git a/htdocs/hrm/class/job.class.php b/htdocs/hrm/class/job.class.php index de2c922bfe5..3f8efdc3034 100644 --- a/htdocs/hrm/class/job.class.php +++ b/htdocs/hrm/class/job.class.php @@ -480,7 +480,7 @@ class Job extends CommonObject if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef(); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = $num; diff --git a/htdocs/hrm/class/position.class.php b/htdocs/hrm/class/position.class.php index 1a3fb560cdf..d3a1269f5df 100644 --- a/htdocs/hrm/class/position.class.php +++ b/htdocs/hrm/class/position.class.php @@ -537,7 +537,7 @@ class Position extends CommonObject if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef(); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = $num; diff --git a/htdocs/hrm/class/skill.class.php b/htdocs/hrm/class/skill.class.php index 10b405da499..1f526971c5f 100644 --- a/htdocs/hrm/class/skill.class.php +++ b/htdocs/hrm/class/skill.class.php @@ -599,7 +599,7 @@ class Skill extends CommonObject if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef(); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = $num; diff --git a/htdocs/hrm/class/skilldet.class.php b/htdocs/hrm/class/skilldet.class.php index ec8aa4855c3..af6d3413742 100644 --- a/htdocs/hrm/class/skilldet.class.php +++ b/htdocs/hrm/class/skilldet.class.php @@ -504,7 +504,7 @@ class Skilldet extends CommonObjectLine if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef(); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = $num; diff --git a/htdocs/hrm/class/skillrank.class.php b/htdocs/hrm/class/skillrank.class.php index d567583945d..4bbbf20d460 100644 --- a/htdocs/hrm/class/skillrank.class.php +++ b/htdocs/hrm/class/skillrank.class.php @@ -518,7 +518,7 @@ class SkillRank extends CommonObject if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef(); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = $num; diff --git a/htdocs/hrm/evaluation_card.php b/htdocs/hrm/evaluation_card.php index 2208e18ed57..bfd3a62ee85 100644 --- a/htdocs/hrm/evaluation_card.php +++ b/htdocs/hrm/evaluation_card.php @@ -376,7 +376,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea setEventMessages($object->error, $object->errors, 'errors'); } } else { - $numref = $object->ref; + $numref = (string) $object->ref; } $text = $langs->trans('ConfirmValidateEvaluation', $numref); diff --git a/htdocs/knowledgemanagement/class/knowledgerecord.class.php b/htdocs/knowledgemanagement/class/knowledgerecord.class.php index 85c5e5e87b1..22e5ed1a570 100644 --- a/htdocs/knowledgemanagement/class/knowledgerecord.class.php +++ b/htdocs/knowledgemanagement/class/knowledgerecord.class.php @@ -589,7 +589,7 @@ class KnowledgeRecord extends CommonObject if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef(); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = $num; diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index 57d10cfdf4c..65ca63279aa 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -600,7 +600,7 @@ class MyObject extends CommonObject if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef(); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = $num; diff --git a/htdocs/mrp/class/mo.class.php b/htdocs/mrp/class/mo.class.php index e2042a9e9e7..4088b41bbb2 100644 --- a/htdocs/mrp/class/mo.class.php +++ b/htdocs/mrp/class/mo.class.php @@ -1117,7 +1117,7 @@ class Mo extends CommonObject $this->fetch_product(); $num = $this->getNextNumRef($this->product); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = $num; diff --git a/htdocs/mrp/mo_card.php b/htdocs/mrp/mo_card.php index 47d6a4aa502..2d732eee47b 100644 --- a/htdocs/mrp/mo_card.php +++ b/htdocs/mrp/mo_card.php @@ -552,7 +552,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea $object->fetch_product(); $numref = $object->getNextNumRef($object->product); } else { - $numref = $object->ref; + $numref = (string) $object->ref; } $text = $langs->trans('ConfirmValidateMo', $numref); diff --git a/htdocs/mrp/mo_production.php b/htdocs/mrp/mo_production.php index 51f3ebb87af..86e926b1770 100644 --- a/htdocs/mrp/mo_production.php +++ b/htdocs/mrp/mo_production.php @@ -596,7 +596,7 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea $object->fetch_product(); $numref = $object->getNextNumRef($object->product); } else { - $numref = $object->ref; + $numref = (string) $object->ref; } $text = $langs->trans('ConfirmValidateMo', $numref); diff --git a/htdocs/partnership/class/partnership.class.php b/htdocs/partnership/class/partnership.class.php index 50dfac2608d..0add272c1c5 100644 --- a/htdocs/partnership/class/partnership.class.php +++ b/htdocs/partnership/class/partnership.class.php @@ -662,7 +662,7 @@ class Partnership extends CommonObject if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef(); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = $num; @@ -794,7 +794,7 @@ class Partnership extends CommonObject if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef(); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = $num; diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 52685d592f5..33f7a7c7ca2 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -5866,7 +5866,7 @@ class Product extends CommonObject $result = ''; - $newref = $this->ref; + $newref = (string) $this->ref; if ($maxlength) { $newref = dol_trunc($newref, $maxlength, 'middle'); } diff --git a/htdocs/product/class/productfournisseurprice.class.php b/htdocs/product/class/productfournisseurprice.class.php index 10278fe92e9..7a5f5f31cfd 100644 --- a/htdocs/product/class/productfournisseurprice.class.php +++ b/htdocs/product/class/productfournisseurprice.class.php @@ -552,7 +552,7 @@ class ProductFournisseurPrice extends CommonObject if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef(); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = $num; diff --git a/htdocs/product/stock/stocktransfer/class/stocktransfer.class.php b/htdocs/product/stock/stocktransfer/class/stocktransfer.class.php index 694f75aa611..522d34976bf 100644 --- a/htdocs/product/stock/stocktransfer/class/stocktransfer.class.php +++ b/htdocs/product/stock/stocktransfer/class/stocktransfer.class.php @@ -615,7 +615,7 @@ class StockTransfer extends CommonObject if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef(); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = $num; diff --git a/htdocs/product/stock/stocktransfer/class/stocktransferline.class.php b/htdocs/product/stock/stocktransfer/class/stocktransferline.class.php index 0356f82e569..aa15f0b124c 100644 --- a/htdocs/product/stock/stocktransfer/class/stocktransferline.class.php +++ b/htdocs/product/stock/stocktransfer/class/stocktransferline.class.php @@ -545,7 +545,7 @@ class StockTransferLine extends CommonObjectLine if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef(); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = $num; diff --git a/htdocs/product/stock/tpl/stockcorrection.tpl.php b/htdocs/product/stock/tpl/stockcorrection.tpl.php index 19d23ff7b5d..a5d9154c9f6 100644 --- a/htdocs/product/stock/tpl/stockcorrection.tpl.php +++ b/htdocs/product/stock/tpl/stockcorrection.tpl.php @@ -1,6 +1,6 @@ - * Copyright (C) 2018-2024 Frédéric France + * Copyright (C) 2018-2025 Frédéric France * Copyright (C) 2024-2025 MDW * * This program is free software; you can redistribute it and/or modify @@ -52,7 +52,7 @@ if (empty($conf) || !is_object($conf)) { $productref = ''; if ($object->element == 'product') { /** @var Product $object */ - $productref = $object->ref; + $productref = (string) $object->ref; } $langs->load("productbatch"); diff --git a/htdocs/product/stock/tpl/stocktransfer.tpl.php b/htdocs/product/stock/tpl/stocktransfer.tpl.php index 35bad85a584..f95e6099608 100644 --- a/htdocs/product/stock/tpl/stocktransfer.tpl.php +++ b/htdocs/product/stock/tpl/stocktransfer.tpl.php @@ -1,6 +1,6 @@ - * Copyright (C) 2018-2024 Frédéric France + * Copyright (C) 2018-2025 Frédéric France * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify @@ -50,7 +50,7 @@ if (empty($conf) || !is_object($conf)) { $productref = ''; if ($object->element == 'product') { /** @var Product $object */ - $productref = $object->ref; + $productref = (string) $object->ref; } $langs->load("productbatch"); diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 660d4abfb63..8972ef84140 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -854,7 +854,7 @@ class Project extends CommonObject } } - return $substitution; + return (string) $substitution; } // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps diff --git a/htdocs/projet/tasks/task.php b/htdocs/projet/tasks/task.php index 2a6196022b6..cc092cc600d 100644 --- a/htdocs/projet/tasks/task.php +++ b/htdocs/projet/tasks/task.php @@ -2,7 +2,7 @@ /* Copyright (C) 2005 Rodolphe Quiedeville * Copyright (C) 2006-2017 Laurent Destailleur * Copyright (C) 2010-2012 Regis Houssin - * Copyright (C) 2018-2024 Frédéric France + * Copyright (C) 2018-2025 Frédéric France * Copyright (C) 2024-2025 MDW * Copyright (C) 2024 Vincent de Grandpré * @@ -307,7 +307,7 @@ $formother = new FormOther($db); $formfile = new FormFile($db); $formproject = new FormProjets($db); -$title = $object->ref; +$title = (string) $object->ref; if (!empty($withproject)) { $title .= ' | ' . $langs->trans("Project") . (!empty($projectstatic->ref) ? ': '.$projectstatic->ref : '') ; } diff --git a/htdocs/public/website/index.php b/htdocs/public/website/index.php index 68875b3ec06..53b014c4d53 100644 --- a/htdocs/public/website/index.php +++ b/htdocs/public/website/index.php @@ -1,7 +1,7 @@ * Copyright (C) 2024-2025 MDW - * Copyright (C) 2024 Frédéric France + * Copyright (C) 2024-2025 Frédéric France * * 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 @@ -184,7 +184,7 @@ if (empty($pageref)) { $objectpage = new WebsitePage($db); $result = $objectpage->fetch($pageid); if ($result > 0) { - $pageref = $objectpage->ref; + $pageref = (string) $objectpage->ref; } } if (preg_match('/^_(library|service)_page_/', $pageref)) { diff --git a/htdocs/reception/card.php b/htdocs/reception/card.php index aa33a07a28c..ffd32fd39db 100644 --- a/htdocs/reception/card.php +++ b/htdocs/reception/card.php @@ -1425,7 +1425,7 @@ if ($action == 'create') { if ($objectref == 'PROV') { $numref = $object->getNextNumRef($soc); } else { - $numref = $object->ref; + $numref = (string) $object->ref; } $text = $langs->trans("ConfirmValidateReception", $numref); diff --git a/htdocs/reception/class/reception.class.php b/htdocs/reception/class/reception.class.php index a6a645e8b60..a0091e8df70 100644 --- a/htdocs/reception/class/reception.class.php +++ b/htdocs/reception/class/reception.class.php @@ -588,7 +588,7 @@ class Reception extends CommonObject if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life $numref = $this->getNextNumRef($soc); } else { - $numref = $this->ref; + $numref = (string) $this->ref; } $this->newref = dol_sanitizeFileName($numref); @@ -1889,7 +1889,7 @@ class Reception extends CommonObject // If stock increment is done on closing if (!$error && isModEnabled('stock') && getDolGlobalInt('STOCK_CALCULATE_ON_RECEPTION_CLOSE')) { require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; - $numref = $this->ref; + $numref = (string) $this->ref; $langs->load("agenda"); // Loop on each product line to add a stock movement diff --git a/htdocs/recruitment/class/recruitmentcandidature.class.php b/htdocs/recruitment/class/recruitmentcandidature.class.php index 883f4923ed3..ef4e56ba994 100644 --- a/htdocs/recruitment/class/recruitmentcandidature.class.php +++ b/htdocs/recruitment/class/recruitmentcandidature.class.php @@ -550,7 +550,7 @@ class RecruitmentCandidature extends CommonObject if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef(); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = $num; diff --git a/htdocs/recruitment/class/recruitmentjobposition.class.php b/htdocs/recruitment/class/recruitmentjobposition.class.php index 4e2533d5e01..e74023e626b 100644 --- a/htdocs/recruitment/class/recruitmentjobposition.class.php +++ b/htdocs/recruitment/class/recruitmentjobposition.class.php @@ -556,7 +556,7 @@ class RecruitmentJobPosition extends CommonObject if (/* !$error && */ (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef(); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = $num; diff --git a/htdocs/supplier_proposal/card.php b/htdocs/supplier_proposal/card.php index d6fa84fb30e..c6da85e75eb 100644 --- a/htdocs/supplier_proposal/card.php +++ b/htdocs/supplier_proposal/card.php @@ -1605,7 +1605,7 @@ if ($action == 'create') { setEventMessages($object->error, $object->errors, 'errors'); } } else { - $numref = $object->ref; + $numref = (string) $object->ref; } $text = $langs->trans('ConfirmValidateAsk', $numref); diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php index 1805d3b9883..6c2387f2148 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -1459,7 +1459,7 @@ class SupplierProposal extends CommonObject if (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref)) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef($soc); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = dol_sanitizeFileName($num); diff --git a/htdocs/variants/combinations.php b/htdocs/variants/combinations.php index 76393d921e2..444bf419574 100644 --- a/htdocs/variants/combinations.php +++ b/htdocs/variants/combinations.php @@ -1,7 +1,7 @@ * Copyright (C) 2017 Laurent Destailleur - * Copyright (C) 2018-2024 Frédéric France + * Copyright (C) 2018-2025 Frédéric France * Copyright (C) 2022 Open-Dsi * Copyright (C) 2024-2025 MDW * @@ -374,7 +374,7 @@ if ($action === 'confirm_deletecombination' && $usercancreate) { $product_child = new Product($db); $product_child->fetch($prodcomb->fk_product_child); - $reference = $product_child->ref; + $reference = (string) $product_child->ref; $weight_impact = $prodcomb->variation_weight; $price_impact = $prodcomb->variation_price; $price_impact_percent = $prodcomb->variation_price_percentage; diff --git a/htdocs/webhook/class/target.class.php b/htdocs/webhook/class/target.class.php index 30faa14f1b7..a27ee32e73f 100644 --- a/htdocs/webhook/class/target.class.php +++ b/htdocs/webhook/class/target.class.php @@ -596,7 +596,7 @@ class Target extends CommonObject if (!$error && (preg_match('/^[\(]?PROV/i', $this->ref) || empty($this->ref))) { // empty should not happened, but when it occurs, the test save life $num = $this->getNextNumRef(); } else { - $num = $this->ref; + $num = (string) $this->ref; } $this->newref = $num; diff --git a/htdocs/webportal/class/html.formwebportal.class.php b/htdocs/webportal/class/html.formwebportal.class.php index 04d2e2ca9a0..3807dbcb5e1 100644 --- a/htdocs/webportal/class/html.formwebportal.class.php +++ b/htdocs/webportal/class/html.formwebportal.class.php @@ -3,7 +3,7 @@ * Copyright (C) 2023-2024 Lionel Vessiller * Copyright (C) 2023-2024 Patrice Andreani * Copyright (C) 2024-2025 MDW - * Copyright (C) 2024 Frédéric France + * Copyright (C) 2024-2025 Frédéric France * * 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 @@ -1077,7 +1077,7 @@ class FormWebPortal extends Form // if (in_array($key, array('rowid', 'ref'))) { if (property_exists($object, 'ref')) { - $value = $object->ref; + $value = (string) $object->ref; } elseif (property_exists($object, 'id')) { $value = $object->id; } else { @@ -1357,15 +1357,16 @@ class FormWebPortal extends Form if ($classname && class_exists($classname)) { $object = new $classname($this->db); '@phan-var-force CommonObject $object'; + /** @var CommonObject $object */ $result = $object->fetch($value); $value = ''; if ($result > 0) { if (property_exists($object, 'label')) { - $value = $object->label; // @phan-suppress-current-line PhanUndeclaredProperty + $value = (string) $object->label; // @phan-suppress-current-line PhanUndeclaredProperty } elseif (property_exists($object, 'libelle')) { - $value = $object->libelle; // @phan-suppress-current-line PhanUndeclaredProperty + $value = (string) $object->libelle; // @phan-suppress-current-line PhanUndeclaredProperty } elseif (property_exists($object, 'nom')) { - $value = $object->nom; // @phan-suppress-current-line PhanUndeclaredProperty + $value = (string) $object->nom; // @phan-suppress-current-line PhanUndeclaredProperty } } }