From 0e1292e2536a67ddec2e2dd6d713c8f2a57a8055 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 29 Sep 2024 02:49:34 +0200 Subject: [PATCH] fix phpstan (#31177) * fix phpstan * fix phpstan * fix phpstan * fix phpstan * fix phpstan --- htdocs/adherents/class/adherent.class.php | 2 +- htdocs/adherents/class/adherent_type.class.php | 4 +++- htdocs/admin/system/dolibarr.php | 5 +++-- htdocs/core/lib/functions.lib.php | 8 ++++---- htdocs/core/modules/barcode/modules_barcode.class.php | 6 +++--- htdocs/core/modules/member/modules_member.class.php | 2 +- htdocs/core/modules/product/modules_product.class.php | 6 +++--- htdocs/core/modules/societe/modules_societe.class.php | 6 +++--- phpstan.neon.dist | 2 +- 9 files changed, 22 insertions(+), 19 deletions(-) diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index 0715d558d01..8e5ed262fe4 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -176,7 +176,7 @@ class Adherent extends CommonObject public $morphy; /** - * @var int Info can be public + * @var int<0,1> Info can be public */ public $public; diff --git a/htdocs/adherents/class/adherent_type.class.php b/htdocs/adherents/class/adherent_type.class.php index 920f5f8838e..a6b0ebe0513 100644 --- a/htdocs/adherents/class/adherent_type.class.php +++ b/htdocs/adherents/class/adherent_type.class.php @@ -107,7 +107,9 @@ class AdherentType extends CommonObject /** @var string Public note */ public $note_public; - /** @var integer Can vote */ + /** + * @var int<0,1> Can vote + */ public $vote; /** @var string Email sent during validation of member */ diff --git a/htdocs/admin/system/dolibarr.php b/htdocs/admin/system/dolibarr.php index 866d57cec81..19c7ec5f819 100644 --- a/htdocs/admin/system/dolibarr.php +++ b/htdocs/admin/system/dolibarr.php @@ -2,7 +2,8 @@ /* Copyright (C) 2005-2020 Laurent Destailleur * Copyright (C) 2007 Rodolphe Quiedeville * Copyright (C) 2007-2012 Regis Houssin - * Copyright (C) 2024 MDW + * Copyright (C) 2024 MDW + * Copyright (C) 2024 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 @@ -276,7 +277,7 @@ $daylight = round($c - $b); $val = ($a >= 0 ? '+' : '').$a; $val .= ' ('.($a == 'unknown' ? 'unknown' : ($a >= 0 ? '+' : '').($a * 3600)).')'; $val .= '       '.getServerTimeZoneString(); -$val .= '       '.$langs->trans("DaylingSavingTime").': '.((is_null($b) || is_null($c)) ? 'unknown' : ($a == $c ? yn($daylight) : yn(0).($daylight ? '     ('.$langs->trans('YesInSummer').')' : ''))); +$val .= '       '.$langs->trans("DaylingSavingTime").': '.((is_null($b) || is_null($c)) ? 'unknown' : ($a == $c ? yn((int) $daylight) : yn(0).($daylight ? '     ('.$langs->trans('YesInSummer').')' : ''))); print $form->textwithtooltip($val, $txt, 2, 1, img_info('')); print ''."\n"; // value defined in http://fr3.php.net/manual/en/timezones.europe.php print '  => '.$langs->trans("CurrentHour").''.dol_print_date(dol_now('gmt'), 'dayhour', 'tzserver').''."\n"; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 56a90559423..f230354af7b 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -7693,10 +7693,10 @@ function get_default_localtax($thirdparty_seller, $thirdparty_buyer, $local, $id /** * Return yes or no in current language * - * @param string|int $yesno Value to test (1, 'yes', 'true' or 0, 'no', 'false') - * @param integer $case 1=Yes/No, 0=yes/no, 2=Disabled checkbox, 3=Disabled checkbox + Yes/No - * @param int $color 0=texte only, 1=Text is formatted with a color font style ('ok' or 'error'), 2=Text is formatted with 'ok' color. - * @return string HTML string + * @param int<0, 1>|'yes'|'true'|'no'|'false' $yesno Value to test (1, 'yes', 'true' or 0, 'no', 'false') + * @param integer $case 1=Yes/No, 0=yes/no, 2=Disabled checkbox, 3=Disabled checkbox + Yes/No + * @param int $color 0=texte only, 1=Text is formatted with a color font style ('ok' or 'error'), 2=Text is formatted with 'ok' color. + * @return string HTML string */ function yn($yesno, $case = 1, $color = 0) { diff --git a/htdocs/core/modules/barcode/modules_barcode.class.php b/htdocs/core/modules/barcode/modules_barcode.class.php index 9e3fe8894e2..16232e783eb 100644 --- a/htdocs/core/modules/barcode/modules_barcode.class.php +++ b/htdocs/core/modules/barcode/modules_barcode.class.php @@ -145,7 +145,7 @@ abstract class ModeleNumRefBarCode extends CommonNumRefGenerator if (getDolGlobalString('MAIN_BARCODE_CODE_ALWAYS_REQUIRED') && !empty($this->code_null)) { $s .= ''; } - $s .= yn(!$this->code_null, 1, 2); + $s .= yn($this->code_null ? 0 : 1, 1, 2); if (getDolGlobalString('MAIN_BARCODE_CODE_ALWAYS_REQUIRED') && !empty($this->code_null)) { $s .= ' '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')'; } @@ -156,7 +156,7 @@ abstract class ModeleNumRefBarCode extends CommonNumRefGenerator if (getDolGlobalString('MAIN_BARCODE_CODE_ALWAYS_REQUIRED') && !empty($this->code_null)) { $s .= ''; } - $s .= yn(!$this->code_null, 1, 2); + $s .= yn($this->code_null ? 0 : 1, 1, 2); if (getDolGlobalString('MAIN_BARCODE_CODE_ALWAYS_REQUIRED') && !empty($this->code_null)) { $s .= ' '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')'; } @@ -167,7 +167,7 @@ abstract class ModeleNumRefBarCode extends CommonNumRefGenerator if (getDolGlobalString('MAIN_BARCODE_CODE_ALWAYS_REQUIRED') && !empty($this->code_null)) { $s .= ''; } - $s .= yn(!$this->code_null, 1, 2); + $s .= yn($this->code_null ? 0 : 1, 1, 2); if (getDolGlobalString('MAIN_BARCODE_CODE_ALWAYS_REQUIRED') && !empty($this->code_null)) { $s .= ' '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')'; } diff --git a/htdocs/core/modules/member/modules_member.class.php b/htdocs/core/modules/member/modules_member.class.php index eeb188056e6..640c31ee2d3 100644 --- a/htdocs/core/modules/member/modules_member.class.php +++ b/htdocs/core/modules/member/modules_member.class.php @@ -108,7 +108,7 @@ abstract class ModeleNumRefMembers extends CommonNumRefGenerator $s .= ''.$langs->trans("ThisIsModuleRules").':
'; $s .= $langs->trans("Required").': '.$strikestart; - $s .= yn(!$this->code_null, 1, 2).$strikeend; + $s .= yn($this->code_null ? 0 : 1, 1, 2).$strikeend; $s .= '
'; $s .= $langs->trans("CanBeModifiedIfOk").': '; $s .= yn($this->code_modifiable, 1, 2); diff --git a/htdocs/core/modules/product/modules_product.class.php b/htdocs/core/modules/product/modules_product.class.php index 554d83f3aff..dc81b248f52 100644 --- a/htdocs/core/modules/product/modules_product.class.php +++ b/htdocs/core/modules/product/modules_product.class.php @@ -154,15 +154,15 @@ abstract class ModeleProductCode extends CommonNumRefGenerator $s .= ''.$langs->trans("ThisIsModuleRules").':
'; if ($type == 0) { $s .= $langs->trans("RequiredIfProduct").': '.$strikestart; - $s .= yn(!$this->code_null, 1, 2).$strikeend; + $s .= yn($this->code_null ? 0 : 1, 1, 2).$strikeend; $s .= '
'; } elseif ($type == 1) { $s .= $langs->trans("RequiredIfService").': '.$strikestart; - $s .= yn(!$this->code_null, 1, 2).$strikeend; + $s .= yn($this->code_null ? 0 : 1, 1, 2).$strikeend; $s .= '
'; } elseif ($type == -1) { $s .= $langs->trans("Required").': '.$strikestart; - $s .= yn(!$this->code_null, 1, 2).$strikeend; + $s .= yn($this->code_null ? 0 : 1, 1, 2).$strikeend; $s .= '
'; } $s .= $langs->trans("CanBeModifiedIfOk").': '; diff --git a/htdocs/core/modules/societe/modules_societe.class.php b/htdocs/core/modules/societe/modules_societe.class.php index c4e65c4fded..82551e436ae 100644 --- a/htdocs/core/modules/societe/modules_societe.class.php +++ b/htdocs/core/modules/societe/modules_societe.class.php @@ -174,15 +174,15 @@ abstract class ModeleThirdPartyCode extends CommonNumRefGenerator $s .= ''.$langs->trans("ThisIsModuleRules").':
'; if ($type == 0) { $s .= $langs->trans("RequiredIfCustomer").': '.$strikestart; - $s .= yn(!$this->code_null, 1, 2).$strikeend; + $s .= yn($this->code_null ? 0 : 1, 1, 2).$strikeend; $s .= '
'; } elseif ($type == 1) { $s .= $langs->trans("RequiredIfSupplier").': '.$strikestart; - $s .= yn(!$this->code_null, 1, 2).$strikeend; + $s .= yn($this->code_null ? 0 : 1, 1, 2).$strikeend; $s .= '
'; } elseif ($type == -1) { $s .= $langs->trans("Required").': '.$strikestart; - $s .= yn(!$this->code_null, 1, 2).$strikeend; + $s .= yn($this->code_null ? 0 : 1, 1, 2).$strikeend; $s .= '
'; } $s .= $langs->trans("CanBeModifiedIfOk").': '; diff --git a/phpstan.neon.dist b/phpstan.neon.dist index eebcb0098bc..4044a33546d 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -72,7 +72,7 @@ parameters: - '# (dol_print_date|correctExifImageOrientation) expects bool\|string#' - '# (getRandomPassword|vatrate|DolEditor constructor) expects bool, int#' - '# SMTPs::(getFrom|getErrorsTo|getReplyTo)\(\) expects bool, string given.#' - - '# (dolibarr_set_const|yn|getLocalTaxesFromRate) expects int\|string#' + - '# (dolibarr_set_const|getLocalTaxesFromRate) expects int\|string#' - '#::(options)\(\) expects int\|string#' - '# (print_barre_liste|dol_substr) expects int\|null#' - '#(?:colorAdjustBrightness|imap_(?:(?:fetch)?body|fetchstructure)) expects int, string#'