diff --git a/dev/build/phpstan/phpstan-baseline.neon b/dev/build/phpstan/phpstan-baseline.neon index 58f2d47be74..4e09e7bae45 100644 --- a/dev/build/phpstan/phpstan-baseline.neon +++ b/dev/build/phpstan/phpstan-baseline.neon @@ -11640,12 +11640,6 @@ parameters: count: 1 path: ../../../htdocs/main.inc.php - - - message: '#^Ternary operator condition is always false\.$#' - identifier: ternary.alwaysFalse - count: 1 - path: ../../../htdocs/main.inc.php - - message: '#^Ternary operator condition is always true\.$#' identifier: ternary.alwaysTrue @@ -11952,12 +11946,6 @@ parameters: count: 1 path: ../../../htdocs/modulebuilder/template/class/myobject.class.php - - - message: '#^Variable \$url in empty\(\) always exists and is not falsy\.$#' - identifier: empty.variable - count: 2 - path: ../../../htdocs/modulebuilder/template/class/myobject.class.php - - message: '#^If condition is always false\.$#' identifier: if.alwaysFalse @@ -12390,48 +12378,12 @@ parameters: count: 1 path: ../../../htdocs/opensurvey/class/opensurveysondage.class.php - - - message: '#^Property Opensurveysondage\:\:\$format \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/opensurvey/class/opensurveysondage.class.php - - message: '#^Property Opensurveysondage\:\:\$id_sondage \(string\) in isset\(\) is not nullable\.$#' identifier: isset.property count: 1 path: ../../../htdocs/opensurvey/class/opensurveysondage.class.php - - - message: '#^Property Opensurveysondage\:\:\$mail_admin \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/opensurvey/class/opensurveysondage.class.php - - - - message: '#^Property Opensurveysondage\:\:\$mailsonde \(int\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/opensurvey/class/opensurveysondage.class.php - - - - message: '#^Property Opensurveysondage\:\:\$nom_admin \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/opensurvey/class/opensurveysondage.class.php - - - - message: '#^Property Opensurveysondage\:\:\$status \(int\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/opensurvey/class/opensurveysondage.class.php - - - - message: '#^Property Opensurveysondage\:\:\$title \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/opensurvey/class/opensurveysondage.class.php - - message: '#^Offset int\<0, max\> on array\, int\<0, max\>\> in isset\(\) always exists and is not nullable\.$#' identifier: isset.offset diff --git a/htdocs/asset/class/assetmodel.class.php b/htdocs/asset/class/assetmodel.class.php index 4031f3c926b..a53e838dfe6 100644 --- a/htdocs/asset/class/assetmodel.class.php +++ b/htdocs/asset/class/assetmodel.class.php @@ -306,8 +306,7 @@ class AssetModel extends CommonObject $result = $object->createCommon($user); if ($result < 0) { $error++; - $this->error = $object->error; - $this->errors = $object->errors; + $this->setErrorsFromObject($object); } if (!$error) { diff --git a/htdocs/bom/class/bom.class.php b/htdocs/bom/class/bom.class.php index 6ecbfb01ce4..f6cbfa46a67 100644 --- a/htdocs/bom/class/bom.class.php +++ b/htdocs/bom/class/bom.class.php @@ -369,8 +369,7 @@ class BOM extends CommonObject $result = $object->createCommon($user); if ($result < 0) { $error++; - $this->error = $object->error; - $this->errors = $object->errors; + $this->setErrorsFromObject($object); } if (!$error) { diff --git a/htdocs/bookcal/class/availabilities.class.php b/htdocs/bookcal/class/availabilities.class.php index 5da3e3c04f7..a149ab1a444 100644 --- a/htdocs/bookcal/class/availabilities.class.php +++ b/htdocs/bookcal/class/availabilities.class.php @@ -315,8 +315,7 @@ class Availabilities extends CommonObject $result = $object->createCommon($user); if ($result < 0) { $error++; - $this->error = $object->error; - $this->errors = $object->errors; + $this->setErrorsFromObject($object); } if (!$error) { diff --git a/htdocs/comm/mailing/class/mailing.class.php b/htdocs/comm/mailing/class/mailing.class.php index 025f06850b4..b2b219205fd 100644 --- a/htdocs/comm/mailing/class/mailing.class.php +++ b/htdocs/comm/mailing/class/mailing.class.php @@ -2,7 +2,7 @@ /* Copyright (C) 2005 Rodolphe Quiedeville * Copyright (C) 2005-2016 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin - * Copyright (C) 2024 Frédéric France + * Copyright (C) 2024-2025 Frédéric France * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify @@ -517,8 +517,7 @@ class Mailing extends CommonObject // Other options if ($result < 0) { - $this->error = $object->error; - $this->errors = array_merge($this->errors, $object->errors); + $this->setErrorsFromObject($object); $error++; } diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 45b326dd043..b2c060944f8 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -1355,20 +1355,17 @@ class Facture extends CommonInvoice $result = $object->create($user); if ($result < 0) { $error++; - $this->error = $object->error; - $this->errors = $object->errors; + $this->setErrorsFromObject($object); } else { // copy internal contacts if ($object->copy_linked_contact($objFrom, 'internal') < 0) { $error++; - $this->error = $object->error; - $this->errors = $object->errors; + $this->setErrorsFromObject($object); } elseif ($object->socid == $objFrom->socid) { // copy external contacts if same company if ($object->copy_linked_contact($objFrom, 'external') < 0) { $error++; - $this->error = $object->error; - $this->errors = $object->errors; + $this->setErrorsFromObject($object); } } } diff --git a/htdocs/compta/sociales/class/paymentsocialcontribution.class.php b/htdocs/compta/sociales/class/paymentsocialcontribution.class.php index 281d342df20..8a270f832f2 100644 --- a/htdocs/compta/sociales/class/paymentsocialcontribution.class.php +++ b/htdocs/compta/sociales/class/paymentsocialcontribution.class.php @@ -2,7 +2,7 @@ /* Copyright (C) 2002 Rodolphe Quiedeville * Copyright (C) 2004-2007 Laurent Destailleur * Copyright (C) 2022 Alexandre Spangaro - * Copyright (C) 2024 Frédéric France + * Copyright (C) 2024-2025 Frédéric France * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify @@ -515,7 +515,7 @@ class PaymentSocialContribution extends CommonObject // Other options if ($result < 0) { - $this->error = $object->error; + $this->setErrorsFromObject($object); $error++; } diff --git a/htdocs/compta/tva/class/paymentvat.class.php b/htdocs/compta/tva/class/paymentvat.class.php index 77893f543b0..cdc638e1f1c 100644 --- a/htdocs/compta/tva/class/paymentvat.class.php +++ b/htdocs/compta/tva/class/paymentvat.class.php @@ -2,7 +2,7 @@ /* Copyright (C) 2002 Rodolphe Quiedeville * Copyright (C) 2004-2007 Laurent Destailleur * Copyright (C) 2021 Gauthier VERDOL - * Copyright (C) 2024 Frédéric France + * Copyright (C) 2024-2025 Frédéric France * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify @@ -512,6 +512,7 @@ class PaymentVAT extends CommonObject // Load source object $object->fetch($fromid); $object->id = 0; + $object->status = 0; $object->statut = 0; // Clear fields diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 1ff35bd7fa0..7b85beaaa9e 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -119,7 +119,7 @@ abstract class CommonObject public $table_element; /** - * @var string Name of id column + * @var ?string Name of id column */ public $table_rowid; diff --git a/htdocs/core/class/defaultvalues.class.php b/htdocs/core/class/defaultvalues.class.php index cd609389f23..02ac56013cd 100644 --- a/htdocs/core/class/defaultvalues.class.php +++ b/htdocs/core/class/defaultvalues.class.php @@ -205,8 +205,7 @@ class DefaultValues extends CommonObject $result = $object->createCommon($user); if ($result < 0) { $error++; - $this->error = $object->error; - $this->errors = $object->errors; + $this->setErrorsFromObject($object); } unset($object->context['createfromclone']); diff --git a/htdocs/don/class/paymentdonation.class.php b/htdocs/don/class/paymentdonation.class.php index 2bb9e094302..ce940637d9b 100644 --- a/htdocs/don/class/paymentdonation.class.php +++ b/htdocs/don/class/paymentdonation.class.php @@ -520,7 +520,7 @@ class PaymentDonation extends CommonObject // Other options if ($result < 0) { - $this->error = $object->error; + $this->setErrorsFromObject($object); $error++; } diff --git a/htdocs/emailcollector/class/emailcollector.class.php b/htdocs/emailcollector/class/emailcollector.class.php index 89068b51fde..ed0aeadd769 100644 --- a/htdocs/emailcollector/class/emailcollector.class.php +++ b/htdocs/emailcollector/class/emailcollector.class.php @@ -445,8 +445,7 @@ class EmailCollector extends CommonObject $result = $object->create($user); if ($result < 0) { $error++; - $this->error = $object->error; - $this->errors = $object->errors; + $this->setErrorsFromObject($object); } unset($object->context['createfromclone']); diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 1956e6b589c..c7392377d89 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -13,7 +13,7 @@ * Copyright (C) 2015 Raphaël Doursenaud * Copyright (C) 2020 Demarest Maxime * Copyright (C) 2020-2024 Charlene Benke - * Copyright (C) 2021-2024 Frédéric France + * Copyright (C) 2021-2025 Frédéric France * Copyright (C) 2021 Alexandre Spangaro * Copyright (C) 2023 Joachim Küter * Copyright (C) 2023 Eric Seigne @@ -536,8 +536,7 @@ if (!defined('NOLOGIN')) { if (!empty($dolibarr_main_demo) && $_SERVER['PHP_SELF'] == DOL_URL_ROOT.'/index.php') { // We ask index page if (empty($_SERVER['HTTP_REFERER']) || !preg_match('/public/', $_SERVER['HTTP_REFERER'])) { dol_syslog("Call index page from another url than demo page (call is done from page ".(empty($_SERVER['HTTP_REFERER']) ? '' : $_SERVER['HTTP_REFERER']).")"); - $url = ''; - $url .= ($url ? '&' : '').($dol_hide_topmenu ? 'dol_hide_topmenu='.$dol_hide_topmenu : ''); + $url = ($dol_hide_topmenu ? 'dol_hide_topmenu='.$dol_hide_topmenu : ''); $url .= ($url ? '&' : '').($dol_hide_leftmenu ? 'dol_hide_leftmenu='.$dol_hide_leftmenu : ''); $url .= ($url ? '&' : '').($dol_optimize_smallscreen ? 'dol_optimize_smallscreen='.$dol_optimize_smallscreen : ''); $url .= ($url ? '&' : '').($dol_no_mouse_hover ? 'dol_no_mouse_hover='.$dol_no_mouse_hover : ''); diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index c9c7241f749..24ad4c37b86 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -860,13 +860,13 @@ class MyObject extends CommonObject $linkclose = ($morecss ? ' class="'.$morecss.'"' : ''); } - if ($option == 'nolink' || empty($url)) { + if ($option == 'nolink') { $linkstart = ''; - if ($option == 'nolink' || empty($url)) { + if ($option == 'nolink') { $linkend = ''; } else { $linkend = ''; diff --git a/htdocs/opensurvey/class/opensurveysondage.class.php b/htdocs/opensurvey/class/opensurveysondage.class.php index 60bd73b9b58..b591c0dceed 100644 --- a/htdocs/opensurvey/class/opensurveysondage.class.php +++ b/htdocs/opensurvey/class/opensurveysondage.class.php @@ -44,6 +44,11 @@ class Opensurveysondage extends CommonObject */ public $table_element = 'opensurvey_sondage'; + /** + * @var string + */ + public $table_rowid = 'id_sondage'; + /** * @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png */ @@ -141,12 +146,12 @@ class Opensurveysondage extends CommonObject public $commentaires; /** - * @var string admin mail + * @var ?string admin mail */ public $mail_admin; /** - * @var string admin name + * @var ?string admin name */ public $nom_admin; @@ -156,13 +161,13 @@ class Opensurveysondage extends CommonObject public $fk_user_creat; /** - * @var string title of survey + * @var ?string title of survey * @deprecated Rename the field titre into title into the table to allow to change this in fields and remove this declaration. */ public $titre; /** - * @var string title of survey + * @var ?string title of survey */ public $title; @@ -170,28 +175,29 @@ class Opensurveysondage extends CommonObject * @var int|'' end date of survey */ public $date_fin = ''; + /** - * @var int + * @var ?int */ public $status; /** - * @var string format 'A' = Text choice (choices are saved into sujet field), 'D' = Date choice (choices are saved into sujet field), 'F' = Form survey + * @var ?string format 'A' = Text choice (choices are saved into sujet field), 'D' = Date choice (choices are saved into sujet field), 'F' = Form survey */ public $format; /** - * @var int to allow send mail + * @var ?int to allow send mail */ public $mailsonde; /** - * @var int Allow comments on this poll + * @var ?int Allow comments on this poll */ public $allow_comments; /** - * @var int Allow users see others vote + * @var ?int Allow users see others vote */ public $allow_spy; @@ -272,10 +278,10 @@ class Opensurveysondage extends CommonObject $sql .= "'".$this->db->escape($this->id_sondage)."',"; $sql .= " ".(empty($this->description) ? 'NULL' : "'".$this->db->escape($this->description)."'").","; $sql .= " ".(int) $user->id.","; - $sql .= " '".$this->db->escape($this->title)."',"; + $sql .= " '".$this->db->escape((string) $this->title)."',"; $sql .= " '".$this->db->idate($this->date_fin)."',"; $sql .= " ".(int) $this->status.","; - $sql .= " '".$this->db->escape($this->format)."',"; + $sql .= " '".$this->db->escape((string) $this->format)."',"; $sql .= " ".((int) $this->mailsonde).","; $sql .= " ".((int) $this->allow_comments).","; $sql .= " ".((int) $this->allow_spy).","; diff --git a/htdocs/product/class/productbatch.class.php b/htdocs/product/class/productbatch.class.php index 7ac2a896fe1..8f3ef7185f6 100644 --- a/htdocs/product/class/productbatch.class.php +++ b/htdocs/product/class/productbatch.class.php @@ -1,7 +1,7 @@ * Copyright (C) 2013-2014 Cedric GROSS - * Copyright (C) 2024 Frédéric France + * Copyright (C) 2024-2025 Frédéric France * Copyright (C) 2024 Ferran Marcet * Copyright (C) 2024-2025 MDW * @@ -335,8 +335,7 @@ class Productbatch extends CommonObject // Other options if ($result < 0) { - $this->error = $object->error; - $this->errors = array_merge($this->errors, $object->errors); + $this->setErrorsFromObject($object); $error++; } diff --git a/htdocs/product/class/productcustomerprice.class.php b/htdocs/product/class/productcustomerprice.class.php index b211eb45224..2c4e0edeee2 100644 --- a/htdocs/product/class/productcustomerprice.class.php +++ b/htdocs/product/class/productcustomerprice.class.php @@ -1,7 +1,7 @@ * Copyright (C) 2014 Florian Henry - * 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 @@ -1162,8 +1162,7 @@ class ProductCustomerPrice extends CommonObject // Other options if ($result < 0) { - $this->error = $object->error; - $this->errors = array_merge($this->errors, $object->errors); + $this->setErrorsFromObject($object); $error++; } diff --git a/htdocs/product/class/productfournisseurprice.class.php b/htdocs/product/class/productfournisseurprice.class.php index 2b1ea94008b..db5cc124807 100644 --- a/htdocs/product/class/productfournisseurprice.class.php +++ b/htdocs/product/class/productfournisseurprice.class.php @@ -366,8 +366,7 @@ class ProductFournisseurPrice extends CommonObject $result = $object->createCommon($user); if ($result < 0) { $error++; - $this->error = $object->error; - $this->errors = $object->errors; + $this->setErrorsFromObject($object); } if (!$error) { diff --git a/htdocs/product/inventory/class/inventory.class.php b/htdocs/product/inventory/class/inventory.class.php index 5019089b4ea..3e26d842228 100644 --- a/htdocs/product/inventory/class/inventory.class.php +++ b/htdocs/product/inventory/class/inventory.class.php @@ -478,8 +478,7 @@ class Inventory extends CommonObject $result = $object->createCommon($user); if ($result < 0) { $error++; - $this->error = $object->error; - $this->errors = $object->errors; + $this->setErrorsFromObject($object); } unset($object->context['createfromclone']); diff --git a/htdocs/product/stock/class/mouvementstock.class.php b/htdocs/product/stock/class/mouvementstock.class.php index cfc7563fcf0..f73e044add9 100644 --- a/htdocs/product/stock/class/mouvementstock.class.php +++ b/htdocs/product/stock/class/mouvementstock.class.php @@ -309,8 +309,7 @@ class MouvementStock extends CommonObject $result = $product->fetch($fk_product); if ($result < 0) { - $this->error = $product->error; - $this->errors = $product->errors; + $this->setErrorsFromObject($product); dol_print_error(null, "Failed to fetch product"); return -1; } diff --git a/htdocs/product/stock/stocktransfer/class/stocktransferline.class.php b/htdocs/product/stock/stocktransfer/class/stocktransferline.class.php index aa15f0b124c..c62f365936a 100644 --- a/htdocs/product/stock/stocktransfer/class/stocktransferline.class.php +++ b/htdocs/product/stock/stocktransfer/class/stocktransferline.class.php @@ -250,8 +250,7 @@ class StockTransferLine extends CommonObjectLine $result = $object->createCommon($user); if ($result < 0) { $error++; - $this->error = $object->error; - $this->errors = $object->errors; + $this->setErrorsFromObject($object); } if (!$error) { diff --git a/htdocs/reception/class/receptionlinebatch.class.php b/htdocs/reception/class/receptionlinebatch.class.php index a477bb678f5..6cfb7f9c3e3 100644 --- a/htdocs/reception/class/receptionlinebatch.class.php +++ b/htdocs/reception/class/receptionlinebatch.class.php @@ -586,6 +586,7 @@ class ReceptionLineBatch extends CommonObjectLine // Load source object $object->fetch($fromid); $object->id = 0; + $object->status = 0; $object->statut = 0; // Clear fields @@ -597,7 +598,7 @@ class ReceptionLineBatch extends CommonObjectLine // Other options if ($result < 0) { - $this->error = $object->error; + $this->setErrorsFromObject($object); $error++; } diff --git a/htdocs/ticket/class/cticketcategory.class.php b/htdocs/ticket/class/cticketcategory.class.php index 334fdcc6fae..298f29764b0 100644 --- a/htdocs/ticket/class/cticketcategory.class.php +++ b/htdocs/ticket/class/cticketcategory.class.php @@ -278,8 +278,7 @@ class CTicketCategory extends CommonObject $result = $object->createCommon($user); if ($result < 0) { $error++; - $this->error = $object->error; - $this->errors = $object->errors; + $this->setErrorsFromObject($object); } if (!$error) { diff --git a/htdocs/website/class/website.class.php b/htdocs/website/class/website.class.php index e9210d3c74d..1cce18ca181 100644 --- a/htdocs/website/class/website.class.php +++ b/htdocs/website/class/website.class.php @@ -786,8 +786,7 @@ class Website extends CommonObject $result = $object->create($user); if ($result < 0) { $error++; - $this->error = $object->error; - $this->errors = $object->errors; + $this->setErrorsFromObject($object); dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR); } diff --git a/htdocs/website/class/websitepage.class.php b/htdocs/website/class/websitepage.class.php index f358eb10306..437f21029af 100644 --- a/htdocs/website/class/websitepage.class.php +++ b/htdocs/website/class/websitepage.class.php @@ -829,8 +829,7 @@ class WebsitePage extends CommonObject $result = $object->create($user); if ($result < 0) { $error++; - $this->error = $object->error; - $this->errors = $object->errors; + $this->setErrorsFromObject($object); dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR); } diff --git a/htdocs/workstation/class/workstation.class.php b/htdocs/workstation/class/workstation.class.php index 41427e04313..6ce132d16df 100644 --- a/htdocs/workstation/class/workstation.class.php +++ b/htdocs/workstation/class/workstation.class.php @@ -320,8 +320,7 @@ class Workstation extends CommonObject $result = $object->create($user); if ($result < 0) { $error++; - $this->error = $object->error; - $this->errors = $object->errors; + $this->setErrorsFromObject($object); } if (!$error) { diff --git a/htdocs/zapier/class/hook.class.php b/htdocs/zapier/class/hook.class.php index 724ce4c5a68..f36dcd6e16a 100644 --- a/htdocs/zapier/class/hook.class.php +++ b/htdocs/zapier/class/hook.class.php @@ -324,8 +324,7 @@ class Hook extends CommonObject $result = $object->createCommon($user); if ($result < 0) { $error++; - $this->error = $object->error; - $this->errors = $object->errors; + $this->setErrorsFromObject($object); } unset($object->context['createfromclone']);