From acd282af6c86cb2cc90140cc96708826005eead4 Mon Sep 17 00:00:00 2001 From: MDW Date: Wed, 5 Feb 2025 22:59:37 +0100 Subject: [PATCH] Qual: Fix phan notices (modulebuilder) --- dev/tools/phan/baseline.txt | 30 +--------- htdocs/core/lib/functions.lib.php | 7 ++- .../doc/doc_generic_usergroup_odt.modules.php | 4 +- htdocs/modulebuilder/index.php | 60 ++++++++----------- htdocs/modulebuilder/template/admin/setup.php | 4 +- .../modulebuilder/template/ajax/myobject.php | 2 +- .../template/class/api_mymodule.class.php | 26 ++++---- .../template/class/myobject.class.php | 2 +- .../doc/pdf_standard_myobject.modules.php | 12 ++-- .../mymodule/mod_myobject_advanced.php | 4 +- .../modulebuilder/template/myobject_list.php | 18 +++--- 11 files changed, 71 insertions(+), 98 deletions(-) diff --git a/dev/tools/phan/baseline.txt b/dev/tools/phan/baseline.txt index 716996e9d84e5..0da0c9a12373b 100644 --- a/dev/tools/phan/baseline.txt +++ b/dev/tools/phan/baseline.txt @@ -9,9 +9,9 @@ */ return [ // # Issue statistics: - // PhanTypeMismatchArgument : 2560+ occurrences + // PhanTypeMismatchArgument : 2490+ occurrences // PhanUndeclaredProperty : 530+ occurrences - // PhanTypeMismatchArgumentNullable : 450+ occurrences + // PhanTypeMismatchArgumentNullable : 430+ occurrences // PhanUndeclaredGlobalVariable : 190+ occurrences // PhanPluginUnknownArrayMethodReturnType : 180+ occurrences // PhanPossiblyUndeclaredGlobalVariable : 160+ occurrences @@ -84,7 +84,7 @@ return [ 'htdocs/adherents/admin/website.php' => ['PhanTypeMismatchArgument'], 'htdocs/adherents/canvas/actions_adherentcard_common.class.php' => ['PhanTypeMismatchArgument'], 'htdocs/adherents/card.php' => ['PhanTypeMismatchArgument'], - 'htdocs/adherents/class/adherent.class.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], + 'htdocs/adherents/class/adherent.class.php' => ['PhanTypeMismatchArgumentNullable'], 'htdocs/adherents/class/adherent_type.class.php' => ['PhanTypeMismatchArgument'], 'htdocs/adherents/class/api_members.class.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], 'htdocs/adherents/list.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanUndeclaredGlobalVariable'], @@ -411,20 +411,16 @@ return [ 'htdocs/core/login/functions_dolibarr.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/login/functions_ldap.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], 'htdocs/core/menus/standard/auguria.lib.php' => ['PhanTypeMismatchArgument'], - 'htdocs/core/modules/asset/doc/doc_generic_asset_odt.modules.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/modules/asset/doc/pdf_standard_asset.modules.php' => ['PhanTypeMismatchArgumentNullable'], 'htdocs/core/modules/asset/mod_asset_advanced.php' => ['PhanUndeclaredProperty'], 'htdocs/core/modules/barcode/mod_barcode_product_standard.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/modules/barcode/mod_barcode_thirdparty_standard.php' => ['PhanTypeMismatchArgument'], - 'htdocs/core/modules/bom/doc/doc_generic_bom_odt.modules.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/modules/bom/mod_bom_advanced.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredProperty'], 'htdocs/core/modules/cheque/doc/pdf_blochet.class.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], 'htdocs/core/modules/cheque/modules_chequereceipts.php' => ['PhanTypeMismatchArgument'], - 'htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/modules/commande/doc/pdf_einstein.modules.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchDimFetch', 'PhanTypeMismatchProperty', 'PhanUndeclaredProperty'], 'htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchDimFetch', 'PhanTypeMismatchProperty', 'PhanUndeclaredProperty'], 'htdocs/core/modules/commande/mod_commande_saphir.php' => ['PhanTypeMismatchArgumentNullable'], - 'htdocs/core/modules/contract/doc/doc_generic_contract_odt.modules.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/modules/contract/doc/pdf_strato.modules.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], 'htdocs/core/modules/delivery/doc/pdf_storm.modules.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], 'htdocs/core/modules/delivery/doc/pdf_typhon.modules.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], @@ -435,7 +431,6 @@ return [ 'htdocs/core/modules/expedition/doc/pdf_rouget.modules.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], 'htdocs/core/modules/expensereport/doc/pdf_standard_expensereport.modules.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredProperty'], 'htdocs/core/modules/expensereport/mod_expensereport_jade.php' => ['PhanTypeMismatchArgument'], - 'htdocs/core/modules/facture/doc/doc_generic_invoice_odt.modules.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/modules/facture/doc/pdf_crabe.modules.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanUndeclaredProperty'], 'htdocs/core/modules/facture/doc/pdf_octopus.modules.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanUndeclaredProperty'], 'htdocs/core/modules/facture/doc/pdf_sponge.modules.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanUndeclaredProperty'], @@ -471,38 +466,29 @@ return [ 'htdocs/core/modules/modSupplierProposal.class.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/modules/modTicket.class.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/modules/movement/doc/pdf_standard_movementstock.modules.php' => ['PhanTypeMismatchArgument'], - 'htdocs/core/modules/mrp/doc/doc_generic_mo_odt.modules.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/modules/mrp/doc/pdf_vinci.modules.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredProperty'], 'htdocs/core/modules/mrp/mod_mo_advanced.php' => ['PhanUndeclaredProperty'], 'htdocs/core/modules/oauth/github_oauthcallback.php' => ['PhanUndeclaredGlobalVariable'], 'htdocs/core/modules/printsheet/doc/pdf_standardlabel.class.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/modules/printsheet/doc/pdf_tcpdflabel.class.php' => ['PhanTypeMismatchArgument'], - 'htdocs/core/modules/product/doc/doc_generic_product_odt.modules.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/modules/project/doc/doc_generic_project_odt.modules.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredProperty'], 'htdocs/core/modules/project/doc/pdf_beluga.modules.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/modules/project/doc/pdf_timespent.modules.php' => ['PhanUndeclaredProperty'], 'htdocs/core/modules/project/task/doc/doc_generic_task_odt.modules.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredProperty'], - 'htdocs/core/modules/propale/doc/doc_generic_proposal_odt.modules.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/modules/propale/doc/pdf_azur.modules.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanUndeclaredProperty'], 'htdocs/core/modules/propale/doc/pdf_cyan.modules.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanUndeclaredProperty'], - 'htdocs/core/modules/reception/doc/doc_generic_reception_odt.modules.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/modules/reception/doc/pdf_squille.modules.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanUndeclaredProperty'], 'htdocs/core/modules/societe/doc/doc_generic_odt.modules.php' => ['PhanTypeMismatchArgumentNullable'], - 'htdocs/core/modules/stock/doc/doc_generic_stock_odt.modules.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/modules/stocktransfer/doc/pdf_eagle.modules.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredProperty'], 'htdocs/core/modules/stocktransfer/doc/pdf_eagle_proforma.modules.php' => ['PhanTypeMismatchArgumentNullable'], 'htdocs/core/modules/stocktransfer/mod_stocktransfer_advanced.php' => ['PhanUndeclaredProperty'], - 'htdocs/core/modules/supplier_invoice/doc/doc_generic_supplier_invoice_odt.modules.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/modules/supplier_invoice/doc/pdf_canelle.modules.php' => ['PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchProperty'], - 'htdocs/core/modules/supplier_order/doc/doc_generic_supplier_order_odt.modules.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/modules/supplier_order/doc/pdf_cornas.modules.php' => ['PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchDimFetch', 'PhanTypeMismatchProperty', 'PhanUndeclaredProperty'], 'htdocs/core/modules/supplier_order/doc/pdf_muscadet.modules.php' => ['PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchDimFetch', 'PhanTypeMismatchProperty', 'PhanUndeclaredProperty'], - 'htdocs/core/modules/supplier_proposal/doc/doc_generic_supplier_proposal_odt.modules.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php' => ['PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchDimFetch', 'PhanTypeMismatchProperty', 'PhanUndeclaredProperty'], 'htdocs/core/modules/supplier_proposal/doc/pdf_zenith.modules.php' => ['PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchDimFetch', 'PhanTypeMismatchProperty', 'PhanUndeclaredProperty'], 'htdocs/core/modules/syslog/mod_syslog_file.php' => ['PhanPluginDuplicateArrayKey'], 'htdocs/core/modules/user/doc/doc_generic_user_odt.modules.php' => ['PhanTypeMismatchArgumentNullable'], - 'htdocs/core/modules/usergroup/doc/doc_generic_usergroup_odt.modules.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/modules/workstation/mod_workstation_advanced.php' => ['PhanUndeclaredProperty'], 'htdocs/core/multicompany_page.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/search_page.php' => ['PhanTypeMismatchArgument'], @@ -622,15 +608,6 @@ return [ 'htdocs/loan/document.php' => ['PhanUndeclaredProperty'], 'htdocs/loan/note.php' => ['PhanUndeclaredProperty'], 'htdocs/loan/payment/payment.php' => ['PhanUndeclaredProperty'], - 'htdocs/modulebuilder/index.php' => ['PhanTypeMismatchArgumentNullable'], - 'htdocs/modulebuilder/template/admin/setup.php' => ['PhanTypeMismatchArgument'], - 'htdocs/modulebuilder/template/ajax/myobject.php' => ['PhanTypeMismatchArgument'], - 'htdocs/modulebuilder/template/class/api_mymodule.class.php' => ['PhanTypeMismatchArgument'], - 'htdocs/modulebuilder/template/class/myobject.class.php' => ['PhanTypeMismatchArgument'], - 'htdocs/modulebuilder/template/core/modules/mymodule/doc/doc_generic_myobject_odt.modules.php' => ['PhanTypeMismatchArgument'], - 'htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], - 'htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_advanced.php' => ['PhanTypeMismatchArgument'], - 'htdocs/modulebuilder/template/myobject_list.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], 'htdocs/mrp/ajax/ajax_bom.php' => ['PhanTypeMismatchArgument'], 'htdocs/mrp/class/api_mos.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanTypeMismatchArgument'], 'htdocs/mrp/class/mo.class.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchProperty'], @@ -802,7 +779,6 @@ return [ 'htdocs/recruitment/class/api_recruitments.class.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], 'htdocs/recruitment/class/recruitmentcandidature.class.php' => ['PhanUndeclaredProperty'], 'htdocs/recruitment/class/recruitmentjobposition.class.php' => ['PhanUndeclaredProperty'], - 'htdocs/recruitment/core/modules/recruitment/doc/doc_generic_recruitmentjobposition_odt.modules.php' => ['PhanTypeMismatchArgument'], 'htdocs/recruitment/core/modules/recruitment/doc/pdf_standard_recruitmentjobposition.modules.php' => ['PhanTypeMismatchArgumentNullable', 'PhanUndeclaredProperty'], 'htdocs/recruitment/core/modules/recruitment/mod_recruitmentcandidature_advanced.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredProperty'], 'htdocs/recruitment/core/modules/recruitment/mod_recruitmentjobposition_advanced.php' => ['PhanTypeMismatchArgument', 'PhanUndeclaredProperty'], diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 3695a1eeb69f8..567eb7e4b867a 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -1207,7 +1207,7 @@ function checkVal($out = '', $check = 'alphanohtml', $filter = null, $options = /** * Return a sanitized or empty value after checking value against a rule. * - * @param string|array $out Value to check/clear. + * @param string|mixed[]|null $out Value to check/clear. * @param string $check Type of check/sanitizing * @param ?int $filter Filter to apply when $check is set to 'custom'. (See http://php.net/manual/en/filter.filters.php for détails) * @param ?mixed $options Options to pass to filter_var when $check is set to 'custom' @@ -1217,6 +1217,9 @@ function sanitizeVal($out = '', $check = 'alphanohtml', $filter = null, $options { // TODO : use class "Validate" to perform tests (and add missing tests) if needed for factorize // Check is done after replacement + if ($out === null) { + $out = ''; + } switch ($check) { case 'none': case 'password': @@ -9895,7 +9898,7 @@ function make_substitutions($text, $substitutionarray, $outputlangs = null, $con * Complete the $substitutionarray with more entries coming from external module that had set the "substitutions=1" into module_part array. * In this case, method completesubstitutionarray provided by module is called. * - * @param array $substitutionarray Array substitution old value => new value value + * @param array $substitutionarray Array substitution old value => new value value * @param Translate $outputlangs Output language * @param ?CommonObject $object Source object * @param ?mixed $parameters Add more parameters (useful to pass product lines) diff --git a/htdocs/core/modules/usergroup/doc/doc_generic_usergroup_odt.modules.php b/htdocs/core/modules/usergroup/doc/doc_generic_usergroup_odt.modules.php index da30d9a0b2148..55015b96550ff 100644 --- a/htdocs/core/modules/usergroup/doc/doc_generic_usergroup_odt.modules.php +++ b/htdocs/core/modules/usergroup/doc/doc_generic_usergroup_odt.modules.php @@ -2,7 +2,7 @@ /* Copyright (C) 2010-2012 Laurent Destailleur * Copyright (C) 2012 Juanjo Menent * Copyright (C) 2018-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 @@ -447,7 +447,7 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede $reshook = $hookmanager->executeHooks('ODTSubstitutionLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks foreach ($tmparray as $key => $val) { try { - if (!is_array($val)) { + if (!is_array($val)) { // @phpstan-ignore-line $listlines->setVars($key, $val, true, 'UTF-8'); } } catch (SegmentException $e) { diff --git a/htdocs/modulebuilder/index.php b/htdocs/modulebuilder/index.php index 86726bb5543f1..a947d49702415 100644 --- a/htdocs/modulebuilder/index.php +++ b/htdocs/modulebuilder/index.php @@ -2,7 +2,7 @@ /* Copyright (C) 2004-2023 Laurent Destailleur * Copyright (C) 2018-2019 Nicolas ZABOURI * Copyright (C) 2023 Alexandre Janniaux - * Copyright (C) 2024 MDW + * Copyright (C) 2024-2025 MDW * Copyright (C) 2024 Frédéric France * * This program is free software; you can redistribute it and/or modify @@ -67,7 +67,7 @@ $sortorder = GETPOST('sortorder', 'aZ09'); $module = GETPOST('module', 'alpha'); -$tab = GETPOST('tab', 'aZ09'); +$tab = (string) GETPOST('tab', 'aZ09'); $tabobj = GETPOST('tabobj', 'alpha'); $tabdic = GETPOST('tabdic', 'alpha'); $propertykey = GETPOST('propertykey', 'alpha'); @@ -77,6 +77,7 @@ if (empty($tab)) { $tab = 'description'; } +'@phan-var-force string $tab'; // Workaround 'empty()' bug of phan if (empty($tabobj)) { $tabobj = 'newobjectifnoobj'; } @@ -850,6 +851,7 @@ function getLicenceHeader($user, $langs, $now) $moduledescriptorfile = '/not_set/'; +$modulelowercase = null; // init Doc if ($dirins && $action == 'initdoc' && !empty($module) && $user->hasRight("modulebuilder", "run")) { @@ -1288,7 +1290,7 @@ function getLicenceHeader($user, $langs, $now) $position = 900; } // $alwayseditable - $alwayseditable=0; + $alwayseditable = 0; if ($fieldname == 'label') { $alwayseditable = 1; } else { @@ -2347,15 +2349,12 @@ function getLicenceHeader($user, $langs, $now) $dirofmodule = dol_buildpath($modulelowercase, 0).'/bin'; $outputfilezip = $dirofmodule.'/'.$FILENAMEZIP; - if ($dirofmodule) { - if (!dol_is_dir($dirofmodule)) { - dol_mkdir($dirofmodule); - } - // Note: We exclude /bin/ to not include the already generated zip - $result = dol_compress_dir($dir, $outputfilezip, 'zip', '/\/bin\/|\.git|\.old|\.back|\.ssh/', $modulelowercase); - } else { - $result = -1; + + if (!dol_is_dir($dirofmodule)) { + dol_mkdir($dirofmodule); } + // Note: We exclude /bin/ to not include the already generated zip + $result = dol_compress_dir($dir, $outputfilezip, 'zip', '/\/bin\/|\.git|\.old|\.back|\.ssh/', $modulelowercase); if ($result > 0) { setEventMessages($langs->trans("ZipFileGeneratedInto", $outputfilezip), null); @@ -2706,12 +2705,9 @@ function getLicenceHeader($user, $langs, $now) if ($module) { $param .= '&module='.urlencode($module); } - if ($tab) { - $param .= '&tab='.urlencode($tab); - } - if ($tabobj) { - $param .= '&tabobj='.urlencode($tabobj); - } + + $param .= '&tab='.urlencode($tab); + $param .= '&tabobj='.urlencode($tabobj); $value = GETPOST('value', 'alpha'); $resarray = activateModule($value); @@ -2744,12 +2740,8 @@ function getLicenceHeader($user, $langs, $now) if ($module) { $param .= '&module='.urlencode($module); } - if ($tab) { - $param .= '&tab='.urlencode($tab); - } - if ($tabobj) { - $param .= '&tabobj='.urlencode($tabobj); - } + $param .= '&tab='.urlencode($tab); + $param .= '&tabobj='.urlencode($tabobj); $value = GETPOST('value', 'alpha'); $result = unActivateModule($value); @@ -3310,15 +3302,12 @@ function getLicenceHeader($user, $langs, $now) $modulelowercase = strtolower($module); $param = ''; - if ($tab) { - $param .= '&tab='.urlencode($tab); - } if ($module) { $param .= '&module='.urlencode($module); } - if ($tabobj) { - $param .= '&tabobj='.urlencode($tabobj); - } + + $param .= '&tab='.urlencode($tab); + $param .= '&tabobj='.urlencode($tabobj); $urltomodulesetup = ''.$langs->trans('Home').'-'.$langs->trans("Setup").'-'.$langs->trans("Modules").''; @@ -3333,9 +3322,7 @@ function getLicenceHeader($user, $langs, $now) $objMod = $moduleobj; $backtourlparam = ''; $backtourlparam .= ($backtourlparam ? '&' : '?').'module='.$module; // No urlencode here, done later - if ($tab) { - $backtourlparam .= ($backtourlparam ? '&' : '?').'tab='.$tab; // No urlencode here, done later - } + $backtourlparam .= ($backtourlparam ? '&' : '?').'tab='.$tab; // No urlencode here, done later $backtourl = $_SERVER["PHP_SELF"].$backtourlparam; $regs = array(); @@ -3493,7 +3480,7 @@ function getLicenceHeader($user, $langs, $now) print ''; print ''; print ''; -} elseif (!empty($module) && isset($modulelowercase)) { +} elseif (!empty($module) && $modulelowercase !== null) { // Tabs for module if (!$error) { $dirread = $listofmodules[strtolower($module)]['moduledescriptorrootpath']; @@ -3848,6 +3835,7 @@ function getLicenceHeader($user, $langs, $now) } else { // Edit text file $fullpathoffile = dol_buildpath($file, 0, 1); // Description - level 2 + $content = ''; if ($fullpathoffile) { $content = file_get_contents($fullpathoffile); } @@ -4377,7 +4365,7 @@ function cleanString( stringtoclean ) print $form->textwithpicto('', $langs->trans("InfoForApiFile"), 1, 'warning'); print '   '; // Comparing to null (phan considers $modulelowercase can be null here) - if ($modulelowercase !== null && !isModEnabled($modulelowercase)) { // If module is not activated + if (!isModEnabled($modulelowercase)) { // If module is not activated print ''.$langs->trans("ApiExplorer").''; } else { print ''.$langs->trans("ApiExplorer").''; @@ -6418,7 +6406,7 @@ function updateInputField() { print ''; print ''; - $texttoshow = null; + $texttoshow = ''; if ($cron['jobtype'] == 'method') { $text = $langs->trans("CronClass"); $texttoshow = $langs->trans('CronModule').': '.$module.'
'; @@ -6658,7 +6646,7 @@ function updateInputField() { print '
'; print ' '.$langs->trans("PathToModulePackage").' : '; - if (!dol_is_file($outputfilezip)) { + if ($outputfilezip === null || !dol_is_file($outputfilezip)) { print ''.$langs->trans("FileNotYetGenerated").''; } else { $relativepath = $modulelowercase.'/bin/'.$FILENAMEZIP; diff --git a/htdocs/modulebuilder/template/admin/setup.php b/htdocs/modulebuilder/template/admin/setup.php index 306a28aa5b92e..3086dedbe0d99 100644 --- a/htdocs/modulebuilder/template/admin/setup.php +++ b/htdocs/modulebuilder/template/admin/setup.php @@ -452,7 +452,7 @@ } print ''; - print $form->textwithpicto('', $htmltooltip, 1, 0); + print $form->textwithpicto('', $htmltooltip, 1, 'info'); print ''; print "\n"; @@ -588,7 +588,7 @@ $htmltooltip .= '
'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang, 1, 1); print ''; - print $form->textwithpicto('', $htmltooltip, 1, 0); + print $form->textwithpicto('', $htmltooltip, 1, 'info'); print ''; // Preview diff --git a/htdocs/modulebuilder/template/ajax/myobject.php b/htdocs/modulebuilder/template/ajax/myobject.php index d4ca191942b44..98bd1909bde03 100644 --- a/htdocs/modulebuilder/template/ajax/myobject.php +++ b/htdocs/modulebuilder/template/ajax/myobject.php @@ -66,7 +66,7 @@ */ $mode = GETPOST('mode', 'aZ09'); -$objectId = GETPOST('objectId', 'aZ09'); +$objectId = GETPOSTINT('objectId'); $field = GETPOST('field', 'aZ09'); $value = GETPOST('value', 'aZ09'); diff --git a/htdocs/modulebuilder/template/class/api_mymodule.class.php b/htdocs/modulebuilder/template/class/api_mymodule.class.php index a57d497ea305d..11da9de834585 100644 --- a/htdocs/modulebuilder/template/class/api_mymodule.class.php +++ b/htdocs/modulebuilder/template/class/api_mymodule.class.php @@ -38,7 +38,7 @@ class MyModuleApi extends DolibarrApi { /** - * @var MyObject $myobject {@type MyObject} + * @var MyObject {@type MyObject} */ public $myobject; @@ -46,7 +46,6 @@ class MyModuleApi extends DolibarrApi * Constructor * * @url GET / - * */ public function __construct() { @@ -194,8 +193,8 @@ public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, * Create myobject object * * @param array $request_data Request data - * @phan-param array{string,mixed} $request_data - * @phpstan-param array{string,mixed} $request_data + * @phan-param ?array $request_data + * @phpstan-param ?array $request_data * @return int ID of myobject * * @throws RestException 403 Not allowed @@ -215,7 +214,7 @@ public function post($request_data = null) foreach ($request_data as $field => $value) { if ($field === 'caller') { // Add a mention of caller so on trigger called after action, we can filter to avoid a loop if we try to sync back again with the caller @phan-suppress-next-line PhanTypeInvalidDimOffset - $this->myobject->context['caller'] = sanitizeVal($request_data['caller'], 'aZ09'); + $this->myobject->context['caller'] = sanitizeVal((string) $request_data['caller'], 'aZ09'); continue; } @@ -243,8 +242,8 @@ public function post($request_data = null) * * @param int $id Id of myobject to update * @param array $request_data Data - * @phan-param mixed[] $request_data - * @phpstan-param mixed[] $request_data + * @phan-param ?array $request_data + * @phpstan-param ?array $request_data * @return Object Object after update * @phan-return MyObject * @phpstan-return MyObject @@ -301,7 +300,7 @@ public function put($id, $request_data = null) // Clean data // $this->myobject->abc = sanitizeVal($this->myobject->abc, 'alphanohtml'); - if ($this->myobject->update(DolibarrApiAccess::$user, false) > 0) { + if ($this->myobject->update(DolibarrApiAccess::$user, 0) > 0) { return $this->get($id); } else { throw new RestException(500, $this->myobject->error); @@ -356,16 +355,19 @@ public function delete($id) * Validate fields before creating or updating object * * @param array $data Array of data to validate - * @phan-param array $data - * @phpstan-param array $data + * @phan-param ?array $data + * @phpstan-param ?array $data * @return array - * @phan-return array|array{} - * @phpstan-return array|array{} + * @phan-return array|array{} + * @phpstan-return array|array{} * * @throws RestException */ private function _validateMyObject($data) { + if (!is_array($data)) { + $data = array(); + } $myobject = array(); foreach ($this->myobject->fields as $field => $propfield) { if (in_array($field, array('rowid', 'entity', 'date_creation', 'tms', 'fk_user_creat')) || $propfield['notnull'] != 1) { diff --git a/htdocs/modulebuilder/template/class/myobject.class.php b/htdocs/modulebuilder/template/class/myobject.class.php index ceefd2998b05d..500cdcaa4766b 100644 --- a/htdocs/modulebuilder/template/class/myobject.class.php +++ b/htdocs/modulebuilder/template/class/myobject.class.php @@ -802,7 +802,7 @@ public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss $result = ''; $params = [ - 'id' => $this->id, + 'id' => (string) $this->id, 'objecttype' => $this->element.($this->module ? '@'.$this->module : ''), 'option' => $option, ]; diff --git a/htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php b/htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php index 7ac4f25e47e2a..9abc8daff75aa 100644 --- a/htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php +++ b/htdocs/modulebuilder/template/core/modules/mymodule/doc/pdf_standard_myobject.modules.php @@ -9,7 +9,7 @@ * Copyright (C) 2015 Marcos García * Copyright (C) 2017 Ferran Marcet * Copyright (C) 2018-2024 Frédéric France - * Copyright (C) 2024 MDW + * Copyright (C) 2024-2025 MDW * Copyright (C) 2024 Alexandre Spangaro * Copyright (C) ---Replace with your own copyright and developer email--- * @@ -431,12 +431,12 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede // $this->_pagefoot($pdf,$object,$outputlangs,1); $pdf->setTopMargin($tab_top_newpage); // The only function to edit the bottom margin of current page to set it. - $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext); + $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext); } // back to start $pdf->setPage($pageposbeforenote); - $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext); + $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext); $pdf->SetFont('', '', $default_font_size - 1); $pdf->writeHTMLCell(190, 3, $this->posxdesc - 1, $tab_top, dol_htmlentitiesbr($notetoshow), 0, 1); $pageposafternote = $pdf->getPage(); @@ -450,7 +450,7 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede $pdf->setPage($pageposafternote); $pdf->setTopMargin($tab_top_newpage); // The only function to edit the bottom margin of current page to set it. - $pdf->setPageOrientation('', 1, $heightforfooter + $heightforfreetext); + $pdf->setPageOrientation('', true, $heightforfooter + $heightforfreetext); //$posyafter = $tab_top_newpage; } @@ -472,7 +472,7 @@ public function write_file($object, $outputlangs, $srctemplatepath = '', $hidede } // Add footer - $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. + $pdf->setPageOrientation('', true, 0); // The only function to edit the bottom margin of current page to set it. $this->_pagefoot($pdf, $object, $outputlangs, 1); $i++; @@ -1174,7 +1174,7 @@ protected function _pagehead(&$pdf, $object, $showaddress, $outputlangs, $output $pdf->SetXY($posx + 2, $posy + 3); $pdf->SetFont('', 'B', $default_font_size); // @phan-suppress-next-line PhanPluginSuspiciousParamOrder - $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, $ltrdirection); + $pdf->MultiCell($widthrecbox, 2, (string) $carac_client_name, 0, $ltrdirection); $posy = $pdf->getY(); diff --git a/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_advanced.php b/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_advanced.php index c8117863f12e4..b900878417c7d 100644 --- a/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_advanced.php +++ b/htdocs/modulebuilder/template/core/modules/mymodule/mod_myobject_advanced.php @@ -4,7 +4,7 @@ * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2008i Raphael Bertrand (Resultic) * Copyright (C) 2019-2024 Frédéric France - * Copyright (C) 2024 MDW + * Copyright (C) 2024-2025 MDW * Copyright (C) ---Replace with your own copyright and developer email--- * * This program is free software; you can redistribute it and/or modify @@ -83,7 +83,7 @@ public function info($langs) // prefix configuration $text .= ''.$langs->trans("Mask").':'; - $text .= ''.$form->textwithpicto('', $tooltip, 1, 1).''; + $text .= ''.$form->textwithpicto('', $tooltip, 1, 'help').''; $text .= '  '; $text .= ''; diff --git a/htdocs/modulebuilder/template/myobject_list.php b/htdocs/modulebuilder/template/myobject_list.php index 2451c35d972b7..6972f0f2567ed 100644 --- a/htdocs/modulebuilder/template/myobject_list.php +++ b/htdocs/modulebuilder/template/myobject_list.php @@ -336,14 +336,18 @@ if ($key == 'status' && $search[$key] == -1) { continue; } - $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0); - if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) { - if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) { + $field_spec = $object->fields[$key]; + if ($field_spec === null) { + continue; + } + $mode_search = (($object->isInt($field_spec) || $object->isFloat($field_spec)) ? 1 : 0); + if ((strpos($field_spec['type'], 'integer:') === 0) || (strpos($field_spec['type'], 'sellist:') === 0) || !empty($field_spec['arrayofkeyval'])) { + if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($field_spec['arrayofkeyval']) || !array_key_exists('0', $field_spec['arrayofkeyval'])))) { $search[$key] = ''; } $mode_search = 2; } - if (empty($object->fields[$key]['searchmulti'])) { + if (empty($field_spec['searchmulti'])) { if (!is_array($search[$key]) && $search[$key] != '') { $sql .= natural_search("t.".$db->escape($key), $search[$key], (($key == 'status') ? 2 : $mode_search)); } @@ -829,15 +833,15 @@ if (!empty($arrayfields['t.'.$key]['checked'])) { print '$key) && !in_array($key, array('ref'))) { - print ' title="'.dol_escape_htmltag($object->$key).'"'; + print ' title="'.dol_escape_htmltag((string) $object->$key).'"'; } print '>'; if ($key == 'status') { print $object->getLibStatut(5); } elseif ($key == 'rowid') { - print $object->showOutputField($val, $key, $object->id, ''); + print $object->showOutputField($val, $key, (string) $object->id, ''); } else { - print $object->showOutputField($val, $key, $object->$key, ''); + print $object->showOutputField($val, $key, (string) $object->$key, ''); } print ''; if (!$i) {