diff --git a/dev/build/phpstan/phpstan-baseline.neon b/dev/build/phpstan/phpstan-baseline.neon index feeee73df53..a825625573e 100644 --- a/dev/build/phpstan/phpstan-baseline.neon +++ b/dev/build/phpstan/phpstan-baseline.neon @@ -2502,48 +2502,6 @@ parameters: count: 1 path: ../../../htdocs/commande/class/api_orders.class.php - - - message: '#^Negated boolean expression is always true\.$#' - identifier: booleanNot.alwaysTrue - count: 5 - path: ../../../htdocs/commande/class/commande.class.php - - - - message: '#^Property Commande\:\:\$mode_reglement_id \(int\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/commande/class/commande.class.php - - - - message: '#^Property Commande\:\:\$ref_client \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: ../../../htdocs/commande/class/commande.class.php - - - - message: '#^Property Commande\:\:\$ref_customer \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/commande/class/commande.class.php - - - - message: '#^Property Commande\:\:\$socid \(int\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/commande/class/commande.class.php - - - - message: '#^Right side of && is always true\.$#' - identifier: booleanAnd.rightAlwaysTrue - count: 2 - path: ../../../htdocs/commande/class/commande.class.php - - - - message: '#^Negated boolean expression is always true\.$#' - identifier: booleanNot.alwaysTrue - count: 2 - path: ../../../htdocs/commande/class/orderline.class.php - - message: '#^Variable \$socid might not be defined\.$#' identifier: variable.undefined diff --git a/dev/tools/phan/config.php b/dev/tools/phan/config.php index 6c2270351be..e6670afe368 100644 --- a/dev/tools/phan/config.php +++ b/dev/tools/phan/config.php @@ -1,6 +1,6 @@ - * Copyright (C) 2024 Frédéric France + * Copyright (C) 2024-2025 Frédéric France * * This is the phan config file used by .github/workflows/phan.yml */ diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 70bce59f557..e890c721790 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -100,17 +100,17 @@ class Commande extends CommonOrder protected $table_ref_field = 'ref'; /** - * @var int Thirdparty ID + * @var ?int Thirdparty ID */ public $socid; /** - * @var string Thirdparty ref of order + * @var ?string Thirdparty ref of order */ public $ref_client; /** - * @var string Thirdparty ref of order + * @var ?string Thirdparty ref of order */ public $ref_customer; @@ -169,7 +169,7 @@ class Commande extends CommonOrder public $mode_reglement; /** - * @var int Payment mode id + * @var ?int Payment mode id */ public $mode_reglement_id; @@ -525,6 +525,10 @@ class Commande extends CommonOrder dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR); return -1; } + if (empty($this->socid)) { + $this->error = 'ErrorWrongParameters'; + return -1; + } $now = dol_now(); @@ -538,7 +542,7 @@ class Commande extends CommonOrder $result = $soc->setAsCustomer(); // 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 + 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 = (string) $this->ref; @@ -695,9 +699,7 @@ class Commande extends CommonOrder $sql .= " WHERE rowid = ".((int) $this->id); if ($this->db->query($sql)) { - if (!$error) { - $this->oldcopy = clone $this; - } + $this->oldcopy = clone $this; // If stock is decremented on validate order, we must reincrement it if (isModEnabled('stock') && getDolGlobalInt('STOCK_CALCULATE_ON_VALIDATE_ORDER') == 1) { @@ -919,7 +921,7 @@ class Commande extends CommonOrder $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, 0, $langs->trans("OrderCanceledInDolibarr", $this->ref)); // price is 0, we don't want WAP to be changed if ($result < 0) { $error++; - $this->error = $mouvP->error; + $this->setErrorsFromObject($mouvP); break; } } @@ -970,6 +972,11 @@ class Commande extends CommonOrder // Clean parameters + if (empty($this->socid)) { + $this->error = 'ErrorWrongParameters'; + return -1; + } + // Set tmp vars $date = ($this->date_commande ? $this->date_commande : $this->date); $this->import_key = trim((string) $this->import_key); @@ -1174,7 +1181,7 @@ class Commande extends CommonOrder } // Add object linked - if (!$error && $this->id && !empty($this->linked_objects) && is_array($this->linked_objects)) { + if (!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) { @@ -1195,7 +1202,7 @@ class Commande extends CommonOrder } } - if (!$error && $this->id && getDolGlobalString('MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN') && !empty($this->origin) && !empty($this->origin_id)) { // Get contact from origin object + if (!$error && getDolGlobalString('MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN') && !empty($this->origin) && !empty($this->origin_id)) { // Get contact from origin object $originforcontact = empty($this->origin_type) ? $this->origin : $this->origin_type; $originidforcontact = $this->origin_id; if ($originforcontact == 'shipping') { // shipment and order share the same contacts. If creating from shipment we take data of order @@ -3007,10 +3014,8 @@ class Commande extends CommonOrder dol_syslog(get_class($this)."::classifyBilled", LOG_DEBUG); if ($this->db->query($sql)) { - if (!$error) { - $this->oldcopy = clone $this; - $this->billed = 1; - } + $this->oldcopy = clone $this; + $this->billed = 1; if (!$notrigger && empty($error)) { // Call trigger @@ -3057,10 +3062,8 @@ class Commande extends CommonOrder dol_syslog(get_class($this)."::classifyUnBilled", LOG_DEBUG); if ($this->db->query($sql)) { - if (!$error) { - $this->oldcopy = clone $this; - $this->billed = 1; - } + $this->oldcopy = clone $this; + $this->billed = 1; if (!$notrigger && empty($error)) { // Call trigger diff --git a/htdocs/commande/class/orderline.class.php b/htdocs/commande/class/orderline.class.php index a5ca253bbdd..a333f17733b 100644 --- a/htdocs/commande/class/orderline.class.php +++ b/htdocs/commande/class/orderline.class.php @@ -508,11 +508,9 @@ class OrderLine extends CommonOrderLine $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'commandedet'); $this->rowid = $this->id; - if (!$error) { - $result = $this->insertExtraFields(); - if ($result < 0) { - $error++; - } + $result = $this->insertExtraFields(); + if ($result < 0) { + $error++; } if (!$error && !$notrigger) { @@ -673,12 +671,10 @@ class OrderLine extends CommonOrderLine dol_syslog(get_class($this)."::update", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { - if (!$error) { - $this->id = $this->rowid; - $result = $this->insertExtraFields(); - if ($result < 0) { - $error++; - } + $this->id = $this->rowid; + $result = $this->insertExtraFields(); + if ($result < 0) { + $error++; } if (!$error && !$notrigger) {