From d7c926a08bcefcbeee17f4da3db526fa24e08f03 Mon Sep 17 00:00:00 2001 From: MDW Date: Mon, 24 Feb 2025 16:12:19 +0100 Subject: [PATCH 1/6] Qual: PHPdoc for anonymous function --- htdocs/core/lib/functions.lib.php | 39 +++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index b102c45408c..17215e8b665 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1180,7 +1180,9 @@ function GETPOSTDATE($prefix, $hourTime = '', $gm = 'auto', $saverestore = '') $minute = intval($m[2]); $second = intval($m[3]); } elseif ($hourTime === 'end') { - $hour = 23; $minute = 59; $second = 59; + $hour = 23; + $minute = 59; + $second = 59; } else { $hour = $minute = $second = 0; } @@ -10674,14 +10676,14 @@ function dol_eval_new($s) { // Only this global variables can be read by eval function and returned to caller global $conf, // Read of const is done with getDolGlobalString() but we need $conf->currency for example - $db, $langs, $user, $website, $websitepage, - $action, $mainmenu, $leftmenu, - $mysoc, - $objectoffield, // To allow the use of $objectoffield in computed fields + $db, $langs, $user, $website, $websitepage, + $action, $mainmenu, $leftmenu, + $mysoc, + $objectoffield, // To allow the use of $objectoffield in computed fields - // Old variables used - $object, - $obj; // To get $obj used into list when dol_eval() is used for computed fields and $obj is not yet $object + // Old variables used + $object, + $obj; // To get $obj used into list when dol_eval() is used for computed fields and $obj is not yet $object // PHP < 7.4.0 defined('T_COALESCE_EQUAL') || define('T_COALESCE_EQUAL', PHP_INT_MAX); @@ -11870,10 +11872,23 @@ function dolExplodeKeepIfQuotes($input) preg_match_all('/"([^"]*)"|\'([^\']*)\'|(\S+)/', $input, $matches); // Merge result and delete empty values - // @phan-suppress-next-line PhanPluginUnknownClosureParamType, PhanPluginUnknownClosureReturnType - return array_filter(array_map(function ($a, $b, $c) { - return $a ?: ($b ?: $c); - }, $matches[1], $matches[2], $matches[3])); + return array_filter(array_map( + /** + * Return first non-empty item, or empty string + * + * @param string $a Possibly empty item - match "" + * @param string $b Possibly empty item - match '' + * @param string $c Non empty string if $a and $b are empty + * + * @return string + */ + static function ($a, $b, $c) { + return $a ?: ($b ?: $c); + }, + $matches[1], + $matches[2], + $matches[3] + )); } From 116913abeb1464029dd9746cdc2ec2e6c56a77f8 Mon Sep 17 00:00:00 2001 From: MDW Date: Mon, 24 Feb 2025 17:23:12 +0100 Subject: [PATCH 2/6] Qual: Fix unmatchedArgment* --- dev/tools/phan/baseline.txt | 54 +++++++++++-------- htdocs/categories/edit.php | 4 +- htdocs/core/class/hookmanager.class.php | 2 +- htdocs/core/lib/functions.lib.php | 40 +++++++------- .../facture/doc/pdf_octopus.modules.php | 1 + htdocs/product/class/product.class.php | 10 ++-- htdocs/projet/tasks/task.php | 2 +- htdocs/user/card.php | 4 +- htdocs/user/group/card.php | 4 +- 9 files changed, 67 insertions(+), 54 deletions(-) diff --git a/dev/tools/phan/baseline.txt b/dev/tools/phan/baseline.txt index c2382f6e823..2c9cc23ca11 100644 --- a/dev/tools/phan/baseline.txt +++ b/dev/tools/phan/baseline.txt @@ -9,11 +9,11 @@ */ return [ // # Issue statistics: - // PhanTypeMismatchArgument : 1380+ occurrences - // PhanUndeclaredProperty : 500+ occurrences + // PhanTypeMismatchArgument : 1360+ occurrences + // PhanUndeclaredProperty : 640+ occurrences // PhanTypeMismatchArgumentNullable : 310+ occurrences // PhanPluginUnknownArrayMethodReturnType : 170+ occurrences - // PhanTypeMismatchProperty : 120+ occurrences + // PhanTypeMismatchProperty : 160+ occurrences // PhanPluginUnknownArrayMethodParamType : 110+ occurrences // PhanUndeclaredGlobalVariable : 100+ occurrences // PhanTypeMismatchArgumentProbablyReal : 35+ occurrences @@ -78,7 +78,7 @@ return [ 'htdocs/adherents/admin/member.php' => ['PhanTypeMismatchArgument'], 'htdocs/adherents/admin/website.php' => ['PhanTypeMismatchArgument'], 'htdocs/adherents/canvas/actions_adherentcard_common.class.php' => ['PhanTypeMismatchArgument'], - 'htdocs/adherents/card.php' => ['PhanTypeMismatchArgument'], + 'htdocs/adherents/card.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchProperty'], 'htdocs/adherents/class/adherent.class.php' => ['PhanTypeMismatchArgumentNullable'], 'htdocs/adherents/class/adherent_type.class.php' => ['PhanTypeMismatchArgument'], 'htdocs/adherents/class/api_members.class.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], @@ -128,7 +128,7 @@ return [ 'htdocs/api/class/api_setup.class.php' => ['PhanPluginUnknownArrayMethodReturnType', 'PhanTypeMismatchArgument'], 'htdocs/api/class/api_status.class.php' => ['PhanPluginUnknownArrayMethodReturnType'], 'htdocs/asset/admin/setup.php' => ['PhanTypeMismatchArgument'], - 'htdocs/asset/card.php' => ['PhanTypeMismatchArgument'], + 'htdocs/asset/card.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchProperty'], 'htdocs/asset/class/asset.class.php' => ['PhanPluginUndeclaredVariableIsset', 'PhanTypeInvalidDimOffset', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], 'htdocs/asset/class/assetdepreciationoptions.class.php' => ['PhanTypeInvalidDimOffset'], 'htdocs/asset/class/assetmodel.class.php' => ['PhanUndeclaredProperty'], @@ -160,7 +160,7 @@ return [ 'htdocs/categories/photos.php' => ['PhanTypeMismatchArgument'], 'htdocs/categories/viewcat.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanUndeclaredProperty'], 'htdocs/collab/index.php' => ['PhanParamTooMany', 'PhanUndeclaredProperty'], - 'htdocs/comm/action/card.php' => ['PhanPluginBothLiteralsBinaryOp', 'PhanTypeMismatchArgument'], + 'htdocs/comm/action/card.php' => ['PhanPluginBothLiteralsBinaryOp', 'PhanTypeMismatchArgument', 'PhanTypeMismatchProperty'], 'htdocs/comm/action/class/actioncomm.class.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], 'htdocs/comm/action/class/api_agendaevents.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanTypeMismatchProperty'], 'htdocs/comm/action/class/cactioncomm.class.php' => ['PhanPluginUnknownArrayPropertyType'], @@ -168,10 +168,10 @@ return [ 'htdocs/comm/action/index.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchDimFetch', 'PhanTypeMismatchProperty'], 'htdocs/comm/action/info.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredProperty'], 'htdocs/comm/action/list.php' => ['PhanTypeMismatchArgument'], - 'htdocs/comm/action/pertype.php' => ['PhanTypeComparisonFromArray', 'PhanTypeExpectedObjectPropAccess', 'PhanTypeMismatchArgument', 'PhanTypeMismatchDimFetch'], + 'htdocs/comm/action/pertype.php' => ['PhanTypeComparisonFromArray', 'PhanTypeExpectedObjectPropAccess', 'PhanTypeMismatchDimFetch'], 'htdocs/comm/action/peruser.php' => ['PhanTypeComparisonFromArray', 'PhanTypeMismatchArgument'], 'htdocs/comm/action/rapport/index.php' => ['PhanTypeMismatchArgument'], - 'htdocs/comm/card.php' => ['PhanTypeMismatchArgument'], + 'htdocs/comm/card.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchProperty'], 'htdocs/comm/mailing/card.php' => ['PhanPluginSuspiciousParamPosition', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], 'htdocs/comm/mailing/cibles.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanUndeclaredProperty'], 'htdocs/comm/mailing/class/advtargetemailing.class.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], @@ -191,7 +191,7 @@ return [ 'htdocs/comm/remise.php' => ['PhanTypeMismatchArgument'], 'htdocs/comm/remx.php' => ['PhanTypeMismatchArgument'], 'htdocs/commande/agenda.php' => ['PhanTypeMismatchArgument'], - 'htdocs/commande/card.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], + 'htdocs/commande/card.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchProperty'], 'htdocs/commande/class/api_orders.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanTypeMismatchArgument'], 'htdocs/commande/class/commande.class.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanUndeclaredProperty'], 'htdocs/commande/class/orderline.class.php' => ['PhanTypeMismatchArgument'], @@ -231,7 +231,7 @@ return [ 'htdocs/compta/deplacement/stats/index.php' => ['PhanTypeMismatchArgument'], 'htdocs/compta/facture/agenda-rec.php' => ['PhanTypeMismatchArgument'], 'htdocs/compta/facture/agenda.php' => ['PhanTypeMismatchArgument'], - 'htdocs/compta/facture/card-rec.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], + 'htdocs/compta/facture/card-rec.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchProperty'], 'htdocs/compta/facture/card.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchProperty', 'PhanUndeclaredProperty'], 'htdocs/compta/facture/class/api_invoices.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanTypeComparisonFromArray', 'PhanTypeMismatchArgumentProbablyReal'], 'htdocs/compta/facture/class/facture-rec.class.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredProperty'], @@ -260,7 +260,7 @@ return [ 'htdocs/compta/paiement/class/paiement.class.php' => ['PhanTypeMismatchArgumentNullable'], 'htdocs/compta/paiement/list.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullableInternal', 'PhanUndeclaredGlobalVariable'], 'htdocs/compta/paiement/rapport.php' => ['PhanTypeMismatchArgument'], - 'htdocs/compta/prelevement/card.php' => ['PhanTypeMismatchArgument'], + 'htdocs/compta/prelevement/card.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchProperty'], 'htdocs/compta/prelevement/class/bonprelevement.class.php' => ['PhanTypeMismatchArgumentNullable'], 'htdocs/compta/prelevement/class/rejetprelevement.class.php' => ['PhanTypeMismatchArgument'], 'htdocs/compta/prelevement/demandes.php' => ['PhanTypeMismatchArgumentNullable'], @@ -269,7 +269,7 @@ return [ 'htdocs/compta/resultat/index.php' => ['PhanTypeMismatchArgument'], 'htdocs/compta/resultat/projects.php' => ['PhanTypeMismatchArgument'], 'htdocs/compta/resultat/result.php' => ['PhanTypeMismatchArgument'], - 'htdocs/compta/sociales/card.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredProperty'], + 'htdocs/compta/sociales/card.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchProperty', 'PhanUndeclaredProperty'], 'htdocs/compta/sociales/list.php' => ['PhanTypeMismatchArgument'], 'htdocs/compta/sociales/payments.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], 'htdocs/compta/stats/cabyprodserv.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], @@ -285,7 +285,7 @@ return [ 'htdocs/compta/tva/quadri_detail.php' => ['PhanTypeArraySuspiciousNull', 'PhanTypeInvalidDimOffset', 'PhanTypeMismatchArgument', 'PhanTypeMismatchProperty'], 'htdocs/contact/ajax/contact.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], 'htdocs/contact/canvas/actions_contactcard_common.class.php' => ['PhanTypeMismatchArgument'], - 'htdocs/contact/card.php' => ['PhanTypeMismatchArgument'], + 'htdocs/contact/card.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchProperty'], 'htdocs/contact/class/contact.class.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], 'htdocs/contact/consumption.php' => ['PhanTypeMismatchArgument'], 'htdocs/contact/list.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], @@ -359,7 +359,7 @@ return [ 'htdocs/core/lib/date.lib.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/lib/expedition.lib.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/lib/files.lib.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanUndeclaredProperty'], - 'htdocs/core/lib/functions.lib.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], + 'htdocs/core/lib/functions.lib.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/lib/functions2.lib.php' => ['PhanUndeclaredProperty'], 'htdocs/core/lib/functionsnumtoword.lib.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/lib/images.lib.php' => ['PhanTypeMismatchArgumentNullable'], @@ -432,6 +432,7 @@ return [ 'htdocs/core/modules/workstation/mod_workstation_advanced.php' => ['PhanUndeclaredProperty'], 'htdocs/core/multicompany_page.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/search_page.php' => ['PhanTypeMismatchArgument'], + 'htdocs/core/tpl/document_actions_post_headers.tpl.php' => ['PhanTypeMismatchArgumentNullable'], 'htdocs/core/tpl/extrafields_list_array_fields.tpl.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/tpl/extrafields_list_print_fields.tpl.php' => ['PhanTypeMismatchArgumentNullable'], 'htdocs/core/tpl/extrafields_view.tpl.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredProperty'], @@ -451,8 +452,10 @@ return [ 'htdocs/datapolicy/class/datapolicycron.class.php' => ['PhanTypeMismatchArgument'], 'htdocs/dav/dav.class.php' => ['PhanTypeMismatchArgument'], 'htdocs/debugbar/class/TraceableDB.php' => ['PhanTypeMismatchArgument'], + 'htdocs/delivery/card.php' => ['PhanTypeMismatchProperty'], 'htdocs/delivery/class/delivery.class.php' => ['PhanUndeclaredProperty'], 'htdocs/don/admin/donation.php' => ['PhanUndeclaredMethod'], + 'htdocs/don/card.php' => ['PhanTypeMismatchProperty'], 'htdocs/don/class/api_donations.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType'], 'htdocs/don/class/don.class.php' => ['PhanParamTooMany'], 'htdocs/don/document.php' => ['PhanUndeclaredGlobalVariable'], @@ -480,9 +483,10 @@ return [ 'htdocs/expedition/class/expedition.class.php' => ['PhanTypeMismatchArgumentNullable', 'PhanUndeclaredProperty'], 'htdocs/expedition/class/expeditionlinebatch.class.php' => ['PhanTypeMismatchArgumentNullable'], 'htdocs/expedition/list.php' => ['PhanTypeMismatchArgument'], + 'htdocs/expedition/shipment.php' => ['PhanTypeMismatchProperty'], 'htdocs/expedition/stats/index.php' => ['PhanTypeMismatchArgument'], 'htdocs/expensereport/ajax/ajaxik.php' => ['PhanTypeMismatchArgument'], - 'htdocs/expensereport/card.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredProperty'], + 'htdocs/expensereport/card.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchProperty', 'PhanUndeclaredProperty'], 'htdocs/expensereport/class/api_expensereports.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType'], 'htdocs/expensereport/class/expensereport.class.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], 'htdocs/expensereport/class/expensereportline.class.php' => ['PhanTypeMismatchArgument'], @@ -497,6 +501,7 @@ return [ 'htdocs/externalsite/frames.php' => ['PhanUndeclaredGlobalVariable'], 'htdocs/fichinter/agenda.php' => ['PhanTypeMismatchArgument'], 'htdocs/fichinter/card-rec.php' => ['PhanUndeclaredGlobalVariable'], + 'htdocs/fichinter/card.php' => ['PhanTypeMismatchProperty'], 'htdocs/fichinter/class/api_interventions.class.php' => ['PhanTypeMismatchArgumentNullable', 'PhanUndeclaredProperty'], 'htdocs/fichinter/class/fichinterrec.class.php' => ['PhanUndeclaredProperty'], 'htdocs/fichinter/contact.php' => ['PhanTypeMismatchArgument'], @@ -506,6 +511,7 @@ return [ 'htdocs/fichinter/stats/index.php' => ['PhanTypeMismatchArgument'], 'htdocs/fichinter/tpl/linkedobjectblock.tpl.php' => ['PhanUndeclaredProperty'], 'htdocs/filefunc.inc.php' => ['PhanPluginUndeclaredVariableIsset', 'PhanPossiblyUndeclaredGlobalVariable', 'PhanUndeclaredGlobalVariable'], + 'htdocs/fourn/card.php' => ['PhanTypeMismatchProperty'], 'htdocs/fourn/class/api_supplier_invoices.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanTypeMismatchArgument'], 'htdocs/fourn/class/api_supplier_orders.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanTypeMismatchArgumentProbablyReal'], 'htdocs/fourn/class/fournisseur.commande.class.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanUndeclaredProperty'], @@ -515,13 +521,14 @@ return [ 'htdocs/fourn/class/fournisseur.facture.ligne.class.php' => ['PhanTypeMismatchArgument'], 'htdocs/fourn/class/fournisseur.orderline.class.php' => ['PhanTypeMismatchArgument'], 'htdocs/fourn/class/fournisseur.product.class.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], - 'htdocs/fourn/commande/card.php' => ['PhanTypeMismatchDimAssignment', 'PhanTypeSuspiciousStringExpression', 'PhanUndeclaredProperty'], + 'htdocs/fourn/commande/card.php' => ['PhanTypeMismatchDimAssignment', 'PhanTypeMismatchProperty', 'PhanTypeSuspiciousStringExpression', 'PhanUndeclaredProperty'], 'htdocs/fourn/commande/dispatch.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], - 'htdocs/fourn/facture/card-rec.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'], + 'htdocs/fourn/facture/card-rec.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchProperty', 'PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'], 'htdocs/fourn/facture/card.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchProperty'], 'htdocs/fourn/facture/paiement.php' => ['PhanUndeclaredGlobalVariable'], 'htdocs/fourn/facture/rapport.php' => ['PhanTypeMismatchArgument'], 'htdocs/fourn/facture/tpl/linkedobjectblock.tpl.php' => ['PhanUndeclaredProperty'], + 'htdocs/holiday/card.php' => ['PhanTypeMismatchProperty'], 'htdocs/holiday/card_group.php' => ['PhanTypeMismatchArgument'], 'htdocs/holiday/list.php' => ['PhanUndeclaredGlobalVariable'], 'htdocs/hrm/class/evaluation.class.php' => ['PhanUndeclaredProperty'], @@ -556,12 +563,15 @@ return [ 'htdocs/partnership/core/modules/partnership/mod_partnership_advanced.php' => ['PhanUndeclaredProperty'], 'htdocs/partnership/partnership_card.php' => ['PhanUndeclaredGlobalVariable'], 'htdocs/partnership/partnership_list.php' => ['PhanUndeclaredProperty'], + 'htdocs/product/card.php' => ['PhanTypeMismatchProperty'], 'htdocs/product/class/api_products.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanTypeMismatchArgument', 'PhanUndeclaredProperty'], 'htdocs/product/class/html.formproduct.class.php' => ['PhanUndeclaredProperty'], 'htdocs/product/class/productfournisseurprice.class.php' => ['PhanUndeclaredMethod', 'PhanUndeclaredProperty'], 'htdocs/product/inventory/class/inventory.class.php' => ['PhanUndeclaredProperty'], 'htdocs/product/price.php' => ['PhanUndeclaredProperty'], + 'htdocs/product/price_suppliers.php' => ['PhanTypeMismatchProperty'], 'htdocs/product/reassort.php' => ['PhanTypeExpectedObjectPropAccessButGotNull'], + 'htdocs/product/stock/card.php' => ['PhanTypeMismatchProperty'], 'htdocs/product/stock/class/api_stockmovements.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanTypeMismatchArgument'], 'htdocs/product/stock/class/api_warehouses.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType'], 'htdocs/product/stock/info.php' => ['PhanUndeclaredProperty'], @@ -578,8 +588,9 @@ return [ 'htdocs/product/stock/tpl/stockcorrection.tpl.php' => ['PhanUndeclaredProperty'], 'htdocs/product/stock/tpl/stocktransfer.tpl.php' => ['PhanUndeclaredProperty'], 'htdocs/projet/admin/project.php' => ['PhanTypeMismatchArgumentProbablyReal'], - 'htdocs/projet/card.php' => ['PhanTypeMismatchArgumentNullable', 'PhanUndeclaredGlobalVariable'], + 'htdocs/projet/card.php' => ['PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchProperty', 'PhanUndeclaredGlobalVariable'], 'htdocs/projet/class/api_tasks.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanTypeMismatchArgument'], + 'htdocs/projet/tasks.php' => ['PhanTypeMismatchArgument'], 'htdocs/projet/tasks/time.php' => ['PhanTypeInvalidDimOffset', 'PhanTypeMismatchArgument', 'PhanUndeclaredProperty'], 'htdocs/projet/tasks/tpl/linkedobjectblock.tpl.php' => ['PhanUndeclaredProperty'], 'htdocs/public/eventorganization/subscriptionok.php' => ['PhanUndeclaredGlobalVariable'], @@ -592,10 +603,10 @@ return [ 'htdocs/public/project/viewandvote.php' => ['PhanUndeclaredGlobalVariable'], 'htdocs/public/recruitment/view.php' => ['PhanUndeclaredGlobalVariable'], 'htdocs/public/webportal/tpl/menu.tpl.php' => ['PhanUndeclaredProperty'], - 'htdocs/reception/card.php' => ['PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'], + 'htdocs/reception/card.php' => ['PhanTypeMismatchProperty', 'PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'], 'htdocs/reception/class/api_receptions.class.php' => ['PhanTypeMismatchArgumentNullable'], 'htdocs/reception/class/reception.class.php' => ['PhanUndeclaredProperty'], - 'htdocs/reception/list.php' => ['PhanUndeclaredProperty'], + 'htdocs/reception/list.php' => ['PhanTypeMismatchArgumentNullable', 'PhanUndeclaredProperty'], 'htdocs/recruitment/class/recruitmentcandidature.class.php' => ['PhanUndeclaredProperty'], 'htdocs/recruitment/class/recruitmentjobposition.class.php' => ['PhanUndeclaredProperty'], 'htdocs/recruitment/core/modules/recruitment/doc/pdf_standard_recruitmentjobposition.modules.php' => ['PhanUndeclaredProperty'], @@ -612,11 +623,12 @@ return [ 'htdocs/salaries/paiement_salary.php' => ['PhanUndeclaredProperty'], 'htdocs/salaries/virement_request.php' => ['PhanUndeclaredProperty'], 'htdocs/societe/ajax/company.php' => ['PhanUndeclaredProperty'], + 'htdocs/societe/card.php' => ['PhanTypeMismatchProperty'], 'htdocs/societe/class/api_thirdparties.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchArgumentProbablyReal', 'PhanTypeMismatchProperty'], 'htdocs/societe/class/societe.class.php' => ['PhanTypeMismatchProperty'], 'htdocs/societe/paymentmodes.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgument'], 'htdocs/stripe/class/stripe.class.php' => ['PhanTypeExpectedObjectPropAccess'], - 'htdocs/supplier_proposal/card.php' => ['PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'], + 'htdocs/supplier_proposal/card.php' => ['PhanTypeMismatchProperty', 'PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'], 'htdocs/supplier_proposal/class/api_supplier_proposals.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanUndeclaredProperty'], 'htdocs/supplier_proposal/class/supplier_proposal.class.php' => ['PhanUndeclaredProperty'], 'htdocs/takepos/index.php' => ['PhanPluginUndeclaredVariableIsset'], diff --git a/htdocs/categories/edit.php b/htdocs/categories/edit.php index aa1c2a32439..d10758189df 100644 --- a/htdocs/categories/edit.php +++ b/htdocs/categories/edit.php @@ -4,7 +4,7 @@ * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2007 Patrick Raguin * Copyright (C) 2020-2024 Frédéric France - * Copyright (C) 2024 MDW + * Copyright (C) 2024-2025 MDW * * 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 @@ -110,7 +110,7 @@ if (empty($reshook)) { // Action mise a jour d'une categorie if ($action == 'update' && $user->hasRight('categorie', 'creer')) { - $object->oldcopy = dol_clone($object, 2); + $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty $object->label = $label; $object->description = dol_htmlcleanlastbr($description); diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php index bfc13a8d337..24b7341cb96 100644 --- a/htdocs/core/class/hookmanager.class.php +++ b/htdocs/core/class/hookmanager.class.php @@ -189,7 +189,7 @@ class HookManager * * @param string $method Name of method hooked ('doActions', 'printSearchForm', 'showInputField', ...) * @param array $parameters Array of parameters - * @param object $object Object to use hooks on + * @param null|Object|string $object Object to use hooks on @phan-ignore-reference * @param string $action Action code on calling page ('create', 'edit', 'view', 'add', 'update', 'delete'...) * @return int<-1,1> For 'addreplace' hooks (doActions, formConfirm, formObjectOptions, pdf_xxx,...): Return 0 if we want to keep standard actions, >0 if we want to stop/replace standard actions, <0 if KO. Things to print are returned into ->resprints and set into ->resPrint. Things to return are returned into ->results by hook and set into ->resArray for caller. * For 'output' hooks (printLeftBlock, formAddObjectLine, formBuilddocOptions, ...): Return 0 if we want to keep standard actions, >0 uf we want to stop/replace standard actions (at least one > 0 and replacement will be done), <0 if KO. Things to print are returned into ->resprints and set into ->resPrint. Things to return are returned into ->results by hook and set into ->resArray for caller. diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 17215e8b665..67fa18fa32b 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -2434,7 +2434,7 @@ function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename = if (!array_key_exists($level, $logLevels)) { dol_syslog('Error Bad Log Level '.$level, LOG_ERR); - $level = $logLevels[LOG_ERR]; + $level = LOG_ERR; } if ($level > getDolGlobalInt('SYSLOG_LEVEL')) { return; @@ -2463,12 +2463,12 @@ function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename = $data = array( 'message' => $message, - 'script' => (isset($_SERVER['PHP_SELF']) ? basename($_SERVER['PHP_SELF'], '.php') : false), + 'script' => (isset($_SERVER['PHP_SELF']) ? basename($_SERVER['PHP_SELF'], '.php') : ''), 'level' => $level, - 'user' => ((is_object($user) && $user->id) ? $user->login : false), - 'ip' => false, - 'osuser' => function_exists('posix_getuid') ? posix_getuid() : false, - 'ospid' => getmypid() // on linux, max value is defined into cat /proc/sys/kernel/pid_max + 'user' => ((is_object($user) && $user->id) ? $user->login : ''), + 'ip' => '', + 'osuser' => function_exists('posix_getuid') ? (string) posix_getuid() : '', + 'ospid' => (string) getmypid() // on linux, max value is defined into cat /proc/sys/kernel/pid_max ); $remoteip = getUserRemoteIP(); // Get ip when page run on a web server @@ -2482,20 +2482,20 @@ function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename = } } elseif (!empty($_SERVER['SERVER_ADDR'])) { // This is when PHP session is ran inside a web server but not inside a client request (example: init code of apache) - $data['ip'] = $_SERVER['SERVER_ADDR']; + $data['ip'] = (string) $_SERVER['SERVER_ADDR']; } elseif (!empty($_SERVER['COMPUTERNAME'])) { // This is when PHP session is ran outside a web server, like from Windows command line (Not always defined, but useful if OS defines it). - $data['ip'] = $_SERVER['COMPUTERNAME']; + $data['ip'] = (string) $_SERVER['COMPUTERNAME']; } else { $data['ip'] = '???'; } if (!empty($_SERVER['USERNAME'])) { // This is when PHP session is ran outside a web server, like from Linux command line (Not always defined, but useful if OS defines it). - $data['osuser'] = $_SERVER['USERNAME']; + $data['osuser'] = (string) $_SERVER['USERNAME']; } elseif (!empty($_SERVER['LOGNAME'])) { // This is when PHP session is ran outside a web server, like from Linux command line (Not always defined, but useful if OS defines it). - $data['osuser'] = $_SERVER['LOGNAME']; + $data['osuser'] = (string) $_SERVER['LOGNAME']; } // Loop on each log handler and send output @@ -3151,7 +3151,7 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi } } } elseif (!$phototoshow) { // example if modulepart = 'societe' or 'photo' or 'memberphoto' - $phototoshow .= $form->showphoto($modulepart, $object, 0, 0, 0, 'photowithmargin photoref', 'small', 1, 0, $maxvisiblephotos); + $phototoshow .= $form->showphoto($modulepart, $object, 0, 0, 0, 'photowithmargin photoref', 'small', 1, 0); } if ($phototoshow) { @@ -4771,9 +4771,9 @@ function dol_print_address($address, $htmlid, $element, $id, $noprint = 0, $char } if (empty($reshook)) { if (empty($charfornl)) { - $out .= nl2br($address); + $out .= nl2br((string) $address); } else { - $out .= preg_replace('/[\r\n]+/', $charfornl, $address); + $out .= preg_replace('/[\r\n]+/', $charfornl, (string) $address); } // TODO Remove this block, we can add this using the hook now @@ -6414,9 +6414,9 @@ function getTitleFieldOfList($name, $thead = 0, $file = "", $field = "", $begin } else { $tmptooltip = array($tooltip); } - $out .= $form->textwithpicto($langs->trans($name), $langs->trans($tmptooltip[0]), (empty($tmptooltip[2]) ? 1 : $tmptooltip[2]), 'help', '', 0, 3, (empty($tmptooltip[1]) ? '' : 'extra_'.str_replace('.', '_', $field).'_'.$tmptooltip[1])); + $out .= $form->textwithpicto($langs->trans((string) $name), $langs->trans($tmptooltip[0]), (empty($tmptooltip[2]) ? '1' : $tmptooltip[2]), 'help', '', 0, 3, (empty($tmptooltip[1]) ? '' : 'extra_'.str_replace('.', '_', $field).'_'.$tmptooltip[1])); } else { - $out .= $langs->trans($name); + $out .= $langs->trans((string) $name); } if (empty($thead) && $field && empty($disablesortlink)) { // If this is a sort field @@ -7190,7 +7190,7 @@ function showDimensionInBestUnit($dimension, $unit, $type, $outputlangs, $round * @param int $local Local tax to search and return (1 or 2 return only tax rate 1 or tax rate 2) * @param ?Societe $thirdparty_buyer Object of buying third party * @param ?Societe $thirdparty_seller Object of selling third party ($mysoc if not defined) - * @param int $vatnpr If vat rate is NPR or not + * @param int<0,1> $vatnpr If vat rate is NPR or not * @return int<0,0>|string 0 if not found, localtax rate if found (Can be '20', '-19:-15:-9') * @see get_default_tva() */ @@ -7300,7 +7300,7 @@ function get_localtax($vatrate, $local, $thirdparty_buyer = null, $thirdparty_se if (!empty($vatratecode)) { $sql .= " AND t.code ='".$db->escape($vatratecode)."'"; // If we have the code, we use it in priority } else { - $sql .= " AND t.recuperableonly = '".$db->escape($vatnpr)."'"; + $sql .= " AND t.recuperableonly = '".$db->escape((string) $vatnpr)."'"; } $resql = $db->query($sql); @@ -7547,7 +7547,7 @@ function get_product_vat_for_country($idprod, $thirdpartytouse, $idprodfournpric ) { // If country of thirdparty to consider is ours if ($idprodfournprice > 0) { // We want vat for product for a "supplier" object - $result = $product->get_buyprice($idprodfournprice, 0, 0, 0); + $result = $product->get_buyprice($idprodfournprice, 0, 0, ''); if ($result > 0) { $ret = $product->vatrate_supplier; if ($product->default_vat_code_supplier) { @@ -10154,7 +10154,7 @@ function setEventMessages($mesg, $mesgs, $style = 'mesgs', $messagekey = '', $no dol_print_error(null, 'Bad parameter style='.$style.' for setEventMessages'); } if (empty($mesgs)) { - setEventMessage($mesg, $style, $noduplicate, $attop); + setEventMessage((string) $mesg, $style, $noduplicate, $attop); } else { if (!empty($mesg) && !in_array($mesg, $mesgs)) { setEventMessage($mesg, $style, $noduplicate, $attop); // Add message string if not already into array @@ -12916,7 +12916,7 @@ function dolGetStatus($statusLabel = '', $statusLabelShort = '', $html = '', $st } else { // If a title was forced from $params['badgeParams']['attr']['title'], we set the class to get it as a tooltip. $dolGetBadgeParams['attr']['class'] .= ' classfortooltip'; // And if we use tooltip, we can output title in HTML @phan-suppress-next-line PhanTypeInvalidDimOffset - $dolGetBadgeParams['attr']['title'] = dol_htmlentitiesbr($dolGetBadgeParams['attr']['title'], 1); + $dolGetBadgeParams['attr']['title'] = dol_htmlentitiesbr((string) $dolGetBadgeParams['attr']['title'], 1); } if ($displayMode == 3) { diff --git a/htdocs/core/modules/facture/doc/pdf_octopus.modules.php b/htdocs/core/modules/facture/doc/pdf_octopus.modules.php index 792d86938fc..cf5e3aa55f2 100644 --- a/htdocs/core/modules/facture/doc/pdf_octopus.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_octopus.modules.php @@ -241,6 +241,7 @@ class pdf_octopus extends ModelePDFFactures $this->atleastonediscount = 0; $this->situationinvoice = true; if (!empty($object)) { + '@phan-var-force Facture $object'; // Supposing $object is Facture; $this->TDataSituation = $this->getDataSituation($object); } else { dol_syslog("object is empty, do not call getDataSituation..."); diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index f06a8fd29ec..88ab82da615 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -5935,9 +5935,9 @@ class Product extends CommonObject /** * Return label of status of object * - * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto - * @param int $type 0=Sell, 1=Buy, 2=Batch Number management - * @return string Label of status + * @param int<0,6> $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto + * @param int<0,2> $type 0=Sell, 1=Buy, 2=Batch Number management + * @return string Label of status */ public function getLibStatut($mode = 0, $type = 0) { @@ -5959,8 +5959,8 @@ class Product extends CommonObject * Return label of a given status * * @param int $status Statut - * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto - * @param int $type 0=Status "to sell", 1=Status "to buy", 2=Status "to Batch" + * @param int<0,6> $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto + * @param int<0,2> $type 0=Status "to sell", 1=Status "to buy", 2=Status "to Batch" * @return string Label of status */ public function LibStatut($status, $mode = 0, $type = 0) diff --git a/htdocs/projet/tasks/task.php b/htdocs/projet/tasks/task.php index 6afc01197d9..b82b92940ea 100644 --- a/htdocs/projet/tasks/task.php +++ b/htdocs/projet/tasks/task.php @@ -109,7 +109,7 @@ if ($action == 'update' && !GETPOST("cancel") && $user->hasRight('projet', 'cree setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")), null, 'errors'); } if (!$error) { - $object->oldcopy = clone $object; + $object->oldcopy = clone $object; // @phan-suppress-current-line PhanTypeMismatchProperty $tmparray = explode('_', GETPOST('task_parent')); $task_parent = $tmparray[1]; diff --git a/htdocs/user/card.php b/htdocs/user/card.php index 19d4d3cf424..75dcbe9d0dc 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -448,7 +448,7 @@ if (empty($reshook)) { if (!$error) { $object->fetch($id); - $object->oldcopy = clone $object; + $object->oldcopy = clone $object; // @phan-suppress-current-line PhanTypeMismatchProperty $db->begin(); @@ -687,7 +687,7 @@ if (empty($reshook)) { $object->fetch($id); if (GETPOST("password", "password")) { // If pass is empty, we do not change it. - $object->oldcopy = clone $object; + $object->oldcopy = clone $object; // @phan-suppress-current-line PhanTypeMismatchProperty $ret = $object->setPassword($user, GETPOST("password", "password")); if (is_int($ret) && $ret < 0) { diff --git a/htdocs/user/group/card.php b/htdocs/user/group/card.php index af5f69019c7..f1a07f585fb 100644 --- a/htdocs/user/group/card.php +++ b/htdocs/user/group/card.php @@ -177,7 +177,7 @@ if (empty($reshook)) { if (($action == 'adduser' || $action == 'removeuser') && $permissiontoedit) { if ($userid > 0) { $object->fetch($id); - $object->oldcopy = clone $object; + $object->oldcopy = clone $object; // @phan-suppress-current-line PhanTypeMismatchProperty $edituser = new User($db); $edituser->fetch($userid); @@ -203,7 +203,7 @@ if (empty($reshook)) { $object->fetch($id); - $object->oldcopy = clone $object; + $object->oldcopy = clone $object; // @phan-suppress-current-line PhanTypeMismatchProperty $object->name = GETPOST("nom", 'alphanohtml'); $object->note = dol_htmlcleanlastbr(trim(GETPOST("note", 'restricthtml'))); From 746dc675569dfd8dfb114f507e3f778fb4b5b16d Mon Sep 17 00:00:00 2001 From: MDW Date: Tue, 25 Feb 2025 13:18:18 +0100 Subject: [PATCH 3/6] Qual: Allow notices for functions.lib.php --- dev/tools/phan/baseline.txt | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/dev/tools/phan/baseline.txt b/dev/tools/phan/baseline.txt index 2c9cc23ca11..91d0a7145b5 100644 --- a/dev/tools/phan/baseline.txt +++ b/dev/tools/phan/baseline.txt @@ -9,7 +9,7 @@ */ return [ // # Issue statistics: - // PhanTypeMismatchArgument : 1360+ occurrences + // PhanTypeMismatchArgument : 1320+ occurrences // PhanUndeclaredProperty : 640+ occurrences // PhanTypeMismatchArgumentNullable : 310+ occurrences // PhanPluginUnknownArrayMethodReturnType : 170+ occurrences @@ -17,9 +17,9 @@ return [ // PhanPluginUnknownArrayMethodParamType : 110+ occurrences // PhanUndeclaredGlobalVariable : 100+ occurrences // PhanTypeMismatchArgumentProbablyReal : 35+ occurrences - // PhanTypeExpectedObjectPropAccess : 30+ occurrences // PhanPossiblyUndeclaredGlobalVariable : 25+ occurrences - // PhanTypeInvalidDimOffset : 25+ occurrences + // PhanTypeExpectedObjectPropAccess : 25+ occurrences + // PhanTypeInvalidDimOffset : 20+ occurrences // PhanTypeMismatchDimFetch : 20+ occurrences // PhanPluginUndeclaredVariableIsset : 15+ occurrences // PhanUndeclaredConstant : 15+ occurrences @@ -359,7 +359,6 @@ return [ 'htdocs/core/lib/date.lib.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/lib/expedition.lib.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/lib/files.lib.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanUndeclaredProperty'], - 'htdocs/core/lib/functions.lib.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/lib/functions2.lib.php' => ['PhanUndeclaredProperty'], 'htdocs/core/lib/functionsnumtoword.lib.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/lib/images.lib.php' => ['PhanTypeMismatchArgumentNullable'], From 586a28f87913d4609be04764df3e03de9e11f8e0 Mon Sep 17 00:00:00 2001 From: MDW Date: Fri, 28 Feb 2025 15:57:47 +0100 Subject: [PATCH 4/6] Qual: Fix new false positives in hookmanager --- dev/tools/phan/baseline.txt | 8 ++++---- htdocs/core/class/hookmanager.class.php | 11 ++++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/dev/tools/phan/baseline.txt b/dev/tools/phan/baseline.txt index 91d0a7145b5..3715beb0308 100644 --- a/dev/tools/phan/baseline.txt +++ b/dev/tools/phan/baseline.txt @@ -9,17 +9,17 @@ */ return [ // # Issue statistics: - // PhanTypeMismatchArgument : 1320+ occurrences - // PhanUndeclaredProperty : 640+ occurrences + // PhanTypeMismatchArgument : 1300+ occurrences + // PhanUndeclaredProperty : 480+ occurrences // PhanTypeMismatchArgumentNullable : 310+ occurrences // PhanPluginUnknownArrayMethodReturnType : 170+ occurrences // PhanTypeMismatchProperty : 160+ occurrences // PhanPluginUnknownArrayMethodParamType : 110+ occurrences // PhanUndeclaredGlobalVariable : 100+ occurrences - // PhanTypeMismatchArgumentProbablyReal : 35+ occurrences // PhanPossiblyUndeclaredGlobalVariable : 25+ occurrences // PhanTypeExpectedObjectPropAccess : 25+ occurrences // PhanTypeInvalidDimOffset : 20+ occurrences + // PhanTypeMismatchArgumentProbablyReal : 20+ occurrences // PhanTypeMismatchDimFetch : 20+ occurrences // PhanPluginUndeclaredVariableIsset : 15+ occurrences // PhanUndeclaredConstant : 15+ occurrences @@ -33,6 +33,7 @@ return [ // PhanEmptyFQSENInClasslike : 3 occurrences // PhanInvalidFQSENInClasslike : 3 occurrences // PhanPluginSuspiciousParamPosition : 2 occurrences + // PhanTypeMismatchArgumentInternal : 2 occurrences // PhanTypeMismatchDimAssignment : 2 occurrences // PhanTypeSuspiciousStringExpression : 2 occurrences // PhanAccessMethodProtected : 1 occurrence @@ -337,7 +338,6 @@ return [ 'htdocs/core/class/extrafields.class.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/class/fileupload.class.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/class/fiscalyear.class.php' => ['PhanTypeMismatchArgument'], - 'htdocs/core/class/hookmanager.class.php' => ['PhanUndeclaredProperty'], 'htdocs/core/class/html.form.class.php' => ['PhanTypeMismatchArgumentNullable'], 'htdocs/core/class/html.formcompany.class.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredProperty'], 'htdocs/core/class/html.formfile.class.php' => ['PhanTypeMismatchArgument'], diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php index 24b7341cb96..033e546c59d 100644 --- a/htdocs/core/class/hookmanager.class.php +++ b/htdocs/core/class/hookmanager.class.php @@ -3,7 +3,7 @@ /* Copyright (C) 2010-2016 Laurent Destailleur * Copyright (C) 2010-2014 Regis Houssin * Copyright (C) 2010-2011 Juanjo Menent - * Copyright (C) 2024-2025 MDW + * Copyright (C) 2024-2025 MDW * * 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 @@ -150,7 +150,8 @@ class HookManager '@phan-var-force CommonHookActions $actionInstance'; - $priority = empty($actionInstance->priority) ? 50 : $actionInstance->priority; + // @phan-suppress-next-line PhanUndeclaredProperty + $priority = property_exists($actionInstance, 'priority') && empty($actionInstance->priority) ? 50 : $actionInstance->priority; $this->hooks[$context][$module] = $actionInstance; $this->hooksSorted[$context][$priority.':'.$module] = $actionInstance; @@ -309,7 +310,7 @@ class HookManager $actionclassinstance->errors = array(); if (getDolGlobalInt('MAIN_HOOK_DEBUG')) { - // This his too much verbose, enabled if const enabled only + // This is too verbose, enabled if const enabled only // False positive about id & element: @phan-suppress-next-line PhanUndeclaredProperty dol_syslog(get_class($this)."::executeHooks Qualified hook found (hooktype=".$hooktype."). We call method ".get_class($actionclassinstance).'->'.$method.", context=".$context.", module=".$module.", action=".$action.((is_object($object) && property_exists($object, 'id')) ? ', object id='.$object->id : '').((is_object($object) && property_exists($object, 'element')) ? ', object element='.$object->element : ''), LOG_DEBUG); } @@ -347,8 +348,8 @@ class HookManager } else { // Generic hooks that return a string or array (printLeftBlock, formAddObjectLine, formBuilddocOptions, ...) - // TODO. this test should be done into the method of hook by returning nothing @phan-suppress-next-line PhanTypeInvalidDimOffset - if (is_array($parameters) && !empty($parameters['special_code']) && $parameters['special_code'] > 3 && $parameters['special_code'] != $actionclassinstance->module_number) { + // TODO. this test should be done in the hook method by returning nothing @phan-suppress-next-line PhanTypeInvalidDimOffset,PhanUndeclaredProperty + if (is_array($parameters) && !empty($parameters['special_code']) && $parameters['special_code'] > 3 && (property_exists($actionclassinstance, 'module_number') && ($parameters['special_code'] != $actionclassinstance->module_number))) { continue; } From c18f84d9488d14cf60b4c48e1bd9a1e9ec7f76ed Mon Sep 17 00:00:00 2001 From: MDW Date: Sat, 1 Mar 2025 11:44:35 +0100 Subject: [PATCH 5/6] Update phan baseline --- dev/tools/phan/baseline.txt | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/dev/tools/phan/baseline.txt b/dev/tools/phan/baseline.txt index 3715beb0308..8caebf69968 100644 --- a/dev/tools/phan/baseline.txt +++ b/dev/tools/phan/baseline.txt @@ -9,21 +9,21 @@ */ return [ // # Issue statistics: - // PhanTypeMismatchArgument : 1300+ occurrences + // PhanTypeMismatchArgument : 1240+ occurrences // PhanUndeclaredProperty : 480+ occurrences - // PhanTypeMismatchArgumentNullable : 310+ occurrences + // PhanTypeMismatchArgumentNullable : 290+ occurrences // PhanPluginUnknownArrayMethodReturnType : 170+ occurrences // PhanTypeMismatchProperty : 160+ occurrences // PhanPluginUnknownArrayMethodParamType : 110+ occurrences // PhanUndeclaredGlobalVariable : 100+ occurrences - // PhanPossiblyUndeclaredGlobalVariable : 25+ occurrences // PhanTypeExpectedObjectPropAccess : 25+ occurrences // PhanTypeInvalidDimOffset : 20+ occurrences - // PhanTypeMismatchArgumentProbablyReal : 20+ occurrences // PhanTypeMismatchDimFetch : 20+ occurrences // PhanPluginUndeclaredVariableIsset : 15+ occurrences + // PhanTypeMismatchArgumentProbablyReal : 15+ occurrences // PhanUndeclaredConstant : 15+ occurrences // PhanTypeMismatchArgumentNullableInternal : 10+ occurrences + // PhanPossiblyUndeclaredGlobalVariable : 9 occurrences // PhanUndeclaredMethod : 9 occurrences // PhanTypeComparisonFromArray : 7 occurrences // PhanPluginDuplicateExpressionBinaryOp : 6 occurrences @@ -33,7 +33,6 @@ return [ // PhanEmptyFQSENInClasslike : 3 occurrences // PhanInvalidFQSENInClasslike : 3 occurrences // PhanPluginSuspiciousParamPosition : 2 occurrences - // PhanTypeMismatchArgumentInternal : 2 occurrences // PhanTypeMismatchDimAssignment : 2 occurrences // PhanTypeSuspiciousStringExpression : 2 occurrences // PhanAccessMethodProtected : 1 occurrence @@ -48,11 +47,9 @@ return [ 'htdocs/accountancy/admin/account.php' => ['PhanTypeMismatchArgument'], 'htdocs/accountancy/admin/card.php' => ['PhanTypeMismatchArgument'], 'htdocs/accountancy/admin/categories.php' => ['PhanTypeMismatchArgumentNullable'], - 'htdocs/accountancy/admin/categories_list.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], + 'htdocs/accountancy/admin/categories_list.php' => ['PhanTypeMismatchArgumentNullable'], 'htdocs/accountancy/admin/fiscalyear_card.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], - 'htdocs/accountancy/admin/journals_list.php' => ['PhanTypeMismatchArgument'], 'htdocs/accountancy/admin/productaccount.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], - 'htdocs/accountancy/admin/report_list.php' => ['PhanTypeMismatchArgument'], 'htdocs/accountancy/admin/subaccount.php' => ['PhanTypeMismatchArgument'], 'htdocs/accountancy/bookkeeping/card.php' => ['PhanTypeMismatchArgument'], 'htdocs/accountancy/bookkeeping/export.php' => ['PhanTypeMismatchArgument'], @@ -77,7 +74,6 @@ return [ 'htdocs/accountancy/supplier/list.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], 'htdocs/accountancy/tpl/export_journal.tpl.php' => ['PhanTypeMismatchArgument'], 'htdocs/adherents/admin/member.php' => ['PhanTypeMismatchArgument'], - 'htdocs/adherents/admin/website.php' => ['PhanTypeMismatchArgument'], 'htdocs/adherents/canvas/actions_adherentcard_common.class.php' => ['PhanTypeMismatchArgument'], 'htdocs/adherents/card.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchProperty'], 'htdocs/adherents/class/adherent.class.php' => ['PhanTypeMismatchArgumentNullable'], @@ -94,7 +90,6 @@ return [ 'htdocs/admin/bom.php' => ['PhanTypeMismatchArgument'], 'htdocs/admin/company.php' => ['PhanTypeMismatchArgument'], 'htdocs/admin/defaultvalues.php' => ['PhanTypeMismatchArgumentProbablyReal'], - 'htdocs/admin/dict.php' => ['PhanTypeMismatchArgument'], 'htdocs/admin/emailcollector_card.php' => ['PhanTypeMismatchArgument'], 'htdocs/admin/emailcollector_list.php' => ['PhanTypeMismatchArgument'], 'htdocs/admin/eventorganization.php' => ['PhanTypeMismatchArgument'], @@ -122,7 +117,6 @@ return [ 'htdocs/admin/ticket.php' => ['PhanTypeMismatchArgument'], 'htdocs/admin/tools/export.php' => ['PhanTypeMismatchArgument'], 'htdocs/admin/webhook.php' => ['PhanTypeMismatchArgument'], - 'htdocs/admin/website.php' => ['PhanTypeMismatchArgument'], 'htdocs/api/class/api_access.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanUndeclaredProperty'], 'htdocs/api/class/api_documents.class.php' => ['PhanPluginDuplicateExpressionBinaryOp', 'PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanTypeMismatchArgument'], 'htdocs/api/class/api_login.class.php' => ['PhanPluginUnknownArrayMethodReturnType', 'PhanTypeMismatchArgument'], @@ -310,7 +304,6 @@ return [ 'htdocs/core/ajax/ajaxdirtree.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchProperty', 'PhanUndeclaredGlobalVariable'], 'htdocs/core/ajax/ajaxstatusprospect.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/ajax/contacts.php' => ['PhanTypeMismatchArgument'], - 'htdocs/core/ajax/editinline.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/ajax/loadinplace.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/ajax/saveinplace.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], 'htdocs/core/ajax/selectobject.php' => ['PhanTypeMismatchArgumentNullable'], From 0533c28d56061dde7e01addbd97dc1b693000a1e Mon Sep 17 00:00:00 2001 From: MDW Date: Sat, 1 Mar 2025 13:10:45 +0100 Subject: [PATCH 6/6] Qual: Fix getLibStatut notices with type hinting --- htdocs/core/lib/functions.lib.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 67fa18fa32b..f5ed6cac0ba 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3213,12 +3213,14 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi $morehtmlstatus .= ''.$object->getLibStatut(6, 1).''; } } elseif (in_array($object->element, array('salary'))) { + '@phan-var-force Salary $object'; $tmptxt = $object->getLibStatut(6, $object->alreadypaid); if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3)) { $tmptxt = $object->getLibStatut(5, $object->alreadypaid); } $morehtmlstatus .= $tmptxt; } elseif (in_array($object->element, array('facture', 'invoice', 'invoice_supplier'))) { // TODO Move this to use ->alreadypaid + '@phan-var-force Facture|FactureFournisseur|CommonInvoice $object'; $totalallpayments = $object->getSommePaiement(0); $totalallpayments += $object->getSumCreditNotesUsed(0); $totalallpayments += $object->getSumDepositsUsed(0); @@ -3228,6 +3230,7 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi } $morehtmlstatus .= $tmptxt; } elseif (in_array($object->element, array('chargesociales', 'loan', 'tva'))) { // TODO Move this to use ->alreadypaid + '@phan-var-force ChargeSociales|Loan|Tva $object'; $tmptxt = $object->getLibStatut(6, $object->totalpaid); if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3)) { $tmptxt = $object->getLibStatut(5, $object->totalpaid);