From 009a4856b34ecfb87e43c6df4a904fe3baf3dbdb Mon Sep 17 00:00:00 2001 From: thibdrev Date: Thu, 22 Feb 2024 13:22:06 +0100 Subject: [PATCH 1/4] qual: phpstan - various fixes (#28351) * qual: phpstan for htdocs/compta/tva/class/paymentvat.class.php htdocs/compta/tva/class/paymentvat.class.php 540 Property CommonObject::$tms (int) does not accept string. * qual: phpstan - various "$enabled (int) does not accept bool." htdocs/core/boxes/box_actions.php 54 Property box_actions::$enabled (int) does not accept bool. htdocs/core/boxes/box_actions_future.php 54 Property box_actions_future::$enabled (int) does not accept bool. htdocs/core/boxes/box_activity.php 53 Property box_activity::$enabled (int) does not accept string. * qual: phpstan for htdocs/core/boxes/box_activity.php htdocs/core/boxes/box_activity.php 53 Property box_activity::$enabled (int) does not accept string. * qual: phpstan for htdocs/core/modules/modTakePos.class.php htdocs/core/modules/modTakePos.class.php 284 Property Societe::$code_client (string) does not accept int. htdocs/core/modules/modTakePos.class.php 285 Property Societe::$code_fournisseur (string) does not accept int. --- htdocs/compta/tva/class/paymentvat.class.php | 2 +- htdocs/core/boxes/box_activity.php | 2 +- htdocs/core/boxes/modules_boxes.php | 2 +- htdocs/core/modules/modTakePos.class.php | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/compta/tva/class/paymentvat.class.php b/htdocs/compta/tva/class/paymentvat.class.php index a8f38ccb9d5..be9df9fe313 100644 --- a/htdocs/compta/tva/class/paymentvat.class.php +++ b/htdocs/compta/tva/class/paymentvat.class.php @@ -537,7 +537,7 @@ class PaymentVAT extends CommonObject $this->id = 0; $this->fk_tva = 0; $this->datec = dol_now(); - $this->tms = ''; + $this->tms = dol_now(); $this->datep = ''; $this->amount = ''; $this->fk_typepaiement = 0; diff --git a/htdocs/core/boxes/box_activity.php b/htdocs/core/boxes/box_activity.php index 52b8cb65504..b84e74dfe18 100644 --- a/htdocs/core/boxes/box_activity.php +++ b/htdocs/core/boxes/box_activity.php @@ -50,7 +50,7 @@ class box_activity extends ModeleBoxes $this->db = $db; // FIXME: Pb into some status - $this->enabled = (getDolGlobalString('MAIN_FEATURES_LEVEL')); // Not enabled by default due to bugs (see previous comments) + $this->enabled = getDolGlobalInt('MAIN_FEATURES_LEVEL'); // Not enabled by default due to bugs (see previous comments) $this->hidden = !( (isModEnabled('facture') && $user->hasRight('facture', 'read')) diff --git a/htdocs/core/boxes/modules_boxes.php b/htdocs/core/boxes/modules_boxes.php index e99f4660a30..1bfd9688e2c 100644 --- a/htdocs/core/boxes/modules_boxes.php +++ b/htdocs/core/boxes/modules_boxes.php @@ -64,7 +64,7 @@ class ModeleBoxes // Can't be abstract as it is instantiated to build "empty" bo public $max = 5; /** - * @var int Condition to have widget enabled + * @var bool|int Condition to have widget enabled */ public $enabled = 1; diff --git a/htdocs/core/modules/modTakePos.class.php b/htdocs/core/modules/modTakePos.class.php index ed237feadf6..d61b3ba3628 100644 --- a/htdocs/core/modules/modTakePos.class.php +++ b/htdocs/core/modules/modTakePos.class.php @@ -281,8 +281,8 @@ class modTakePos extends DolibarrModules if ($searchcompanyid == 0) { $societe->name = $nametouse; $societe->client = 1; - $societe->code_client = -1; - $societe->code_fournisseur = -1; + $societe->code_client = '-1'; + $societe->code_fournisseur = '-1'; $societe->note_private = "Default customer automatically created by Point Of Sale module activation. Can be used as the default generic customer in the Point Of Sale setup. Can also be edited or removed if you don't need a generic customer."; $searchcompanyid = $societe->create($user); From 2b4bc3b4bce52cc5c6ae1c6ef5ea8350861793e3 Mon Sep 17 00:00:00 2001 From: thibdrev Date: Thu, 22 Feb 2024 13:22:24 +0100 Subject: [PATCH 2/4] qual: phpstan for htdocs/resource/class/dolresource.class.php (#28352) htdocs/resource/class/dolresource.class.php 723 Property Dolresource::$busy (int) does not accept string. htdocs/resource/class/dolresource.class.php 726 Property Dolresource::$mandatory (int) does not accept string. --- htdocs/resource/class/dolresource.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/resource/class/dolresource.class.php b/htdocs/resource/class/dolresource.class.php index 38a880f1d6c..687d484283c 100644 --- a/htdocs/resource/class/dolresource.class.php +++ b/htdocs/resource/class/dolresource.class.php @@ -720,10 +720,10 @@ class Dolresource extends CommonObject $this->element_type = trim($this->element_type); } if (isset($this->busy)) { - $this->busy = trim($this->busy); + $this->busy = (int) $this->busy; } if (isset($this->mandatory)) { - $this->mandatory = trim($this->mandatory); + $this->mandatory = (int) $this->mandatory; } // Update request From f1f516f54c198fdf6b32e2dd9af3a845d2e96641 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 22 Feb 2024 13:23:39 +0100 Subject: [PATCH 3/4] NEW: Global constant for deprecated module mapping (#28348) * Qual: Add another deprecated module mapping * NEW: Global constant for deprecated module mapping --- htdocs/core/lib/functions.lib.php | 34 +++++++++++++++++++++---------- test/phpunit/CodingPhpTest.php | 3 ++- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index c8f8a31b1dc..d3f619d19b6 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -206,6 +206,28 @@ function getDolUserInt($key, $default = 0, $tmpuser = null) return (int) (empty($tmpuser->conf->$key) ? $default : $tmpuser->conf->$key); } +define( + 'DEPRECATED_MODULE_MAPPING', + array( + 'actioncomm' => 'agenda', + 'adherent' => 'member', + 'adherent_type' => 'member_type', + 'banque' => 'bank', + 'categorie' => 'category', + 'commande' => 'order', + 'contrat' => 'contract', + 'entrepot' => 'stock', + 'expedition' => 'delivery_note', + 'facture' => 'invoice', + 'fichinter' => 'intervention', + 'product_fournisseur_price' => 'productsupplierprice', + 'product_price' => 'productprice', + 'projet' => 'project', + 'propale' => 'propal', + 'socpeople' => 'contact', + ) +); + /** * Is Dolibarr module enabled * @@ -217,17 +239,7 @@ function isModEnabled($module) global $conf; // Fix old names (map to new names) - $arrayconv = array( - 'adherent' => 'member', - 'banque' => 'bank', - 'categorie' => 'category', - 'commande' => 'order', - 'contrat' => 'contract', - 'expedition' => 'delivery_note', - 'facture' => 'invoice', - 'projet' => 'project', - 'propale' => 'propal', - ); + $arrayconv = DEPRECATED_MODULE_MAPPING; if (!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) { // Special cases: both use the same module. diff --git a/test/phpunit/CodingPhpTest.php b/test/phpunit/CodingPhpTest.php index 7290d9562d6..f39e2540ef3 100644 --- a/test/phpunit/CodingPhpTest.php +++ b/test/phpunit/CodingPhpTest.php @@ -633,6 +633,7 @@ class CodingPhpTest extends CommonClassTest 'commande' => 'order', 'contrat' => 'contract', 'entrepot' => 'stock', + 'expedition' => 'delivery_note', 'facture' => 'invoice', 'fichinter' => 'intervention', 'product_fournisseur_price' => 'productsupplierprice', @@ -647,6 +648,7 @@ class CodingPhpTest extends CommonClassTest 'member_type' => 1, 'bank' => 1, 'category' => 1, + 'delivery_note' => 1, 'order' => 1, 'contract' => 1, 'stock' => 1, @@ -680,7 +682,6 @@ class CodingPhpTest extends CommonClassTest 'ecotax' => 1, 'emailcollector' => 1, 'eventorganization' => 1, - 'expedition' => 1, 'expensereport' => 1, 'export' => 1, 'externalsite' => 1, From 999af4951ba9f791636d8c5887d211c4b09c5245 Mon Sep 17 00:00:00 2001 From: thibdrev Date: Thu, 22 Feb 2024 13:27:04 +0100 Subject: [PATCH 4/4] qual: phpstan - various "$hidden (bool) does not accept string." (#28350) * Update modWebsite.class.php * Update DolibarrModules.class.php * Update modCron.class.php * Update modSocialNetworks.class.php * qual: phpstan for htdocs/core/modules/modCollab.class.php htdocs/core/modules/modCollab.class.php 68 Property DolibarrModules::$hidden (bool) does not accept string. --- htdocs/core/modules/DolibarrModules.class.php | 2 +- htdocs/core/modules/modCollab.class.php | 2 +- htdocs/core/modules/modCron.class.php | 2 +- htdocs/core/modules/modSocialNetworks.class.php | 2 +- htdocs/core/modules/modWebsite.class.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/htdocs/core/modules/DolibarrModules.class.php b/htdocs/core/modules/DolibarrModules.class.php index 1b3b4b62d09..1604e31760e 100644 --- a/htdocs/core/modules/DolibarrModules.class.php +++ b/htdocs/core/modules/DolibarrModules.class.php @@ -397,7 +397,7 @@ class DolibarrModules // Can not be abstract, because we need to instantiate it public $enabled_bydefault; /** - * @var bool Whether to hide the module. + * @var bool|int Whether to hide the module. */ public $hidden = false; diff --git a/htdocs/core/modules/modCollab.class.php b/htdocs/core/modules/modCollab.class.php index d08a8438954..be1edcb8c62 100644 --- a/htdocs/core/modules/modCollab.class.php +++ b/htdocs/core/modules/modCollab.class.php @@ -65,7 +65,7 @@ class modCollab extends DolibarrModules // Dependencies //------------- - $this->hidden = getDolGlobalString('MODULE_COLLAB_DISABLED'); // A condition to disable module + $this->hidden = getDolGlobalInt('MODULE_COLLAB_DISABLED'); // A condition to disable module $this->depends = array(); // List of modules id that must be enabled if this module is enabled $this->requiredby = array(); // List of modules id to disable if this one is disabled $this->conflictwith = array(); // List of modules id this module is in conflict with diff --git a/htdocs/core/modules/modCron.class.php b/htdocs/core/modules/modCron.class.php index 44d9962ef6c..29daa7d61bf 100644 --- a/htdocs/core/modules/modCron.class.php +++ b/htdocs/core/modules/modCron.class.php @@ -66,7 +66,7 @@ class modCron extends DolibarrModules // Dependencies //------------- - $this->hidden = getDolGlobalString('MODULE_CRON_DISABLED'); // A condition to disable module + $this->hidden = getDolGlobalInt('MODULE_CRON_DISABLED'); // A condition to disable module $this->depends = array(); // List of modules id that must be enabled if this module is enabled $this->requiredby = array(); // List of modules id to disable if this one is disabled $this->conflictwith = array(); // List of modules id this module is in conflict with diff --git a/htdocs/core/modules/modSocialNetworks.class.php b/htdocs/core/modules/modSocialNetworks.class.php index 4f007a0d9e3..a62b249f410 100644 --- a/htdocs/core/modules/modSocialNetworks.class.php +++ b/htdocs/core/modules/modSocialNetworks.class.php @@ -64,7 +64,7 @@ class modSocialNetworks extends DolibarrModules $this->config_page_url = array(DOL_URL_ROOT.'/admin/dict.php?id=38'); // Dependencies - $this->hidden = getDolGlobalString('MODULE_SOCIALNETWORKS_DISABLED'); // A condition to hide module + $this->hidden = getDolGlobalInt('MODULE_SOCIALNETWORKS_DISABLED'); // A condition to hide module $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled $this->requiredby = array(); // List of module ids to disable if this one is disabled $this->conflictwith = array(); // List of module class names as string this module is in conflict with diff --git a/htdocs/core/modules/modWebsite.class.php b/htdocs/core/modules/modWebsite.class.php index f75acbf713b..d7afc7921b7 100644 --- a/htdocs/core/modules/modWebsite.class.php +++ b/htdocs/core/modules/modWebsite.class.php @@ -61,7 +61,7 @@ class modWebsite extends DolibarrModules $this->config_page_url = array('website.php'); // Dependencies - $this->hidden = getDolGlobalString('MODULE_WEBSITE_DISABLED'); // A condition to disable module + $this->hidden = getDolGlobalInt('MODULE_WEBSITE_DISABLED'); // A condition to disable module $this->depends = array('modFckeditor'); // List of modules id that must be enabled if this module is enabled $this->requiredby = array(); // List of modules id to disable if this one is disabled $this->conflictwith = array(); // List of modules id this module is in conflict with