From 78f593848585828e889b24010e123d385fac68ff Mon Sep 17 00:00:00 2001 From: MDW Date: Fri, 14 Feb 2025 01:09:38 +0100 Subject: [PATCH] Qual: Fix phan notices (resource+salary) --- dev/tools/phan/baseline.txt | 21 ++------- htdocs/resource/card.php | 10 ++-- htdocs/resource/class/dolresource.class.php | 38 +++++++-------- .../class/html.formresource.class.php | 46 +++++++++---------- htdocs/resource/element_resource.php | 8 ++-- htdocs/resource/list.php | 25 +++++----- htdocs/salaries/admin/salaries.php | 3 +- htdocs/salaries/card.php | 16 +++---- htdocs/salaries/class/paymentsalary.class.php | 2 +- htdocs/salaries/class/salariesstats.class.php | 6 +-- htdocs/salaries/class/salary.class.php | 4 +- htdocs/salaries/document.php | 8 ++-- htdocs/salaries/info.php | 7 +-- htdocs/salaries/list.php | 5 +- htdocs/salaries/paiement_salary.php | 15 +++--- htdocs/salaries/stats/index.php | 6 +-- htdocs/salaries/virement_request.php | 21 +++++---- 17 files changed, 114 insertions(+), 127 deletions(-) diff --git a/dev/tools/phan/baseline.txt b/dev/tools/phan/baseline.txt index 402fcca8709..e4bac1868cc 100644 --- a/dev/tools/phan/baseline.txt +++ b/dev/tools/phan/baseline.txt @@ -9,8 +9,8 @@ */ return [ // # Issue statistics: - // PhanTypeMismatchArgument : 1730+ occurrences - // PhanUndeclaredProperty : 510+ occurrences + // PhanTypeMismatchArgument : 1690+ occurrences + // PhanUndeclaredProperty : 500+ occurrences // PhanTypeMismatchArgumentNullable : 350+ occurrences // PhanPluginUnknownArrayMethodReturnType : 170+ occurrences // PhanUndeclaredGlobalVariable : 160+ occurrences @@ -636,23 +636,10 @@ return [ 'htdocs/recruitment/recruitmentjobposition_card.php' => ['PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'], 'htdocs/recruitment/recruitmentjobposition_document.php' => ['PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'], 'htdocs/recruitment/recruitmentjobposition_note.php' => ['PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'], - 'htdocs/resource/card.php' => ['PhanTypeMismatchArgument'], 'htdocs/resource/class/dolresource.class.php' => ['PhanTypeMismatchArgumentNullable'], - 'htdocs/resource/class/html.formresource.class.php' => ['PhanTypeMismatchArgument'], - 'htdocs/resource/element_resource.php' => ['PhanTypeMismatchArgument'], - 'htdocs/resource/list.php' => ['PhanTypeMismatchArgument'], - 'htdocs/salaries/admin/salaries.php' => ['PhanTypeMismatchArgumentProbablyReal'], - 'htdocs/salaries/card.php' => ['PhanTypeMismatchArgument'], 'htdocs/salaries/class/api_salaries.class.php' => ['PhanPluginUnknownArrayMethodParamType', 'PhanPluginUnknownArrayMethodReturnType'], - 'htdocs/salaries/class/paymentsalary.class.php' => ['PhanTypeMismatchArgument'], - 'htdocs/salaries/class/salariesstats.class.php' => ['PhanTypeMismatchArgument'], - 'htdocs/salaries/class/salary.class.php' => ['PhanTypeMismatchArgument'], - 'htdocs/salaries/document.php' => ['PhanTypeMismatchArgument'], - 'htdocs/salaries/info.php' => ['PhanTypeMismatchArgument'], - 'htdocs/salaries/list.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanUndeclaredGlobalVariable'], - 'htdocs/salaries/paiement_salary.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal', 'PhanUndeclaredProperty'], - 'htdocs/salaries/stats/index.php' => ['PhanTypeMismatchArgument'], - 'htdocs/salaries/virement_request.php' => ['PhanPossiblyUndeclaredGlobalVariable', 'PhanTypeMismatchArgument', 'PhanUndeclaredProperty'], + 'htdocs/salaries/paiement_salary.php' => ['PhanUndeclaredProperty'], + 'htdocs/salaries/virement_request.php' => ['PhanUndeclaredProperty'], 'htdocs/societe/admin/societe.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal', 'PhanUndeclaredMethod'], 'htdocs/societe/ajax/company.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchArgumentProbablyReal', 'PhanUndeclaredProperty'], 'htdocs/societe/canvas/actions_card_common.class.php' => ['PhanTypeMismatchArgument'], diff --git a/htdocs/resource/card.php b/htdocs/resource/card.php index 90aa41bbeb7..93af0c5fe59 100644 --- a/htdocs/resource/card.php +++ b/htdocs/resource/card.php @@ -1,7 +1,7 @@ * Copyright (C) 2023-2024 William Mead - * 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 @@ -290,7 +290,7 @@ if ($action == 'create' || $object->fetch($id, $ref) > 0) { print ''; - print $form->widgetForTranslation("address", $object, $permissiontoadd, 'textarea', 'alphanohtml', 'quatrevingtpercent'); + print $form->widgetForTranslation("address", $object, (bool) $permissiontoadd, 'textarea', 'alphanohtml', 'quatrevingtpercent'); print ''; // Zip @@ -302,13 +302,13 @@ if ($action == 'create' || $object->fetch($id, $ref) > 0) { // Town print ''; print ''.$form->editfieldkey('Town', 'town', '', $object, 0).''; - print $formresource->select_ziptown(GETPOSTISSET('town') ? GETPOST('town') : $object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id')); - print $form->widgetForTranslation("town", $object, $permissiontoadd, 'string', 'alphanohtml', 'maxwidth100 quatrevingtpercent'); + print $formresource->select_ziptown(GETPOSTISSET('town') ? GETPOST('town') : $object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id')); + print $form->widgetForTranslation("town", $object, (bool) $permissiontoadd, 'string', 'alphanohtml', 'maxwidth100 quatrevingtpercent'); print ''; // Origin country print ''.$langs->trans("CountryOrigin").''; - print $form->select_country(GETPOSTISSET('country_id') ? GETPOSTINT('country_id') : $object->country_id, 'country_id'); + print $form->select_country(GETPOSTISSET('country_id') ? (string) GETPOSTINT('country_id') : (string) $object->country_id, 'country_id'); if ($user->admin) { print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); } diff --git a/htdocs/resource/class/dolresource.class.php b/htdocs/resource/class/dolresource.class.php index 8ea926faa86..157b3ec6544 100644 --- a/htdocs/resource/class/dolresource.class.php +++ b/htdocs/resource/class/dolresource.class.php @@ -1,7 +1,7 @@ * Copyright (C) 2023-2024 William Mead - * 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 @@ -127,7 +127,7 @@ class Dolresource extends CommonObject public $objelement; /** - * @var array Cache of type of resources. TODO Use $conf->cache['type_of_resources'] instead + * @var array Cache of type of resources. TODO Use->cache['type_of_resources'] instead */ public $cache_code_type_resource; @@ -148,9 +148,9 @@ class Dolresource extends CommonObject /** * Create object in database * - * @param User $user User that creates - * @param int $no_trigger 0=launch triggers after, 1=disable triggers - * @return int if KO: <0 || if OK: Id of created object + * @param User $user User that creates + * @param int<0,1> $no_trigger 0=launch triggers after, 1=disable triggers + * @return int if KO: <0 || if OK: Id of created object */ public function create(User $user, int $no_trigger = 0) { @@ -412,7 +412,7 @@ class Dolresource extends CommonObject $this->errors[] = "Error ".$this->db->lasterror(); } - if (!$error) { + if (!$error && $user !== null) { if (!$notrigger) { // Call trigger $result = $this->call_trigger('RESOURCE_MODIFY', $user); @@ -517,9 +517,9 @@ class Dolresource extends CommonObject /** * Delete a resource object * - * @param User $user User making the change - * @param int $notrigger Disable all triggers - * @return int if OK: >0 || if KO: <0 + * @param User $user User making the change + * @param int<0,1> $notrigger Disable all triggers + * @return int if OK: >0 || if KO: <0 */ public function delete(User $user, int $notrigger = 0) { @@ -759,7 +759,7 @@ class Dolresource extends CommonObject $this->errors[] = "Error ".$this->db->lasterror(); } - if (!$error) { + if (!$error && $user !== null) { if (!$notrigger) { // Call trigger $result = $this->call_trigger('RESOURCE_MODIFY', $user); @@ -913,12 +913,12 @@ class Dolresource extends CommonObject /** * Return clickable link of object (with optional picto) * - * @param int $withpicto Add picto into link - * @param string $option Where point the link ('compta', 'expedition', 'document', ...) - * @param string $get_params Parameters added to url - * @param int $notooltip 1=Disable tooltip - * @param string $morecss Add more css on link - * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking + * @param int<0,2> $withpicto Add picto into link + * @param string $option Where point the link ('compta', 'expedition', 'document', ...) + * @param string $get_params Parameters added to url + * @param int<0,1> $notooltip 1=Disable tooltip + * @param string $morecss Add more css on link + * @param int<-1,1> $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking * @return string String with URL */ public function getNomUrl($withpicto = 0, string $option = '', string $get_params = '', int $notooltip = 0, string $morecss = '', int $save_lastsearch_value = -1) @@ -995,7 +995,7 @@ class Dolresource extends CommonObject /** * Get status label * - * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto + * @param int<0,6> $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto * @return string Label of status */ public function getLibStatut(int $mode = 0) @@ -1006,8 +1006,8 @@ class Dolresource extends CommonObject /** * Get status * - * @param int $status Id status - * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 5=Long label + Picto + * @param int $status Id status + * @param int<0,6> $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 5=Long label + Picto * @return string Label of status */ public static function getLibStatusLabel(int $status, int $mode = 0) diff --git a/htdocs/resource/class/html.formresource.class.php b/htdocs/resource/class/html.formresource.class.php index 8461c3b966e..6f517272040 100644 --- a/htdocs/resource/class/html.formresource.class.php +++ b/htdocs/resource/class/html.formresource.class.php @@ -3,7 +3,7 @@ * Copyright (C) 2019-2024 Frédéric France * Copyright (C) 2022 Ferran Marcet * Copyright (C) 2023 William Mead - * 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 @@ -73,18 +73,18 @@ class FormResource /** * Output html form to select a resource * - * @param int $selected Preselected resource id - * @param string $htmlname Name of field in form - * @param string $filter Optional filters criteria (example: 's.rowid <> x') - * @param int $showempty Add an empty field - * @param int $showtype Show third party type in combo list (customer, prospect or supplier) - * @param int $forcecombo Force to use combo box + * @param int $selected Preselected resource id + * @param string $htmlname Name of field in form + * @param string $filter Optional filters criteria (example: 's.rowid <> x') + * @param int<0,1> $showempty Add an empty field + * @param int<0,1> $showtype Show third party type in combo list (customer, prospect or supplier) + * @param int<0,1> $forcecombo Force to use combo box * @param array}> $event Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) - * @param string $filterkey Filter on key value + * @param string $filterkey Filter on key value * @param int<0,2> $outputmode 0=HTML select string, 1=Array, 2=without form tag - * @param int $limit Limit number of answers, 0 for no limit - * @param string $morecss More css - * @param bool $multiple add [] in the name of element and add 'multiple' attribute + * @param int $limit Limit number of answers, 0 for no limit + * @param string $morecss More css + * @param bool $multiple add [] in the name of element and add 'multiple' attribute * @return string|array HTML string with */ public function select_resource_list($selected = 0, $htmlname = 'fk_resource', $filter = '', $showempty = 0, $showtype = 0, $forcecombo = 0, $event = [], $filterkey = '', $outputmode = 0, $limit = 20, $morecss = 'minwidth100', $multiple = false) @@ -175,15 +175,15 @@ class FormResource /** * Return html list of tickets type * - * @param string $selected Id du type pre-selectionne - * @param string $htmlname Nom de la zone select - * @param string $filtertype To filter on field type in llx_c_ticket_type (array('code'=>xx,'label'=>zz)) - * @param int $format 0=id+libelle, 1=code+code, 2=code+libelle, 3=id+code - * @param int $empty 1=peut etre vide, 0 sinon - * @param int $noadmininfo 0=Add admin info, 1=Disable admin info - * @param int $maxlength Max length of label - * @param int $usejscombo 1=Use jscombo, 0=No js combo - * @param string $morecss Add more css + * @param string $selected Id du type pre-selectionne + * @param string $htmlname Nom de la zone select + * @param string $filtertype To filter on field type in llx_c_ticket_type (array('code'=>xx,'label'=>zz)) + * @param int<0,3> $format 0=id+libelle, 1=code+code, 2=code+libelle, 3=id+code + * @param int<0,1> $empty 1=peut etre vide, 0 sinon + * @param int<0,1> $noadmininfo 0=Add admin info, 1=Disable admin info + * @param int $maxlength Max length of label + * @param int<0,1> $usejscombo 1=Use jscombo, 0=No js combo + * @param string $morecss Add more css * @return void */ public function select_types_resource($selected = '', $htmlname = 'type_resource', $filtertype = '', $format = 0, $empty = 0, $noadmininfo = 0, $maxlength = 0, $usejscombo = 0, $morecss = 'minwidth100') @@ -263,7 +263,7 @@ class FormResource * @param string $htmlname HTML select name * @param string[] $fields Array with key of fields to refresh after selection * @param int $fieldsize Field size - * @param int $disableautocomplete 1 To disable ajax autocomplete features (browser autocomplete may still occurs) + * @param int<0,1> $disableautocomplete 1 To disable ajax autocomplete features (browser autocomplete may still occurs) * @param string $moreattrib Add more attribute on HTML input field * @param string $morecss More css * @return string @@ -297,7 +297,7 @@ class FormResource * Thus the links with the departments are done on a department independently of its name. * * @param int $selected Code state preselected (mus be state id) - * @param integer $country_codeid Country code or id: 0=list for all countries, otherwise country code or country rowid to show + * @param int $country_codeid Country code or id: 0=list for all countries, otherwise country code or country rowid to show * @param string $htmlname Id of department. If '', we want only the string with