From 19e4b8f269beb9ab036f32d1da5d1701eeb806e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 11 Dec 2024 17:55:20 +0100 Subject: [PATCH 1/8] fix phpstan --- build/phpstan/phpstan-baseline.neon | 6 ------ 1 file changed, 6 deletions(-) diff --git a/build/phpstan/phpstan-baseline.neon b/build/phpstan/phpstan-baseline.neon index b436d3ce5d3..3c007cca51a 100644 --- a/build/phpstan/phpstan-baseline.neon +++ b/build/phpstan/phpstan-baseline.neon @@ -25470,12 +25470,6 @@ parameters: count: 2 path: ../../htdocs/product/class/product.class.php - - - message: '#^Ternary operator condition is always true\.$#' - identifier: ternary.alwaysTrue - count: 1 - path: ../../htdocs/product/class/product.class.php - - message: '#^Negated boolean expression is always true\.$#' identifier: booleanNot.alwaysTrue From bf46df80d4aedc730453cadd6687553dd3477907 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 11 Dec 2024 18:04:05 +0100 Subject: [PATCH 2/8] fix phpstan --- htdocs/product/class/product.class.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index c5ab3793d34..f555e133299 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -646,6 +646,10 @@ class Product extends CommonObject * @var array{}|array{customers_toconsume:int,nb_toconsume:int,qty_toconsume:float,customers_consumed:int,nb_consumed:int,qty_consumed:float,customers_toproduce:int,nb_toproduce:int,qty_toproduce:float,customers_produced:int,nb_produced:int,qty_produced:float} stats by role toconsume, consumed, toproduce, produced */ public $stats_mo = array(); + + /** + * @var array{}|array{nb_toproduce:int,nb_toconsume:int,qty_toproduce:float,qty_toconsume:float} + */ public $stats_bom = array(); public $stats_mrptoconsume = array(); public $stats_mrptoproduce = array(); From 45fa431092c6a3728e4fa079a306b7cb2c411709 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 11 Dec 2024 18:07:16 +0100 Subject: [PATCH 3/8] fix phpstan --- htdocs/product/class/product.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index f555e133299..e987b88377e 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -3083,7 +3083,7 @@ class Product extends CommonObject $this->multiprices_min_ttc[$i] = $result ? $result["price_min_ttc"] : null; $this->multiprices_base_type[$i] = $result ? $result["price_base_type"] : null; // Next two fields are used only if PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL is on - $this->multiprices_tva_tx[$i] = $result ? $result["tva_tx"].($result ? ' ('.$result['default_vat_code'].')' : '') : null; + $this->multiprices_tva_tx[$i] = $result ? $result["tva_tx"].(!empty($result['default_vat_code']) ? ' ('.$result['default_vat_code'].')' : '') : null; $this->multiprices_recuperableonly[$i] = $result ? $result["recuperableonly"] : null; // Price by quantity From 3bb34cbf24f548d023a62b28b2b2e515929138fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 11 Dec 2024 18:12:08 +0100 Subject: [PATCH 4/8] fix phpstan --- build/phpstan/phpstan-baseline.neon | 30 -------------------------- htdocs/product/class/product.class.php | 8 +++---- 2 files changed, 4 insertions(+), 34 deletions(-) diff --git a/build/phpstan/phpstan-baseline.neon b/build/phpstan/phpstan-baseline.neon index 3c007cca51a..6fd43263efc 100644 --- a/build/phpstan/phpstan-baseline.neon +++ b/build/phpstan/phpstan-baseline.neon @@ -25410,36 +25410,6 @@ parameters: count: 1 path: ../../htdocs/product/class/product.class.php - - - message: '#^Property Product\:\:\$stats_bom has no type specified\.$#' - identifier: missingType.property - count: 1 - path: ../../htdocs/product/class/product.class.php - - - - message: '#^Property Product\:\:\$stats_facture_fournisseur has no type specified\.$#' - identifier: missingType.property - count: 1 - path: ../../htdocs/product/class/product.class.php - - - - message: '#^Property Product\:\:\$stats_facturerec has no type specified\.$#' - identifier: missingType.property - count: 1 - path: ../../htdocs/product/class/product.class.php - - - - message: '#^Property Product\:\:\$stats_mrptoconsume has no type specified\.$#' - identifier: missingType.property - count: 1 - path: ../../htdocs/product/class/product.class.php - - - - message: '#^Property Product\:\:\$stats_mrptoproduce has no type specified\.$#' - identifier: missingType.property - count: 1 - path: ../../htdocs/product/class/product.class.php - - message: '#^Property Product\:\:\$status \(int\) in isset\(\) is not nullable\.$#' identifier: isset.property diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index e987b88377e..3b34af84ed5 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -1141,10 +1141,10 @@ class Product extends CommonObject if ($id > 0) { $this->id = $id; - $this->price = $price_ht; - $this->price_ttc = $price_ttc; - $this->price_min = $price_min_ht; - $this->price_min_ttc = $price_min_ttc; + $this->price = $price_ht; + $this->price_ttc = $price_ttc; + $this->price_min = $price_min_ht; + $this->price_min_ttc = $price_min_ttc; $result = $this->_log_price($user); if ($result > 0) { From a97ffa85537e7aeba782440ed006a1cc1fef18d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 11 Dec 2024 18:16:28 +0100 Subject: [PATCH 5/8] fix phpstan --- htdocs/product/class/product.class.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 3b34af84ed5..580983d03c0 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -651,9 +651,25 @@ class Product extends CommonObject * @var array{}|array{nb_toproduce:int,nb_toconsume:int,qty_toproduce:float,qty_toconsume:float} */ public $stats_bom = array(); + + /** + * @var array{} + */ public $stats_mrptoconsume = array(); + + /** + * @var array{} + */ public $stats_mrptoproduce = array(); + + /** + * @var array{} + */ public $stats_facturerec = array(); + + /** + * @var array{} + */ public $stats_facture_fournisseur = array(); /** From 9738afbab532ba04d3932955f7ed9cca4439e3ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 11 Dec 2024 18:29:46 +0100 Subject: [PATCH 6/8] fix phpstan --- htdocs/product/class/product.class.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 580983d03c0..4b9d61e6b44 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -653,12 +653,12 @@ class Product extends CommonObject public $stats_bom = array(); /** - * @var array{} + * @var array{}|array{customers:int,nb:int,rows:int,qty:float} */ public $stats_mrptoconsume = array(); /** - * @var array{} + * @var array{}|array{customers:int,nb:int,rows:int,qty:float} */ public $stats_mrptoproduce = array(); @@ -3940,25 +3940,25 @@ class Product extends CommonObject if ($result) { while ($obj = $this->db->fetch_object($result)) { if ($obj->role == 'toconsume' && empty($warehouseid)) { - $this->stats_mrptoconsume['customers'] += $obj->nb_customers; - $this->stats_mrptoconsume['nb'] += $obj->nb; - $this->stats_mrptoconsume['rows'] += $obj->nb_rows; - $this->stats_mrptoconsume['qty'] += ($obj->qty ? $obj->qty : 0); + $this->stats_mrptoconsume['customers'] += (int) $obj->nb_customers; + $this->stats_mrptoconsume['nb'] += (int) $obj->nb; + $this->stats_mrptoconsume['rows'] += (int) $obj->nb_rows; + $this->stats_mrptoconsume['qty'] += ($obj->qty ? (float) $obj->qty : 0.0); } if ($obj->role == 'consumed' && empty($warehouseid)) { //$this->stats_mrptoconsume['customers'] += $obj->nb_customers; //$this->stats_mrptoconsume['nb'] += $obj->nb; //$this->stats_mrptoconsume['rows'] += $obj->nb_rows; - $this->stats_mrptoconsume['qty'] -= ($obj->qty ? $obj->qty : 0); + $this->stats_mrptoconsume['qty'] -= ($obj->qty ? (float) $obj->qty : 0.0); } if ($obj->role == 'toproduce') { if ($warehouseid) { - $this->stock_warehouse[$warehouseid]->stats_mrptoproduce['qty'] += ($obj->qty ? $obj->qty : 0); + $this->stock_warehouse[$warehouseid]->stats_mrptoproduce['qty'] += ($obj->qty ? (float) $obj->qty : 0.0); } else { - $this->stats_mrptoproduce['customers'] += $obj->nb_customers; - $this->stats_mrptoproduce['nb'] += $obj->nb; - $this->stats_mrptoproduce['rows'] += $obj->nb_rows; - $this->stats_mrptoproduce['qty'] += ($obj->qty ? $obj->qty : 0); + $this->stats_mrptoproduce['customers'] += (int) $obj->nb_customers; + $this->stats_mrptoproduce['nb'] += (int) $obj->nb; + $this->stats_mrptoproduce['rows'] += (int) $obj->nb_rows; + $this->stats_mrptoproduce['qty'] += ($obj->qty ? (float) $obj->qty : 0.0); } } if ($obj->role == 'produced') { From a30e367b9d96e92d88b0ba8990e11e6a726e713d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 11 Dec 2024 18:40:48 +0100 Subject: [PATCH 7/8] fix phpstan --- htdocs/product/class/product.class.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 4b9d61e6b44..66d3bbe97c6 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -663,12 +663,12 @@ class Product extends CommonObject public $stats_mrptoproduce = array(); /** - * @var array{} + * @var array{}|array{customers:int,nb:int,rows:int,qty:float} stats facture rec */ public $stats_facturerec = array(); /** - * @var array{} + * @var array{}|array{suppliers:int,nb:int,rows:int,qty:float} stats supplier invoices */ public $stats_facture_fournisseur = array(); @@ -3929,11 +3929,11 @@ class Product extends CommonObject $this->stats_mrptoconsume['customers'] = 0; $this->stats_mrptoconsume['nb'] = 0; $this->stats_mrptoconsume['rows'] = 0; - $this->stats_mrptoconsume['qty'] = 0; + $this->stats_mrptoconsume['qty'] = 0.0; $this->stats_mrptoproduce['customers'] = 0; $this->stats_mrptoproduce['nb'] = 0; $this->stats_mrptoproduce['rows'] = 0; - $this->stats_mrptoproduce['qty'] = 0; + $this->stats_mrptoproduce['qty'] = 0.0; } $result = $this->db->query($sql); @@ -4184,10 +4184,10 @@ class Product extends CommonObject $result = $this->db->query($sql); if ($result) { $obj = $this->db->fetch_object($result); - $this->stats_facturerec['customers'] = $obj->nb_customers; - $this->stats_facturerec['nb'] = $obj->nb; - $this->stats_facturerec['rows'] = $obj->nb_rows; - $this->stats_facturerec['qty'] = $obj->qty ? $obj->qty : 0; + $this->stats_facturerec['customers'] = (int) $obj->nb_customers; + $this->stats_facturerec['nb'] = (int) $obj->nb; + $this->stats_facturerec['rows'] = (int) $obj->nb_rows; + $this->stats_facturerec['qty'] = $obj->qty ? (float) $obj->qty : 0.0; // if it's a virtual product, maybe it is in invoice by extension if (getDolGlobalString('PRODUCT_STATS_WITH_PARENT_PROD_IF_INCDEC')) { @@ -4258,10 +4258,10 @@ class Product extends CommonObject $result = $this->db->query($sql); if ($result) { $obj = $this->db->fetch_object($result); - $this->stats_facture_fournisseur['suppliers'] = $obj->nb_suppliers; - $this->stats_facture_fournisseur['nb'] = $obj->nb; - $this->stats_facture_fournisseur['rows'] = $obj->nb_rows; - $this->stats_facture_fournisseur['qty'] = $obj->qty ? $obj->qty : 0; + $this->stats_facture_fournisseur['suppliers'] = (int) $obj->nb_suppliers; + $this->stats_facture_fournisseur['nb'] = (int) $obj->nb; + $this->stats_facture_fournisseur['rows'] = (int) $obj->nb_rows; + $this->stats_facture_fournisseur['qty'] = $obj->qty ? (float) $obj->qty : 0.0; $parameters = array('socid' => $socid); $reshook = $hookmanager->executeHooks('loadStatsSupplierInvoice', $parameters, $this, $action); From e5449c7a67c7251f526a7e5a6b361c35a4a6457c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 11 Dec 2024 18:53:16 +0100 Subject: [PATCH 8/8] fix phpstan --- htdocs/core/modules/modStock.class.php | 2 +- htdocs/product/class/product.class.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/core/modules/modStock.class.php b/htdocs/core/modules/modStock.class.php index 1531a9245ae..bd6f23aeb9d 100644 --- a/htdocs/core/modules/modStock.class.php +++ b/htdocs/core/modules/modStock.class.php @@ -44,7 +44,7 @@ class modStock extends DolibarrModules */ public function __construct($db) { - global $langs; + global $conf, $langs; // do not remove $conf $this->db = $db; $this->numero = 52; diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 66d3bbe97c6..a94aa6d490a 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -653,12 +653,12 @@ class Product extends CommonObject public $stats_bom = array(); /** - * @var array{}|array{customers:int,nb:int,rows:int,qty:float} + * @var array{}|array{customers:int,nb:int,rows:int,qty:float} stats mrp to consume */ public $stats_mrptoconsume = array(); /** - * @var array{}|array{customers:int,nb:int,rows:int,qty:float} + * @var array{}|array{customers:int,nb:int,rows:int,qty:float} stats mrp to produce */ public $stats_mrptoproduce = array();