From 32839b138bc0cca86ee8da60bbedac7acbbf4eb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Tue, 13 Aug 2024 23:16:09 +0200 Subject: [PATCH] fix phpstan level 5 (#30565) * fix phpstan level 5 * fix phpstan level 5 * fix phpstan level 5 * fix phpstan level 5 * fix phpstan level 5 * fix phpstan level 5 * fix phpstan level 5 * fix phpstan level 5 * fix phpstan level 5 * fix phpstan level 5 * fix phpstan level 5 * fix phpstan level 5 * fix phan * fix phpstan * fix phpstan * fix phpstan * fix phpstan * fix phpstan * fix phpstan * fix phpstan fix phpstan fix phpstan fix phpstan * increase level for apstat --- dev/tools/apstats.php | 2 +- htdocs/comm/action/class/actioncomm.class.php | 2 +- htdocs/compta/facture/class/facture.class.php | 2 +- .../core/class/socialnetworkmanager.class.php | 3 +- htdocs/core/lib/agenda.lib.php | 2 +- htdocs/core/menus/standard/eldy.lib.php | 2 +- .../task/doc/doc_generic_task_odt.modules.php | 155 ++++++++++-------- htdocs/imports/import.php | 20 +-- .../Documentation_full_en.example.asciidoc | 10 +- htdocs/public/webportal/tpl/menu.tpl.php | 19 ++- phpstan.neon.dist | 13 +- 11 files changed, 140 insertions(+), 90 deletions(-) diff --git a/dev/tools/apstats.php b/dev/tools/apstats.php index 6f71492b32d..e33526e270b 100755 --- a/dev/tools/apstats.php +++ b/dev/tools/apstats.php @@ -98,7 +98,7 @@ while ($i < $argc) { } // PHPSTAN setup -$PHPSTANLEVEL = 4; +$PHPSTANLEVEL = 6; // PHAN setup. Configuration is required, otherwise phan is disabled. $PHAN_CONFIG = "{$path}phan/config_extended.php"; diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index f4630cc04b4..3a7b1d18a51 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -2707,7 +2707,7 @@ class ActionComm extends CommonObject $errormesg = ''; // Make substitution in email content - $substitutionarray = getCommonSubstitutionArray($langs, 0, '', $this); + $substitutionarray = getCommonSubstitutionArray($langs, 0, null, $this); complete_substitutions_array($substitutionarray, $langs, $this); diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 3859944b65f..da36cdcaafa 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -5746,7 +5746,7 @@ class Facture extends CommonInvoice $errormesg = ''; // Make substitution in email content - $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, '', $tmpinvoice); + $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, null, $tmpinvoice); complete_substitutions_array($substitutionarray, $outputlangs, $tmpinvoice); diff --git a/htdocs/core/class/socialnetworkmanager.class.php b/htdocs/core/class/socialnetworkmanager.class.php index 5957a34526e..fbac124cb52 100644 --- a/htdocs/core/class/socialnetworkmanager.class.php +++ b/htdocs/core/class/socialnetworkmanager.class.php @@ -1,5 +1,6 @@ + * 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,7 @@ class SocialNetworkManager /** * @var int */ - private $lastFetchDate; + private $lastFetchDate; // @phpstan-ignore-line /** * Constructor diff --git a/htdocs/core/lib/agenda.lib.php b/htdocs/core/lib/agenda.lib.php index 1649b5e3682..5c627f94655 100644 --- a/htdocs/core/lib/agenda.lib.php +++ b/htdocs/core/lib/agenda.lib.php @@ -41,7 +41,7 @@ * @param int $pid Product id * @param int $socid Third party id * @param string $action Action string - * @param array $showextcals Array with list of external calendars (used to show links to select calendar), or -1 to show no legend + * @param array|int $showextcals Array with list of external calendars (used to show links to select calendar), or -1 to show no legend * @param string|array $actioncode Preselected value(s) of actioncode for filter on event type * @param int $usergroupid Id of group to filter on users * @param string $excludetype A type to exclude ('systemauto', 'system', '') diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index e1c67c5b01f..a3f6a341221 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -744,7 +744,7 @@ function print_left_eldy_menu($db, $menu_array_before, $menu_array_after, &$tabM $mainmenu = ($forcemainmenu ? $forcemainmenu : $_SESSION["mainmenu"] ?? ''); $leftmenu = ($forceleftmenu ? '' : (empty($_SESSION["leftmenu"]) ? 'none' : $_SESSION["leftmenu"] ?? '')); - if (is_null($mainmenu)) { + if (empty($mainmenu)) { $mainmenu = 'home'; } diff --git a/htdocs/core/modules/project/task/doc/doc_generic_task_odt.modules.php b/htdocs/core/modules/project/task/doc/doc_generic_task_odt.modules.php index b330aaac9b2..517a0dc3067 100644 --- a/htdocs/core/modules/project/task/doc/doc_generic_task_odt.modules.php +++ b/htdocs/core/modules/project/task/doc/doc_generic_task_odt.modules.php @@ -531,8 +531,8 @@ class doc_generic_task_odt extends ModelePDFTask // Make substitution $substitutionarray = array( - '__FROM_NAME__' => $this->emetteur->name, - '__FROM_EMAIL__' => $this->emetteur->email, + '__FROM_NAME__' => $this->emetteur->name, + '__FROM_EMAIL__' => $this->emetteur->email, ); complete_substitutions_array($substitutionarray, $langs, $object); // Call the ODTSubstitution hook @@ -547,10 +547,10 @@ class doc_generic_task_odt extends ModelePDFTask $odfHandler = new Odf( $srctemplatepath, array( - 'PATH_TO_TMP' => $conf->project->dir_temp, - 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. - 'DELIMITER_LEFT' => '{', - 'DELIMITER_RIGHT' => '}' + 'PATH_TO_TMP' => $conf->project->dir_temp, + 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. + 'DELIMITER_LEFT' => '{', + 'DELIMITER_RIGHT' => '}' ) ); } catch (Exception $e) { @@ -607,8 +607,6 @@ class doc_generic_task_odt extends ModelePDFTask $odfHandler->setVars($key, $val, true, 'UTF-8'); } catch (OdfException $e) { dol_syslog($e->getMessage(), LOG_INFO); - } catch (SegmentException $e) { - dol_syslog($e->getMessage(), LOG_INFO); } } @@ -621,9 +619,16 @@ class doc_generic_task_odt extends ModelePDFTask $contact_arrray = array_merge($contact_arrray, $contact_temp); } } - if ((is_array($contact_arrray) && count($contact_arrray) > 0)) { + // Check for segment + $foundtagforlines = 1; + try { $listlinestaskres = $odfHandler->setSegment('tasksressources'); - + } catch (OdfExceptionSegmentNotFound $e) { + // We may arrive here if tags for lines not present into template + $foundtagforlines = 0; + dol_syslog($e->getMessage(), LOG_INFO); + } + if ($foundtagforlines && (is_array($contact_arrray) && count($contact_arrray) > 0)) { foreach ($contact_arrray as $contact) { if ($contact['source'] == 'internal') { $objectdetail = new User($this->db); @@ -644,8 +649,6 @@ class doc_generic_task_odt extends ModelePDFTask foreach ($tmparray as $key => $val) { try { $listlinestaskres->setVars($key, $val, true, 'UTF-8'); - } catch (OdfException $e) { - dol_syslog($e->getMessage(), LOG_INFO); } catch (SegmentException $e) { dol_syslog($e->getMessage(), LOG_INFO); } @@ -655,6 +658,16 @@ class doc_generic_task_odt extends ModelePDFTask $odfHandler->mergeSegment($listlinestaskres); } + // Check for segment + $foundtagforlines = 1; + try { + $listlinestasktime = $odfHandler->setSegment('taskstimes'); + } catch (OdfExceptionSegmentNotFound $e) { + // We may arrive here if tags for lines not present into template + $foundtagforlines = 0; + dol_syslog($e->getMessage(), LOG_INFO); + } + // Time resources $sql = "SELECT t.rowid, t.element_date as task_date, t.element_duration as task_duration, t.fk_user, t.note"; $sql .= ", u.lastname, u.firstname"; @@ -666,17 +679,17 @@ class doc_generic_task_odt extends ModelePDFTask $sql .= " ORDER BY t.element_date DESC"; $resql = $this->db->query($sql); - if ($resql) { + if ($foundtagforlines && $resql) { $num = $this->db->num_rows($resql); $i = 0; $tasks = array(); - $listlinestasktime = $odfHandler->setSegment('taskstimes'); + while ($i < $num) { $row = $this->db->fetch_array($resql); if (!empty($row['fk_user'])) { $objectdetail = new User($this->db); $objectdetail->fetch($row['fk_user']); - // TODO Use a cache to aoid fetch for same user + // TODO Use a cache to avoid fetch for same user $row['fullcivname'] = $objectdetail->getFullName($outputlangs, 1); } else { $row['fullcivname'] = ''; @@ -687,8 +700,6 @@ class doc_generic_task_odt extends ModelePDFTask foreach ($tmparray as $key => $val) { try { $listlinestasktime->setVars($key, $val, true, 'UTF-8'); - } catch (OdfException $e) { - dol_syslog($e->getMessage(), LOG_INFO); } catch (SegmentException $e) { dol_syslog($e->getMessage(), LOG_INFO); } @@ -703,29 +714,35 @@ class doc_generic_task_odt extends ModelePDFTask // Replace tags of project files - $listtasksfiles = $odfHandler->setSegment('tasksfiles'); - - $upload_dir = $conf->project->dir_output.'/'.dol_sanitizeFileName($project->ref).'/'.dol_sanitizeFileName($object->ref); - $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', 'name', SORT_ASC, 1); - - - foreach ($filearray as $filedetail) { - $tmparray = $this->get_substitutionarray_task_file($filedetail, $outputlangs); - //dol_syslog(get_class($this).'::main $tmparray'.var_export($tmparray,true)); - foreach ($tmparray as $key => $val) { - try { - $listtasksfiles->setVars($key, $val, true, 'UTF-8'); - } catch (OdfException $e) { - dol_syslog($e->getMessage(), LOG_INFO); - } catch (SegmentException $e) { - dol_syslog($e->getMessage(), LOG_INFO); - } - } - $listtasksfiles->merge(); + // Check for segment + $foundtagforlines = 1; + try { + $listtasksfiles = $odfHandler->setSegment('tasksfiles'); + } catch (OdfExceptionSegmentNotFound $e) { + // We may arrive here if tags for lines not present into template + $foundtagforlines = 0; + dol_syslog($e->getMessage(), LOG_INFO); } - //$listlines->merge(); + if ($foundtagforlines) { + $upload_dir = $conf->project->dir_output.'/'.dol_sanitizeFileName($project->ref).'/'.dol_sanitizeFileName($object->ref); + $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', 'name', SORT_ASC, 1); - $odfHandler->mergeSegment($listtasksfiles); + foreach ($filearray as $filedetail) { + $tmparray = $this->get_substitutionarray_task_file($filedetail, $outputlangs); + //dol_syslog(get_class($this).'::main $tmparray'.var_export($tmparray,true)); + foreach ($tmparray as $key => $val) { + try { + $listtasksfiles->setVars($key, $val, true, 'UTF-8'); + } catch (SegmentException $e) { + dol_syslog($e->getMessage(), LOG_INFO); + } + } + $listtasksfiles->merge(); + } + //$listlines->merge(); + + $odfHandler->mergeSegment($listtasksfiles); + } } catch (OdfException $e) { $this->error = $e->getMessage(); dol_syslog($this->error, LOG_WARNING); @@ -733,35 +750,40 @@ class doc_generic_task_odt extends ModelePDFTask } - // Replace tags of project files + // Check for segment + $foundtagforlines = 1; try { $listlines = $odfHandler->setSegment('projectfiles'); + } catch (OdfExceptionSegmentNotFound $e) { + // We may arrive here if tags for lines not present into template + $foundtagforlines = 0; + dol_syslog($e->getMessage(), LOG_INFO); + } + if ($foundtagforlines) { + try { + $upload_dir = $conf->project->dir_output.'/'.dol_sanitizeFileName($object->ref); + $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', 'name', SORT_ASC, 1); - $upload_dir = $conf->project->dir_output.'/'.dol_sanitizeFileName($object->ref); - $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', 'name', SORT_ASC, 1); + foreach ($filearray as $filedetail) { + //dol_syslog(get_class($this).'::main $filedetail'.var_export($filedetail,true)); + $tmparray = $this->get_substitutionarray_project_file($filedetail, $outputlangs); - - foreach ($filearray as $filedetail) { - //dol_syslog(get_class($this).'::main $filedetail'.var_export($filedetail,true)); - $tmparray = $this->get_substitutionarray_project_file($filedetail, $outputlangs); - - foreach ($tmparray as $key => $val) { - try { - $listlines->setVars($key, $val, true, 'UTF-8'); - } catch (OdfException $e) { - dol_syslog($e->getMessage(), LOG_INFO); - } catch (SegmentException $e) { - dol_syslog($e->getMessage(), LOG_INFO); + foreach ($tmparray as $key => $val) { + try { + $listlines->setVars($key, $val, true, 'UTF-8'); + } catch (SegmentException $e) { + dol_syslog($e->getMessage(), LOG_INFO); + } } + $listlines->merge(); } - $listlines->merge(); + $odfHandler->mergeSegment($listlines); + } catch (OdfException $e) { + $this->error = $e->getMessage(); + dol_syslog($this->error, LOG_WARNING); + return -1; } - $odfHandler->mergeSegment($listlines); - } catch (OdfException $e) { - $this->error = $e->getMessage(); - dol_syslog($this->error, LOG_WARNING); - return -1; } // Replace tags of lines for contacts @@ -773,10 +795,17 @@ class doc_generic_task_odt extends ModelePDFTask $contact_arrray = array_merge($contact_arrray, $contact_temp); } } - if ((is_array($contact_arrray) && count($contact_arrray) > 0)) { + // Check for segment + $foundtagforlines = 1; + try { + $listlines = $odfHandler->setSegment('projectcontacts'); + } catch (OdfExceptionSegmentNotFound $e) { + // We may arrive here if tags for lines not present into template + $foundtagforlines = 0; + dol_syslog($e->getMessage(), LOG_INFO); + } + if ($foundtagforlines && (is_array($contact_arrray) && count($contact_arrray) > 0)) { try { - $listlines = $odfHandler->setSegment('projectcontacts'); - foreach ($contact_arrray as $contact) { if ($contact['source'] == 'internal') { $objectdetail = new User($this->db); @@ -797,8 +826,6 @@ class doc_generic_task_odt extends ModelePDFTask foreach ($tmparray as $key => $val) { try { $listlines->setVars($key, $val, true, 'UTF-8'); - } catch (OdfException $e) { - dol_syslog($e->getMessage(), LOG_INFO); } catch (SegmentException $e) { dol_syslog($e->getMessage(), LOG_INFO); } diff --git a/htdocs/imports/import.php b/htdocs/imports/import.php index ebdb27c1089..ca26244439d 100644 --- a/htdocs/imports/import.php +++ b/htdocs/imports/import.php @@ -820,6 +820,7 @@ if ($step == 4 && $datatoimport) { $fieldssource[$i]['example1'] = $langs->trans('Empty'); $i++; } + $fieldssource[$i]['imported'] = 0; } $obj->import_close_file(); } @@ -1085,20 +1086,22 @@ if ($step == 4 && $datatoimport) { $optionsall = array(); foreach ($fieldstarget as $code => $line) { - //var_dump($line); - $tmparray = explode('|', $line["label"]); // If label of field is several translation keys separated with | $labeltoshow = ''; foreach ($tmparray as $tmpkey => $tmpval) { $labeltoshow .= ($labeltoshow ? ' '.$langs->trans('or').' ' : '').$langs->transnoentities($tmpval); } - $optionsall[$code] = array('labelkey' => $line['label'], 'labelkeyarray' => $tmparray, 'label' => $labeltoshow, 'required' => (empty($line["required"]) ? 0 : 1), 'position' => !empty($line['position']) ? $line['position'] : 0); // TODO Get type from a new array into module descriptor. - //$picto = 'email'; + // $picto = 'email'; $picto = ''; - if ($picto) { - $optionsall[$code]['picto'] = $picto; - } + $optionsall[$code] = array( + 'labelkey' => $line['label'], + 'labelkeyarray' => $tmparray, + 'label' => $labeltoshow, + 'required' => (empty($line["required"]) ? 0 : 1), + 'position' => (!empty($line['position']) ? $line['position'] : 0), + 'picto' => $picto, + ); } // $optionsall is an array of all possible target fields. key=>array('label'=>..., 'xxx') @@ -1137,9 +1140,6 @@ if ($step == 4 && $datatoimport) { print '=> '; print ''; - //var_dump($_SESSION['dol_array_match_file_to_database_select']); - //var_dump($_SESSION['dol_array_match_file_to_database']); - $selectforline = ''; $selectforline .= '