From acd8fdc24ea3b05e5f53d9323fcf829bbebb4008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 9 Jun 2024 13:26:45 +0200 Subject: [PATCH] fix phpstan level 4 (#29954) * fix phpstan level 4 * fix phpstan level 4 --- ..._generic_supplier_proposal_odt.modules.php | 75 +++++++++---------- .../doc/doc_generic_usergroup_odt.modules.php | 67 ++++++++--------- htdocs/dav/dav.class.php | 12 ++- .../product/actions_card_product.class.php | 3 +- htdocs/user/class/api_users.class.php | 3 +- 5 files changed, 81 insertions(+), 79 deletions(-) diff --git a/htdocs/core/modules/supplier_proposal/doc/doc_generic_supplier_proposal_odt.modules.php b/htdocs/core/modules/supplier_proposal/doc/doc_generic_supplier_proposal_odt.modules.php index 467b3cf65bd..17e7fb8ae2c 100644 --- a/htdocs/core/modules/supplier_proposal/doc/doc_generic_supplier_proposal_odt.modules.php +++ b/htdocs/core/modules/supplier_proposal/doc/doc_generic_supplier_proposal_odt.modules.php @@ -2,7 +2,7 @@ /* Copyright (C) 2010-2012 Laurent Destailleur * Copyright (C) 2012 Juanjo Menent * Copyright (C) 2016 Charlie Benke - * Copyright (C) 2018 Frédéric France + * Copyright (C) 2018-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 @@ -339,11 +339,11 @@ class doc_generic_supplier_proposal_odt extends ModelePDFSupplierProposal // Make substitution $substitutionarray = array( - '__FROM_NAME__' => $this->emetteur->name, - '__FROM_EMAIL__' => $this->emetteur->email, - '__TOTAL_TTC__' => $object->total_ttc, - '__TOTAL_HT__' => $object->total_ht, - '__TOTAL_VAT__' => $object->total_tva + '__FROM_NAME__' => $this->emetteur->name, + '__FROM_EMAIL__' => $this->emetteur->email, + '__TOTAL_TTC__' => $object->total_ttc, + '__TOTAL_HT__' => $object->total_ht, + '__TOTAL_VAT__' => $object->total_tva ); complete_substitutions_array($substitutionarray, $langs, $object); // Call the ODTSubstitution hook @@ -424,44 +424,39 @@ class doc_generic_supplier_proposal_odt extends ModelePDFSupplierProposal } } // Replace tags of lines + $foundtagforlines = 1; try { - $foundtagforlines = 1; - try { - $listlines = $odfHandler->setSegment('lines'); - } catch (OdfExceptionSegmentNotFound $e) { - // We may arrive here if tags for lines not present into template - $foundtagforlines = 0; - dol_syslog($e->getMessage(), LOG_INFO); - } catch (OdfException $e) { - $foundtagforlines = 0; - dol_syslog($e->getMessage(), LOG_INFO); - } - if ($foundtagforlines) { - $linenumber = 0; - foreach ($object->lines as $line) { - $linenumber++; - $tmparray = $this->get_substitutionarray_lines($line, $outputlangs, $linenumber); - complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines"); - // Call the ODTSubstitutionLine hook - $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray, 'line'=>$line); - $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 { - $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); - } + $listlines = $odfHandler->setSegment('lines'); + } 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) { + $linenumber = 0; + foreach ($object->lines as $line) { + $linenumber++; + $tmparray = $this->get_substitutionarray_lines($line, $outputlangs, $linenumber); + complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines"); + // Call the ODTSubstitutionLine hook + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray, 'line'=>$line); + $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 { + $listlines->setVars($key, $val, true, 'UTF-8'); + } catch (SegmentException $e) { + dol_syslog($e->getMessage(), LOG_INFO); } - $listlines->merge(); } - $odfHandler->mergeSegment($listlines); + $listlines->merge(); + } + try { + $odfHandler->mergeSegment($listlines); + } catch (OdfException $e) { + $this->error = $e->getMessage(); + dol_syslog($this->error, LOG_WARNING); + return -1; } - } catch (OdfException $e) { - $this->error = $e->getMessage(); - dol_syslog($this->error, LOG_WARNING); - return -1; } // Replace labels translated 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 3ac04e38e2a..cabdf9611aa 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 @@ -1,7 +1,7 @@ * Copyright (C) 2012 Juanjo Menent - * Copyright (C) 2018 Frédéric France + * Copyright (C) 2018-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 @@ -422,46 +422,41 @@ class doc_generic_usergroup_odt extends ModelePDFUserGroup } } // Replace tags of lines + $foundtagforlines = 1; try { - $foundtagforlines = 1; - try { - $listlines = $odfHandler->setSegment('lines'); - } catch (OdfExceptionSegmentNotFound $e) { - // We may arrive here if tags for lines not present into template - $foundtagforlines = 0; - dol_syslog($e->getMessage(), LOG_INFO); - } catch (OdfException $e) { - $foundtagforlines = 0; - dol_syslog($e->getMessage(), LOG_INFO); - } - if ($foundtagforlines) { - foreach ($object->members as $u) { - $tmparray = $this->get_substitutionarray_each_var_object($u, $outputlangs); - unset($tmparray['object_pass']); - unset($tmparray['object_pass_indatabase']); - complete_substitutions_array($tmparray, $outputlangs, $object, $user, "completesubstitutionarray_users"); - // Call the ODTSubstitutionLine hook - $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray, 'line'=>$u); - $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)) { - $listlines->setVars($key, $val, true, 'UTF-8'); - } - } catch (OdfException $e) { - dol_syslog($e->getMessage(), LOG_WARNING); - } catch (SegmentException $e) { - dol_syslog($e->getMessage(), LOG_WARNING); + $listlines = $odfHandler->setSegment('lines'); + } 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) { + foreach ($object->members as $u) { + $tmparray = $this->get_substitutionarray_each_var_object($u, $outputlangs); + unset($tmparray['object_pass']); + unset($tmparray['object_pass_indatabase']); + complete_substitutions_array($tmparray, $outputlangs, $object, $user, "completesubstitutionarray_users"); + // Call the ODTSubstitutionLine hook + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray, 'line'=>$u); + $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)) { + $listlines->setVars($key, $val, true, 'UTF-8'); } + } catch (SegmentException $e) { + dol_syslog($e->getMessage(), LOG_WARNING); } - $listlines->merge(); } - $odfHandler->mergeSegment($listlines); + $listlines->merge(); + } + try { + $odfHandler->mergeSegment($listlines); + } catch (OdfException $e) { + $this->error = $e->getMessage(); + dol_syslog($this->error, LOG_WARNING); + return -1; } - } catch (OdfException $e) { - $this->error = $e->getMessage(); - dol_syslog($this->error, LOG_WARNING); - return -1; } // Replace labels translated diff --git a/htdocs/dav/dav.class.php b/htdocs/dav/dav.class.php index 275827a0bf2..13a6b449faa 100644 --- a/htdocs/dav/dav.class.php +++ b/htdocs/dav/dav.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 @@ -27,11 +28,20 @@ */ class CdavLib { + /** + * @var DoliDB + */ private $db; + /** + * @var User + */ private $user; - private $langs; + /** + * @var Translate + */ + private $langs; // @phpstan-ignore-line /** * Constructor diff --git a/htdocs/product/canvas/product/actions_card_product.class.php b/htdocs/product/canvas/product/actions_card_product.class.php index fe7285c8907..6ccec546297 100644 --- a/htdocs/product/canvas/product/actions_card_product.class.php +++ b/htdocs/product/canvas/product/actions_card_product.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 @@ -257,7 +258,7 @@ class ActionsCardProduct * * @return void */ - private function getFieldListCanvas() + private function getFieldListCanvas() // @phpstan-ignore-line { global $conf, $langs; diff --git a/htdocs/user/class/api_users.class.php b/htdocs/user/class/api_users.class.php index 9223ebbc24c..c391f57aa55 100644 --- a/htdocs/user/class/api_users.class.php +++ b/htdocs/user/class/api_users.class.php @@ -2,6 +2,7 @@ /* Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2020 Thibault FOUCART * 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 @@ -773,7 +774,7 @@ class Users extends DolibarrApi * @return array * @throws RestException */ - private function _validate($data) + private function _validate($data) // @phpstan-ignore-line { $account = array(); foreach (Users::$FIELDS as $field) {