From 801a7599757282b013bfd6aaecaed8a27d8e46a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Fri, 25 Oct 2024 14:15:39 +0200 Subject: [PATCH] fix phpstan (#31543) * fix phpstan * fix phpstan * fix phpstan * fix phpstan * fix phpstan * fix phpstan * fix phpstan --- htdocs/core/actions_fetchobject.inc.php | 2 +- htdocs/core/ajax/ajaxtooltip.php | 10 ++++-- htdocs/core/ajax/editextrafield.php | 12 +++++-- htdocs/core/ajax/loadinplace.php | 15 ++++++--- htdocs/core/ajax/saveinplace.php | 14 ++++++-- htdocs/core/boxes/box_actions.php | 2 +- htdocs/core/boxes/box_actions_future.php | 4 +-- htdocs/core/boxes/box_activity.php | 2 +- htdocs/core/boxes/box_birthdays_members.php | 2 +- htdocs/core/boxes/box_boms.php | 2 +- htdocs/core/boxes/box_bookmarks.php | 2 +- .../class/opensurveysondage.class.php | 33 +++++++++++++++++-- phpstan.neon.dist | 2 +- 13 files changed, 80 insertions(+), 22 deletions(-) diff --git a/htdocs/core/actions_fetchobject.inc.php b/htdocs/core/actions_fetchobject.inc.php index 2492ab3dbe6..85573c4da5e 100644 --- a/htdocs/core/actions_fetchobject.inc.php +++ b/htdocs/core/actions_fetchobject.inc.php @@ -1,6 +1,6 @@ - * Copyright (C) 2015 Frederic France + * Copyright (C) 2015-2024 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/htdocs/core/ajax/ajaxtooltip.php b/htdocs/core/ajax/ajaxtooltip.php index 0ea8d182169..6290659b955 100644 --- a/htdocs/core/ajax/ajaxtooltip.php +++ b/htdocs/core/ajax/ajaxtooltip.php @@ -53,9 +53,15 @@ if (GETPOSTISSET('infologin')) { if (GETPOSTISSET('option')) { $params['option'] = GETPOST('option', 'restricthtml'); } - +$element_ref = ''; +if (is_numeric($id)) { + $id = (int) $id; +} else { + $element_ref = $id; + $id = 0; +} // Load object according to $element -$object = fetchObjectByElement($id, $objecttype); +$object = fetchObjectByElement($id, $objecttype, $element_ref); if (empty($object->element)) { httponly_accessforbidden('Failed to get object with fetchObjectByElement(id='.$id.', objecttype='.$objecttype.')'); } diff --git a/htdocs/core/ajax/editextrafield.php b/htdocs/core/ajax/editextrafield.php index 1cc4178fbc8..3982b542441 100644 --- a/htdocs/core/ajax/editextrafield.php +++ b/htdocs/core/ajax/editextrafield.php @@ -1,5 +1,6 @@ +/* Copyright (C) 2022 Laurent Destailleur + * Copyright (C) 2024 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -51,7 +52,14 @@ $field = GETPOST('field', 'aZ09'); $value = GETPOST('value', 'aZ09'); $module = getElementProperties($objectType)['module']; -$object = fetchObjectByElement($objectId, $objectType); +$element_ref = ''; +if (is_numeric($objectId)) { + $objectId = (int) $objectId; +} else { + $element_ref = $objectId; + $objectId = 0; +} +$object = fetchObjectByElement($objectId, $objectType, $element_ref); // Security check if (!$user->hasRight($module, $object->element, 'write') && !$user->hasRight($module, 'write')) { diff --git a/htdocs/core/ajax/loadinplace.php b/htdocs/core/ajax/loadinplace.php index da926556250..949c018d353 100644 --- a/htdocs/core/ajax/loadinplace.php +++ b/htdocs/core/ajax/loadinplace.php @@ -1,6 +1,7 @@ - * Copyright (C) 2024 MDW +/* Copyright (C) 2011-2014 Regis Houssin + * Copyright (C) 2024 MDW + * Copyright (C) 2024 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -42,10 +43,16 @@ $field = GETPOST('field', 'alpha'); $element = GETPOST('element', 'alpha'); $table_element = GETPOST('table_element', 'alpha'); $fk_element = GETPOST('fk_element', 'alpha'); -$id = $fk_element; // Load object according to $id and $element -$object = fetchObjectByElement($id, $element); +$element_ref = ''; +if (is_numeric($fk_element)) { + $id = (int) $fk_element; +} else { + $element_ref = $fk_element; + $id = 0; +} +$object = fetchObjectByElement($id, $element, $element_ref); $module = $object->module; $element = $object->element; diff --git a/htdocs/core/ajax/saveinplace.php b/htdocs/core/ajax/saveinplace.php index 5caa21f0cfc..eba220a9d9b 100644 --- a/htdocs/core/ajax/saveinplace.php +++ b/htdocs/core/ajax/saveinplace.php @@ -1,6 +1,7 @@ - * Copyright (C) 2024 MDW +/* Copyright (C) 2011-2012 Regis Houssin + * Copyright (C) 2024 MDW + * Copyright (C) 2024 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -57,7 +58,14 @@ savemethodname: */ // Load object according to $id and $element -$object = fetchObjectByElement($id, $element); +$element_ref = ''; +if (is_numeric($fk_element)) { + $id = (int) $fk_element; +} else { + $element_ref = $fk_element; + $id = 0; +} +$object = fetchObjectByElement($id, $element, $element_ref); $module = $object->module; $element = $object->element; diff --git a/htdocs/core/boxes/box_actions.php b/htdocs/core/boxes/box_actions.php index 4d9954669eb..d1f8411f3ac 100644 --- a/htdocs/core/boxes/box_actions.php +++ b/htdocs/core/boxes/box_actions.php @@ -3,7 +3,7 @@ * Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2005-2011 Regis Houssin * Copyright (C) 2014 Charles-Fr BENKE - * Copyright (C) 2015 Frederic France + * Copyright (C) 2015-2024 Frédéric France * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify diff --git a/htdocs/core/boxes/box_actions_future.php b/htdocs/core/boxes/box_actions_future.php index 88293dfff4c..43eeed62e95 100644 --- a/htdocs/core/boxes/box_actions_future.php +++ b/htdocs/core/boxes/box_actions_future.php @@ -3,8 +3,8 @@ * Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2005-2011 Regis Houssin * Copyright (C) 2014 Charles-Fr BENKE - * Copyright (C) 2015 Frederic France - * Copyright (C) 2024 MDW + * Copyright (C) 2015-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 diff --git a/htdocs/core/boxes/box_activity.php b/htdocs/core/boxes/box_activity.php index e62e49fe3a6..9ab9544671e 100644 --- a/htdocs/core/boxes/box_activity.php +++ b/htdocs/core/boxes/box_activity.php @@ -1,7 +1,7 @@ * Copyright (C) 2005-2015 Laurent Destailleur - * Copyright (C) 2014-2021 Frederic France + * Copyright (C) 2014-2024 Frédéric France * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify diff --git a/htdocs/core/boxes/box_birthdays_members.php b/htdocs/core/boxes/box_birthdays_members.php index 3ab3863fdb6..edf35d08df1 100644 --- a/htdocs/core/boxes/box_birthdays_members.php +++ b/htdocs/core/boxes/box_birthdays_members.php @@ -2,7 +2,7 @@ /* Copyright (C) 2003-2007 Rodolphe Quiedeville * Copyright (C) 2004-2010 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin - * Copyright (C) 2015-2023 Frederic France + * Copyright (C) 2015-2024 Frédéric France * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify diff --git a/htdocs/core/boxes/box_boms.php b/htdocs/core/boxes/box_boms.php index 99ca90917e2..75d929e0b1a 100644 --- a/htdocs/core/boxes/box_boms.php +++ b/htdocs/core/boxes/box_boms.php @@ -2,7 +2,7 @@ /* Copyright (C) 2003-2007 Rodolphe Quiedeville * Copyright (C) 2004-2009 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin - * Copyright (C) 2015 Frederic France + * Copyright (C) 2015-2024 Frédéric France * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify diff --git a/htdocs/core/boxes/box_bookmarks.php b/htdocs/core/boxes/box_bookmarks.php index ddaf6749dfd..dea4675db3f 100644 --- a/htdocs/core/boxes/box_bookmarks.php +++ b/htdocs/core/boxes/box_bookmarks.php @@ -1,6 +1,6 @@ - * Copyright (C) 2015 Frederic France + * Copyright (C) 2015-2024 Frédéric France * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify diff --git a/htdocs/opensurvey/class/opensurveysondage.class.php b/htdocs/opensurvey/class/opensurveysondage.class.php index 4d9986338e7..13327925dcc 100644 --- a/htdocs/opensurvey/class/opensurveysondage.class.php +++ b/htdocs/opensurvey/class/opensurveysondage.class.php @@ -126,20 +126,49 @@ class Opensurveysondage extends CommonObject * @var string Id sondage not an int */ public $id_sondage; + /** * @var string Description * @deprecated Use $description instead */ public $commentaires; + + /** + * @var string admin mail + */ public $mail_admin; + + /** + * @var string admin name + */ public $nom_admin; + + /** + * @var int ID of user + */ public $fk_user_creat; + + /** + * @var string title of survey + */ public $title; + + /** + * @var int|'' end date of survey + */ public $date_fin = ''; public $status; + + /** + * @var string format 'A' = Text choice (choices are saved into sujet field), 'D' = Date choice (choices are saved into sujet field), 'F' = Form survey + */ public $format; + + /** + * @var int to allow send mail + */ public $mailsonde; - public $entity; + /** * @var int Allow comments on this poll */ @@ -274,7 +303,7 @@ class Opensurveysondage extends CommonObject /** * Load object in memory from the database * - * @param int $id Id object + * @param string $id Id object * @param string $numsurvey Ref of survey (admin or not) * @return int Return integer <0 if KO, >0 if OK */ diff --git a/phpstan.neon.dist b/phpstan.neon.dist index c2f39c480dc..11e816a6995 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -84,7 +84,7 @@ parameters: - '# EmailCollector::getpart\(\) expects string#' - '#(?:(?:CommonStickerGenerator::_Croix|pdf_(?:azur::_tableau_(?:info|tot)|ban::_tableau))\(\)|pdf_(?:bank|c(?:anelle::_tableau_(?:(?:tot|versements)\(\))|ornas::_tableau_(?:(?:info|tot)\(\))|rabe::_tableau_(?:(?:info|tot|versements)\(\))|yan::draw(?:(?:Info|Total)Table\(\)))|e(?:agle(?:(?:::_tableau_tot|_proforma::drawTotalTable)\(\))|instein::_tableau_(?:(?:info|tot)\(\))|ratosthene::draw(?:(?:Info|Total)Table\(\))|spadon::_tableau_tot\(\))|muscadet::_tableau_(?:(?:info|tot)\(\))|octopus::(?:_table(?:(?:FirstPage|au)\(\))|draw(?:(?:Info|Total)Table\(\)))|page(?:foot|head)|(?:rouget::_tableau_tot|s(?:epamandate::_tableau(?:_info)?|ponge::draw(?:(?:Info|Total)Table)|quille::_tableau_tot|t(?:andard_(?:e(?:(?:valuation|xpensereport)::_tableau|xpensereport::tablePayments)|(?:myobjec|supplierpaymen)t::_tableau|supplierpayment::_tableau_cheque)|orm::_tableau_info|rato::tabSignature))|t(?:cpdflabel::writeBarcode|yphon::_tableau_info)|vinci::_tableau_info)\(\)|w(?:atermark|rite(?:LinkedObjects|linedesc))|zenith::_tableau_tot\(\))) expects int, float given\.#' - '#(?:Comm(?:(?:ande::updateline|on(?:Invoice::getLibStatut|StickerGenerator::Set_Char_Size))\(\))|Facture(?:(?:::update|FournisseurRec::add)line\(\))|(?:Holiday::addLogCP|Loan::getLibStatut|SupplierProposal::updateline)\(\)|calcul_price_total) expects int, float given\.#' - - '#(?:dol_(?:mktime|remove_file_process)|fetchObjectByElement|print_actions_filter) expects int, array\|string given\.#' + - '#(?:dol_(?:mktime|remove_file_process)|print_actions_filter) expects int, array\|string given\.#' - '# (CSMSFile) constructor expects int, array\|string given.#' - '#(?:ProductFournisseur::logPrice\(\)) expects float\|null#' - '#(?:(?:Asset::addDepreciationL|Facture(?:(?:(?:Fournisseur)?::add|Fournisseur::update)l))ine\(\)|calcul_price_total|dol_convertToWord|(?:loanCalcMonthlyPaymen|print_paypal_redirec)t) expects float, string given.#'