From 78fde76f617fb6e6129aa0bc598cd355a26e3fbe Mon Sep 17 00:00:00 2001 From: MDW Date: Sat, 16 Nov 2024 17:59:26 +0100 Subject: [PATCH] Qual: Fix some phan notices (#31948) --- dev/tools/phan/baseline.txt | 16 +++++----------- htdocs/compta/cashcontrol/cashcontrol_card.php | 5 ++++- htdocs/compta/charges/index.php | 6 +++--- htdocs/compta/deplacement/stats/index.php | 1 + htdocs/compta/facture/agenda-rec.php | 17 +++++++++-------- htdocs/compta/facture/contact.php | 5 +++-- htdocs/compta/facture/invoicetemplate_list.php | 2 +- htdocs/compta/facture/list.php | 14 +++++++++----- 8 files changed, 35 insertions(+), 31 deletions(-) diff --git a/dev/tools/phan/baseline.txt b/dev/tools/phan/baseline.txt index 85e1a4e33c7a6..a9d07010f5137 100644 --- a/dev/tools/phan/baseline.txt +++ b/dev/tools/phan/baseline.txt @@ -10,9 +10,9 @@ return [ // # Issue statistics: // PhanUndeclaredProperty : 560+ occurrences - // PhanPossiblyUndeclaredGlobalVariable : 500+ occurrences + // PhanPossiblyUndeclaredGlobalVariable : 490+ occurrences // PhanUndeclaredGlobalVariable : 350+ occurrences - // PhanTypeMismatchArgumentProbablyReal : 270+ occurrences + // PhanTypeMismatchArgumentProbablyReal : 260+ occurrences // PhanPluginUnknownArrayMethodReturnType : 180+ occurrences // PhanTypeMismatchProperty : 140+ occurrences // PhanPluginUnknownPropertyType : 130+ occurrences @@ -21,7 +21,7 @@ return [ // PhanPluginUndeclaredVariableIsset : 65+ occurrences // PhanRedefineFunction : 45+ occurrences // PhanTypeExpectedObjectPropAccess : 45+ occurrences - // PhanTypeMismatchArgumentNullableInternal : 45+ occurrences + // PhanTypeMismatchArgumentNullableInternal : 40+ occurrences // PhanTypeInvalidDimOffset : 35+ occurrences // PhanPluginEmptyStatementIf : 30+ occurrences // PhanTypeMismatchDimFetch : 30+ occurrences @@ -108,19 +108,13 @@ return [ 'htdocs/compta/bank/various_payment/document.php' => ['PhanPluginUnknownObjectMethodCall', 'PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'], 'htdocs/compta/bank/various_payment/info.php' => ['PhanPluginUnknownObjectMethodCall', 'PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'], 'htdocs/compta/bank/various_payment/list.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchProperty'], - 'htdocs/compta/cashcontrol/cashcontrol_card.php' => ['PhanPluginDuplicateExpressionBinaryOp', 'PhanPossiblyUndeclaredGlobalVariable'], + 'htdocs/compta/cashcontrol/cashcontrol_card.php' => ['PhanPluginDuplicateExpressionBinaryOp'], 'htdocs/compta/cashcontrol/cashcontrol_list.php' => ['PhanTypeMismatchProperty'], - 'htdocs/compta/charges/index.php' => ['PhanTypeMismatchArgumentNullableInternal'], 'htdocs/compta/clients.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanUndeclaredGlobalVariable'], - 'htdocs/compta/deplacement/stats/index.php' => ['PhanPossiblyUndeclaredGlobalVariable'], - 'htdocs/compta/facture/agenda-rec.php' => ['PhanPluginEmptyStatementIf'], 'htdocs/compta/facture/card.php' => ['PhanTypeMismatchProperty', 'PhanUndeclaredProperty'], 'htdocs/compta/facture/class/api_invoices.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType', 'PhanTypeComparisonFromArray', 'PhanTypeMismatchArgumentProbablyReal'], 'htdocs/compta/facture/class/facture-rec.class.php' => ['PhanUndeclaredProperty'], 'htdocs/compta/facture/class/facture.class.php' => ['PhanUndeclaredProperty'], - 'htdocs/compta/facture/contact.php' => ['PhanTypeMismatchArgumentProbablyReal'], - 'htdocs/compta/facture/invoicetemplate_list.php' => ['PhanTypeMismatchArgumentProbablyReal'], - 'htdocs/compta/facture/list.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgumentProbablyReal'], 'htdocs/compta/facture/note.php' => ['PhanTypeMismatchArgumentProbablyReal'], 'htdocs/compta/facture/prelevement.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgumentProbablyReal'], 'htdocs/compta/facture/stats/index.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgumentProbablyReal'], @@ -599,7 +593,7 @@ return [ 'htdocs/societe/consumption.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgumentProbablyReal'], 'htdocs/societe/list.php' => ['PhanPluginUndeclaredVariableIsset', 'PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgumentProbablyReal'], 'htdocs/societe/paymentmodes.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeExpectedObjectPropAccess', 'PhanUndeclaredGlobalVariable'], - 'htdocs/societe/price.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgumentProbablyReal'], + 'htdocs/societe/price.php' => ['PhanTypeMismatchArgumentProbablyReal'], 'htdocs/societe/tpl/linesalesrepresentative.tpl.php' => ['PhanTypeMismatchArgumentProbablyReal'], 'htdocs/societe/website.php' => ['PhanTypeMismatchArgumentProbablyReal'], 'htdocs/stripe/class/actions_stripe.class.php' => ['PhanPluginBothLiteralsBinaryOp', 'PhanPluginSuspiciousParamPosition'], diff --git a/htdocs/compta/cashcontrol/cashcontrol_card.php b/htdocs/compta/cashcontrol/cashcontrol_card.php index 89675f57f08ed..66dc032dd2aa3 100644 --- a/htdocs/compta/cashcontrol/cashcontrol_card.php +++ b/htdocs/compta/cashcontrol/cashcontrol_card.php @@ -280,6 +280,9 @@ llxHeader('', $langs->trans("CashControl")); +$terminalid = ''; +$terminaltouse = ''; + if ($action == "create" || $action == "start" || $action == 'close') { if ($action == 'close') { $posmodule = $object->posmodule; @@ -305,7 +308,7 @@ } } - if (isset($terminalid) && $terminalid != '') { + if (isset($terminalid) && $terminalid != '' && isset($posmodule)) { // Calculate $initialbalanceforterminal for terminal 0 foreach ($arrayofpaymentmode as $key => $val) { if ($key != 'cash') { diff --git a/htdocs/compta/charges/index.php b/htdocs/compta/charges/index.php index 9299b55c2cb09..76dde4ff08bf3 100644 --- a/htdocs/compta/charges/index.php +++ b/htdocs/compta/charges/index.php @@ -166,7 +166,7 @@ $sql .= " OR (cs.periode IS NULL AND cs.date_ech between '".$db->idate(dol_get_first_day($year))."' AND '".$db->idate(dol_get_last_day($year))."')"; $sql .= ")"; } - if (preg_match('/^cs\./', $sortfield) || preg_match('/^c\./', $sortfield) || preg_match('/^pc\./', $sortfield) || preg_match('/^pct\./', $sortfield)) { + if (preg_match('/^(cs?|pct?)\./', (string) $sortfield)) { $sql .= $db->order($sortfield, $sortorder); } //$sql.= $db->plimit($limit+1,$offset); @@ -310,7 +310,7 @@ // so we are compatible when period is not mandatory $sql .= " AND pv.datev between '".$db->idate(dol_get_first_day($year, 1, false))."' AND '".$db->idate(dol_get_last_day($year, 12, false))."'"; } - if (preg_match('/^pv\./', $sortfield) || preg_match('/^ptva\./', $sortfield)) { + if (preg_match('/^(pv|ptva)\./', (string) $sortfield)) { $sql .= $db->order($sortfield, $sortorder); } @@ -465,7 +465,7 @@ // so we are compatible when period is not mandatory $sql .= " AND pv.datev between '".$db->idate(dol_get_first_day($year, 1, false))."' AND '".$db->idate(dol_get_last_day($year, 12, false))."'"; } - if (preg_match('/^pv/', $sortfield)) { + if (preg_match('/^pv/', (string) $sortfield)) { $sql .= $db->order($sortfield, $sortorder); } diff --git a/htdocs/compta/deplacement/stats/index.php b/htdocs/compta/deplacement/stats/index.php index d2f0ef0564789..79f3f16c9d8fa 100644 --- a/htdocs/compta/deplacement/stats/index.php +++ b/htdocs/compta/deplacement/stats/index.php @@ -176,6 +176,7 @@ $data = $stats->getAverageByMonthWithPrevYear($endyear, $startyear); $filename_avg = ''; +$fileurl_avg = ''; if (!$user->hasRight('societe', 'client', 'voir')) { $filename_avg = $dir.'/ordersaverage-'.$user->id.'-'.$year.'.png'; if ($mode == 'customer') { diff --git a/htdocs/compta/facture/agenda-rec.php b/htdocs/compta/facture/agenda-rec.php index 5ae579f5a82f9..6cdbed1196e11 100644 --- a/htdocs/compta/facture/agenda-rec.php +++ b/htdocs/compta/facture/agenda-rec.php @@ -1,6 +1,7 @@ * Copyright (C) 2024 Frédéric France + * Copyright (C) 2024 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 @@ -227,15 +228,15 @@ //$messagingUrl = DOL_URL_ROOT.'/societe/agenda.php?socid='.$object->id; //$morehtmlstatus .= dolGetButtonTitle($langs->trans('MessageListViewType'), '', 'fa fa-bars imgforviewmode', $messagingUrl, '', 2); - if (isModEnabled('agenda')) { - /* - if ($user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create')) { - $morehtmlstatus .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out); - } else { - $morehtmlstatus .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out, '', 0); - } - */ + //if (isModEnabled('agenda')) { + /* + if ($user->hasRight('agenda', 'myactions', 'create') || $user->hasRight('agenda', 'allactions', 'create')) { + $morehtmlstatus .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out); + } else { + $morehtmlstatus .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out, '', 0); } + */ + //} if (isModEnabled('agenda') && ($user->hasRight('agenda', 'myactions', 'read') || $user->hasRight('agenda', 'allactions', 'read'))) { diff --git a/htdocs/compta/facture/contact.php b/htdocs/compta/facture/contact.php index 65aff00aa88bf..bd9486e2b9742 100644 --- a/htdocs/compta/facture/contact.php +++ b/htdocs/compta/facture/contact.php @@ -6,6 +6,7 @@ * Copyright (C) 2017 Ferran Marcet * Copyright (C) 2023 Christian Foellmann * Copyright (C) 2024 Frédéric France + * Copyright (C) 2024 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 @@ -63,7 +64,7 @@ $object = new Facture($db); // Load object if ($id > 0 || !empty($ref)) { - $ret = $object->fetch($id, $ref, '', '', (getDolGlobalString('INVOICE_USE_SITUATION') ? $conf->global->INVOICE_USE_SITUATION : 0)); + $ret = $object->fetch($id, $ref, '', 0, (getDolGlobalString('INVOICE_USE_SITUATION') ? $conf->global->INVOICE_USE_SITUATION : 0)); } // Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context $hookmanager->initHooks(array('invoicecontactcard', 'globalcard')); @@ -77,7 +78,7 @@ * Actions */ -$parameters = array('id'=>$id); +$parameters = array('id' => $id); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); diff --git a/htdocs/compta/facture/invoicetemplate_list.php b/htdocs/compta/facture/invoicetemplate_list.php index cf8faf85f15f6..c3a18a0aa2632 100644 --- a/htdocs/compta/facture/invoicetemplate_list.php +++ b/htdocs/compta/facture/invoicetemplate_list.php @@ -927,7 +927,7 @@ // Payment term if (!empty($arrayfields['f.fk_cond_reglement']['checked'])) { print ''; - $form->form_conditions_reglement('', $objp->fk_cond_reglement, 'none'); + $form->form_conditions_reglement(0, $objp->fk_cond_reglement, 'none'); print ''."\n"; if (!$i) { $totalarray['nbfield']++; diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index dfc15d484b037..992fea6556d9a 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -570,6 +570,8 @@ $result_sql = $db->query($rsql); if ($result_sql) { $numprlv = $db->num_rows($result_sql); + } else { + $numprlv = 0; } if ($numprlv > 0) { @@ -633,9 +635,11 @@ if (empty($search_company)) { $search_company = $soc->name; } +} else { + $soc = null; } -$title = $langs->trans('BillsCustomers').' '.($socid > 0 ? ' - '.$soc->name : ''); +$title = $langs->trans('BillsCustomers').' '.(($socid > 0 && $soc !== null) ? ' - '.$soc->name : ''); $help_url = 'EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes'; $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage; @@ -1341,7 +1345,7 @@ include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; $moreforfilter .= '
'; $tmptitle = $langs->trans('IncludingProductWithTag'); - $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1); + $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, '', 'parent', 0, 0, 1); $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_product_category', $cate_arbo, $search_product_category, $tmptitle, 0, 0, '', 0, 0, 0, 0, 'maxwidth300 widthcentpercentminusx', 1); $moreforfilter .= '
'; } @@ -1509,7 +1513,7 @@ // Country if (!empty($arrayfields['country.code_iso']['checked'])) { print ''; - print $form->select_country($search_country, 'search_country', '', 0, 'minwidth150imp maxwidth150', 'code2', 1, 0, 1, null, 1); + print $form->select_country($search_country, 'search_country', '', 0, 'minwidth150imp maxwidth150', 'code2', 1, 0, 1, array(), 1); print ''; } // Company type @@ -2051,10 +2055,10 @@ $multicurrency_remaintopay = 0; } if ($facturestatic->type == Facture::TYPE_CREDIT_NOTE && $obj->paye == 1) { // If credit note closed, we take into account the amount not yet consumed - $remaincreditnote = $discount->getAvailableDiscounts($companystatic, '', 'rc.fk_facture_source='.$facturestatic->id); + $remaincreditnote = $discount->getAvailableDiscounts($companystatic, null, 'rc.fk_facture_source='.$facturestatic->id); $remaintopay = -$remaincreditnote; $totalallpayments = price2num($facturestatic->total_ttc - $remaintopay); - $multicurrency_remaincreditnote = $discount->getAvailableDiscounts($companystatic, '', 'rc.fk_facture_source='.$facturestatic->id, 0, 0, 1); + $multicurrency_remaincreditnote = $discount->getAvailableDiscounts($companystatic, null, 'rc.fk_facture_source='.$facturestatic->id, 0, 0, 1); $multicurrency_remaintopay = -$multicurrency_remaincreditnote; $multicurrency_totalpay = price2num($facturestatic->multicurrency_total_ttc - $multicurrency_remaintopay); }