From c496e84916bcaed82ee7d55e62bd7c1174d39dd5 Mon Sep 17 00:00:00 2001 From: MDW Date: Thu, 29 Aug 2024 15:01:42 +0200 Subject: [PATCH] Qual: Fix phan issues related to getNextValue() notices (#30747) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Qual: 🛟 Fix reference to $db with $this->db # Qual: reference to $db with $this->db $db was undeclared, use $this->db. * Fix suspected issue with environment max size and md5sum working on limited files * Qual: Fix LDAP typing * Qual: Fix some phan typing related to getNextValue() # Qual: Fix some phan typing related to getNextValue() This fixes a few typings in relation to getNextValue(). * Update phan baseline * PHPDoc: set arguments as nullable (+update array types) * Improve PHPDoc * Force toselect type to int[] * Enable all phan notices on actions_massactions.inc.php * Test was wrong, can not count when it's not an array * Update baseline * Remove ignore for notice that no longer exists * Update baseline * Fix format argument --------- Co-authored-by: Laurent Destailleur --- dev/tools/phan/baseline.txt | 12 ++++++------ htdocs/admin/pdf.php | 2 +- htdocs/comm/propal/class/propal.class.php | 3 ++- htdocs/commande/class/commande.class.php | 2 ++ htdocs/compta/paiement/class/paiement.class.php | 3 ++- htdocs/core/lib/pdf.lib.php | 10 +++++----- htdocs/core/modules/bom/mod_bom_advanced.php | 8 ++++---- htdocs/core/modules/bom/mod_bom_standard.php | 6 +++--- htdocs/core/modules/bom/modules_bom.php | 6 +++--- htdocs/core/modules/facture/mod_facture_mars.php | 4 ++-- htdocs/core/modules/facture/mod_facture_mercure.php | 6 +++--- htdocs/core/modules/facture/mod_facture_terre.php | 4 ++-- htdocs/core/modules/facture/modules_facture.php | 4 ++-- htdocs/core/tpl/massactions_pre.tpl.php | 5 ++++- htdocs/projet/class/task.class.php | 8 ++++---- htdocs/projet/contact.php | 3 ++- 16 files changed, 47 insertions(+), 39 deletions(-) diff --git a/dev/tools/phan/baseline.txt b/dev/tools/phan/baseline.txt index f868e54693a..e86d8fae4d4 100644 --- a/dev/tools/phan/baseline.txt +++ b/dev/tools/phan/baseline.txt @@ -235,7 +235,7 @@ return [ 'htdocs/comm/mailing/index.php' => ['PhanUndeclaredProperty'], 'htdocs/comm/propal/card.php' => ['PhanPluginUnknownObjectMethodCall', 'PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchProperty', 'PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'], 'htdocs/comm/propal/class/api_proposals.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanTypeMismatchArgumentProbablyReal'], - 'htdocs/comm/propal/class/propal.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanPluginUnknownObjectMethodCall', 'PhanPluginUnknownPropertyType'], + 'htdocs/comm/propal/class/propal.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanPluginUnknownPropertyType'], 'htdocs/comm/propal/class/propalestats.class.php' => ['PhanPluginUnknownArrayMethodReturnType', 'PhanPluginUnknownPropertyType'], 'htdocs/comm/propal/list.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgumentProbablyReal', 'PhanUndeclaredGlobalVariable'], 'htdocs/comm/propal/stats/index.php' => ['PhanPossiblyUndeclaredGlobalVariable'], @@ -303,13 +303,13 @@ return [ 'htdocs/compta/paiement/cheque/class/remisecheque.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownPropertyType', 'PhanUndeclaredMethod'], 'htdocs/compta/paiement/cheque/list.php' => ['PhanUndeclaredGlobalVariable'], 'htdocs/compta/paiement/class/cpaiement.class.php' => ['PhanPluginUnknownPropertyType'], - 'htdocs/compta/paiement/class/paiement.class.php' => ['PhanEmptyForeach', 'PhanPluginEmptyStatementIf', 'PhanPluginUnknownObjectMethodCall', 'PhanPluginUnknownPropertyType', 'PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgumentProbablyReal'], + 'htdocs/compta/paiement/class/paiement.class.php' => ['PhanEmptyForeach', 'PhanPluginEmptyStatementIf', 'PhanPluginUnknownPropertyType', 'PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgumentProbablyReal'], 'htdocs/compta/paiement/list.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgumentNullableInternal', 'PhanUndeclaredGlobalVariable'], 'htdocs/compta/paiement_charge.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgumentProbablyReal'], 'htdocs/compta/paiement_vat.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgumentProbablyReal'], 'htdocs/compta/payment_vat/card.php' => ['PhanUndeclaredGlobalVariable'], 'htdocs/compta/prelevement/card.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgumentProbablyReal'], - 'htdocs/compta/prelevement/class/bonprelevement.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownPropertyType', 'PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchProperty'], + 'htdocs/compta/prelevement/class/bonprelevement.class.php' => ['PhanPluginUnknownPropertyType', 'PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchProperty'], 'htdocs/compta/prelevement/class/rejetprelevement.class.php' => ['PhanPluginUnknownArrayMethodReturnType', 'PhanPluginUnknownPropertyType', 'PhanTypeMismatchProperty'], 'htdocs/compta/prelevement/create.php' => ['PhanPluginSuspiciousParamPosition', 'PhanPossiblyUndeclaredGlobalVariable'], 'htdocs/compta/prelevement/demandes.php' => ['PhanPossiblyUndeclaredGlobalVariable'], @@ -521,7 +521,7 @@ return [ 'htdocs/core/lib/images.lib.php' => ['PhanPluginUnknownArrayFunctionReturnType', 'PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgumentNullableInternal'], 'htdocs/core/lib/import.lib.php' => ['PhanPluginUnknownArrayFunctionReturnType'], 'htdocs/core/lib/invoice.lib.php' => ['PhanPluginUnknownArrayFunctionReturnType'], - 'htdocs/core/lib/invoice2.lib.php' => ['PhanPluginUnknownArrayFunctionParamType', 'PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgumentProbablyReal'], + 'htdocs/core/lib/invoice2.lib.php' => ['PhanPluginUnknownArrayFunctionParamType', 'PhanPossiblyUndeclaredVariable'], 'htdocs/core/lib/ldap.lib.php' => ['PhanPluginUnknownArrayFunctionReturnType'], 'htdocs/core/lib/loan.lib.php' => ['PhanPluginUnknownArrayFunctionReturnType'], 'htdocs/core/lib/mailmanspip.lib.php' => ['PhanPluginUnknownArrayFunctionReturnType'], @@ -567,7 +567,7 @@ return [ 'htdocs/core/modules/barcode/doc/phpbarcode.modules.php' => ['PhanPossiblyNullTypeMismatchProperty', 'PhanPossiblyUndeclaredVariable'], 'htdocs/core/modules/barcode/mod_barcode_product_standard.php' => ['PhanPluginUnknownPropertyType'], 'htdocs/core/modules/barcode/modules_barcode.class.php' => ['PhanPluginUnknownPropertyType'], - 'htdocs/core/modules/bom/mod_bom_advanced.php' => ['PhanTypeMismatchArgumentProbablyReal', 'PhanUndeclaredProperty'], + 'htdocs/core/modules/bom/mod_bom_advanced.php' => ['PhanUndeclaredProperty'], 'htdocs/core/modules/cheque/doc/pdf_blochet.class.php' => ['PhanPluginUnknownPropertyType', 'PhanTypeMismatchArgumentProbablyReal'], 'htdocs/core/modules/cheque/modules_chequereceipts.php' => ['PhanPluginUnknownObjectMethodCall'], 'htdocs/core/modules/commande/doc/pdf_einstein.modules.php' => ['PhanTypeMismatchArgumentProbablyReal', 'PhanUndeclaredProperty'], @@ -1004,7 +1004,7 @@ return [ 'htdocs/projet/class/projectstats.class.php' => ['PhanPluginUnknownArrayMethodReturnType', 'PhanPluginUnknownPropertyType', 'PhanPossiblyUndeclaredVariable'], 'htdocs/projet/class/task.class.php' => ['PhanPluginEmptyStatementIf', 'PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanPluginUnknownPropertyType', 'PhanTypeMismatchArgumentProbablyReal'], 'htdocs/projet/class/taskstats.class.php' => ['PhanPluginUnknownArrayMethodReturnType', 'PhanPluginUnknownPropertyType'], - 'htdocs/projet/contact.php' => ['PhanPluginUnknownObjectMethodCall', 'PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeComparisonFromArray', 'PhanTypeMismatchArgumentProbablyReal'], + 'htdocs/projet/contact.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeComparisonFromArray', 'PhanTypeMismatchArgumentProbablyReal'], 'htdocs/projet/element.php' => ['PhanPluginUnknownArrayFunctionParamType', 'PhanPluginUnknownArrayFunctionReturnType', 'PhanPluginUnknownObjectMethodCall', 'PhanPossiblyUndeclaredGlobalVariable', 'PhanUndeclaredProperty'], 'htdocs/projet/ganttchart.inc.php' => ['PhanPluginUnknownArrayFunctionParamType', 'PhanTypeMismatchArgumentProbablyReal', 'PhanUndeclaredGlobalVariable'], 'htdocs/projet/ganttview.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgumentProbablyReal'], diff --git a/htdocs/admin/pdf.php b/htdocs/admin/pdf.php index 0ee86f731cd..49e974d42e4 100644 --- a/htdocs/admin/pdf.php +++ b/htdocs/admin/pdf.php @@ -224,7 +224,7 @@ $arraylistofpdfformat = array( $s = $langs->trans("LibraryToBuildPDF")."
"; $i = 0; -$pdf = pdf_getInstance('A4'); +$pdf = pdf_getInstance(array(210, 297)); if (class_exists('FPDF') && !class_exists('TCPDF')) { if ($i) { $s .= ' + '; diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index ca425adc047..eccc1da887a 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -3643,7 +3643,8 @@ class Propal extends CommonObject } $obj = new $classname(); - $numref = ""; + '@phan-var-force ModeleNumRefPropales $obj'; + $numref = $obj->getNextValue($soc, $this); if ($numref != "") { diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 6e37cdb2121..7592fd43c14 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -449,6 +449,8 @@ class Commande extends CommonOrder } $obj = new $classname(); + '@phan-var-force ModeleNumRefCommandes $obj'; + $numref = $obj->getNextValue($soc, $this); if ($numref != "") { diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index 3ecb65e120a..5bc3236cb3c 100644 --- a/htdocs/compta/paiement/class/paiement.class.php +++ b/htdocs/compta/paiement/class/paiement.class.php @@ -1212,7 +1212,8 @@ class Paiement extends CommonObject } $obj = new $classname(); - $numref = ""; + '@phan-var-force ModeleNumRefPayments $obj'; + $numref = $obj->getNextValue($soc, $this); /** diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 8eeea4da03a..df5ac25f5c1 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -79,9 +79,9 @@ function pdf_admin_prepare_head() /** * Return array with format properties of default PDF format * - * @param Translate|null $outputlangs Output lang to use to autodetect output format if we need 'auto' detection - * @param string $mode 'setup' = Use setup, 'auto' = Force autodetection whatever is setup - * @return array Array('width'=>w,'height'=>h,'unit'=>u); + * @param ?Translate $outputlangs Output lang to use to autodetect output format if we need 'auto' detection + * @param 'setup'|'auto' $mode 'setup' = Use setup, 'auto' = Force autodetection whatever is setup + * @return array{width:float|int,height:float|int,unit:string} Array('width'=>w,'height'=>h,'unit'=>u); */ function pdf_getFormat(Translate $outputlangs = null, $mode = 'setup') { @@ -120,9 +120,9 @@ function pdf_getFormat(Translate $outputlangs = null, $mode = 'setup') /** * Return a PDF instance object. We create a FPDI instance that instantiate TCPDF. * - * @param string $format Array(width,height). Keep empty to use default setup. + * @param array{float|int,float|int}|array{}|'' $format Array(width,height). Keep empty to use default setup. * @param string $metric Unit of format ('mm') - * @param string $pagetype 'P' or 'l' + * @param 'P'|'l' $pagetype 'P' or 'l' * @return TCPDF|TCPDI PDF object */ function pdf_getInstance($format = '', $metric = 'mm', $pagetype = 'P') diff --git a/htdocs/core/modules/bom/mod_bom_advanced.php b/htdocs/core/modules/bom/mod_bom_advanced.php index 65b3edf3b68..18cbfa0cdb6 100644 --- a/htdocs/core/modules/bom/mod_bom_advanced.php +++ b/htdocs/core/modules/bom/mod_bom_advanced.php @@ -107,7 +107,7 @@ class mod_bom_advanced extends ModeleNumRefBoms $old_code_type = $mysoc->typent_code; $mysoc->code_client = 'CCCCCCCCCC'; $mysoc->typent_code = 'TTTTTTTTTT'; - $numExample = $this->getNextValue($mysoc, ''); + $numExample = $this->getNextValue($mysoc, null); $mysoc->code_client = $old_code_client; $mysoc->typent_code = $old_code_type; @@ -120,9 +120,9 @@ class mod_bom_advanced extends ModeleNumRefBoms /** * Return next free value * - * @param Product $objprod Object product - * @param Bom $object Object we need next value for - * @return string|int Next value if OK, 0 if KO + * @param Product $objprod Object product + * @param ?Bom $object Object we need next value for + * @return string|int<-1,0> Next value if OK, 0 if KO */ public function getNextValue($objprod, $object) { diff --git a/htdocs/core/modules/bom/mod_bom_standard.php b/htdocs/core/modules/bom/mod_bom_standard.php index 5b3d8006cfa..e4d93ed4014 100644 --- a/htdocs/core/modules/bom/mod_bom_standard.php +++ b/htdocs/core/modules/bom/mod_bom_standard.php @@ -114,9 +114,9 @@ class mod_bom_standard extends ModeleNumRefBoms /** * Return next free value * - * @param Product $objprod Object product - * @param Bom $object Object we need next value for - * @return string|int<-1,-1> Next value if OK, -1 if KO + * @param Product $objprod Object product + * @param ?Bom $object Object we need next value for + * @return string|int<-1,0> Next value if OK, 0 if KO */ public function getNextValue($objprod, $object) { diff --git a/htdocs/core/modules/bom/modules_bom.php b/htdocs/core/modules/bom/modules_bom.php index ed78515888a..d1f00a27e9f 100644 --- a/htdocs/core/modules/bom/modules_bom.php +++ b/htdocs/core/modules/bom/modules_bom.php @@ -88,9 +88,9 @@ abstract class ModeleNumRefBoms extends CommonNumRefGenerator /** * Return next free value * - * @param Product $objprod Object product - * @param Bom $object Object we need next value for - * @return string|int<-1,-1> Next value if OK, -1 if KO + * @param Product $objprod Object product + * @param ?Bom $object Object we need next value for + * @return string|int<-1,0> Next value if OK, 0 if KO */ abstract public function getNextValue($objprod, $object); } diff --git a/htdocs/core/modules/facture/mod_facture_mars.php b/htdocs/core/modules/facture/mod_facture_mars.php index 3bf4271aa06..bef545ffe48 100644 --- a/htdocs/core/modules/facture/mod_facture_mars.php +++ b/htdocs/core/modules/facture/mod_facture_mars.php @@ -160,9 +160,9 @@ class mod_facture_mars extends ModeleNumRefFactures * Return next value not used or last value used * * @param Societe $objsoc Object third party - * @param Facture $invoice Object invoice + * @param ?Facture $invoice Object invoice * @param string $mode 'next' for next value or 'last' for last value - * @return string|int<-1,1> Value if OK, <=0 if KO + * @return string|int<-1,0> Value if OK, <=0 if KO */ public function getNextValue($objsoc, $invoice, $mode = 'next') { diff --git a/htdocs/core/modules/facture/mod_facture_mercure.php b/htdocs/core/modules/facture/mod_facture_mercure.php index 9ff41aa2258..3c5334bfa03 100644 --- a/htdocs/core/modules/facture/mod_facture_mercure.php +++ b/htdocs/core/modules/facture/mod_facture_mercure.php @@ -125,7 +125,7 @@ class mod_facture_mercure extends ModeleNumRefFactures $old_code_type = $mysoc->typent_code; $mysoc->code_client = 'CCCCCCCCCC'; $mysoc->typent_code = 'TTTTTTTTTT'; - $numExample = $this->getNextValue($mysoc, ''); + $numExample = $this->getNextValue($mysoc, null); $mysoc->code_client = $old_code_client; $mysoc->typent_code = $old_code_type; @@ -139,9 +139,9 @@ class mod_facture_mercure extends ModeleNumRefFactures * Return next value not used or last value used * * @param Societe $objsoc Object third party - * @param Facture $invoice Object invoice + * @param ?Facture $invoice Object invoice * @param string $mode 'next' for next value or 'last' for last value - * @return string|int<-1,1> Value if OK, <=0 if KO + * @return string|int<-1,0> Value if OK, <=0 if KO */ public function getNextValue($objsoc, $invoice, $mode = 'next') { diff --git a/htdocs/core/modules/facture/mod_facture_terre.php b/htdocs/core/modules/facture/mod_facture_terre.php index 25ac8001b86..38866d581cc 100644 --- a/htdocs/core/modules/facture/mod_facture_terre.php +++ b/htdocs/core/modules/facture/mod_facture_terre.php @@ -201,9 +201,9 @@ class mod_facture_terre extends ModeleNumRefFactures * ALTER TABLE llx_facture ADD INDEX calculated_numrefonly_idx (calculated_numrefonly); * * @param Societe $objsoc Object third party - * @param Facture $invoice Object invoice + * @param ?Facture $invoice Object invoice * @param string $mode 'next' for next value or 'last' for last value - * @return string|int<-1,1> Value if OK, <=0 if KO + * @return string|int<-1,0> Value if OK, <=0 if KO */ public function getNextValue($objsoc, $invoice, $mode = 'next') { diff --git a/htdocs/core/modules/facture/modules_facture.php b/htdocs/core/modules/facture/modules_facture.php index 2bf9f1fc516..586e7f8a414 100644 --- a/htdocs/core/modules/facture/modules_facture.php +++ b/htdocs/core/modules/facture/modules_facture.php @@ -272,9 +272,9 @@ abstract class ModeleNumRefFactures extends CommonNumRefGenerator * Return next value not used or last value used * * @param Societe $objsoc Object third party - * @param Facture $invoice Object invoice + * @param ?Facture $invoice Object invoice * @param string $mode 'next' for next value or 'last' for last value - * @return string|int<-1,1> Value if OK, <=0 if KO + * @return string|int<-1,0> Value if OK, <=0 if KO */ abstract public function getNextValue($objsoc, $invoice, $mode = 'next'); } diff --git a/htdocs/core/tpl/massactions_pre.tpl.php b/htdocs/core/tpl/massactions_pre.tpl.php index d479a223a12..957b9b6d5b8 100644 --- a/htdocs/core/tpl/massactions_pre.tpl.php +++ b/htdocs/core/tpl/massactions_pre.tpl.php @@ -31,7 +31,10 @@ // $object = Object fetched; // $sendto // $withmaindocfilemail -'@phan-var-force CommonObject $objecttmp'; +' +@phan-var-force CommonObject $objecttmp +@phan-var-force int[] $toselect +'; if (!empty($sall) || !empty($search_all)) { $search_all = empty($sall) ? $search_all : $sall; diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php index 5b3ef03053c..12cbf3f9dae 100644 --- a/htdocs/projet/class/task.class.php +++ b/htdocs/projet/class/task.class.php @@ -1041,8 +1041,8 @@ class Task extends CommonObjectLine * Return list of tasks for all projects or for one particular project * Sort order is on project, then on position of task, and last on start date of first level task * - * @param User $usert Object user to limit tasks affected to a particular user - * @param User $userp Object user to limit projects of a particular user and public projects + * @param ?User $usert Object user to limit tasks affected to a particular user + * @param ?User $userp Object user to limit projects of a particular user and public projects * @param int $projectid Project id * @param int $socid Third party id * @param int $mode 0=Return list of tasks and their projects, 1=Return projects and tasks if exists @@ -1053,12 +1053,12 @@ class Task extends CommonObjectLine * @param int $filterontaskuser Filter on user assigned to task * @param ?Extrafields $extrafields Show additional column from project or task * @param int $includebilltime Calculate also the time to bill and billed - * @param array $search_array_options Array of search filters. Not Used yet. + * @param array $search_array_options Array of search filters. Not Used yet. * @param int $loadextras Fetch all Extrafields on each project and task * @param int $loadRoleMode 1= will test Roles on task; 0 used in delete project action * @param string $sortfield Sort field * @param string $sortorder Sort order - * @return array|string Array of tasks + * @return Task[]|string Array of tasks */ public function getTasksArray($usert = null, $userp = null, $projectid = 0, $socid = 0, $mode = 0, $filteronproj = '', $filteronprojstatus = '-1', $morewherefilter = '', $filteronprojuser = 0, $filterontaskuser = 0, $extrafields = null, $includebilltime = 0, $search_array_options = array(), $loadextras = 0, $loadRoleMode = 1, $sortfield = '', $sortorder = '') { diff --git a/htdocs/projet/contact.php b/htdocs/projet/contact.php index 773e7fad1a1..60ce796b03a 100644 --- a/htdocs/projet/contact.php +++ b/htdocs/projet/contact.php @@ -105,7 +105,8 @@ if (empty($reshook)) { foreach ($task_array as $task) { $task_already_affected = false; $personsLinked = $task->liste_contact(-1, $source); - if (!is_array($personsLinked) && count($personsLinked) < 0) { + if (!is_array($personsLinked)) { + // When liste_contact() does not return an array, it's an error. setEventMessage($object->error, 'errors'); } else { foreach ($personsLinked as $person) {