From a4d8ec381098a05c7a459fc648de97224190abc2 Mon Sep 17 00:00:00 2001 From: MDW Date: Sat, 30 Mar 2024 22:09:24 +0100 Subject: [PATCH 1/8] Remove useless test - empty('0') is also true --- htdocs/admin/security_file.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/admin/security_file.php b/htdocs/admin/security_file.php index 0c191d9ae7b..ba2d0be6054 100644 --- a/htdocs/admin/security_file.php +++ b/htdocs/admin/security_file.php @@ -2,6 +2,7 @@ /* Copyright (C) 2004-2017 Laurent Destailleur * Copyright (C) 2005-2017 Regis Houssin * Copyright (C) 2013 Juanjo Menent + * 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 @@ -86,7 +87,7 @@ if ($action == 'updateform') { if (!preg_match('/^0/', $tmpumask)) { $tmpumask = '0'.$tmpumask; } - if (empty($tmpumask) || $tmpumask === '0') { + if (empty($tmpumask)) { // Also matches '0' $tmpumask = '0664'; } From a27b7300904624b4a728a7be54f0302c747ff29e Mon Sep 17 00:00:00 2001 From: MDW Date: Sat, 30 Mar 2024 23:56:37 +0100 Subject: [PATCH 2/8] Final elseif conditions is always true, optimize --- htdocs/core/class/notify.class.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/htdocs/core/class/notify.class.php b/htdocs/core/class/notify.class.php index f2a19b8269e..e498e287323 100644 --- a/htdocs/core/class/notify.class.php +++ b/htdocs/core/class/notify.class.php @@ -7,6 +7,7 @@ * Copyright (C) 2022 Anthony Berton * Copyright (C) 2023 William Mead * Copyright (C) 2024 Jon Bendtsen + * 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 @@ -213,7 +214,7 @@ class Notify $texte = img_object($langs->trans("Notifications"), 'email', 'class="pictofixedwidth"').$langs->trans("NoNotificationsWillBeSent"); } elseif ($nb == 1) { $texte = img_object($langs->trans("Notifications"), 'email', 'class="pictofixedwidth"').$langs->trans("ANotificationsWillBeSent"); - } elseif ($nb >= 2) { + } else { // Always >= 2 if ($nb >= 2) { $texte = img_object($langs->trans("Notifications"), 'email', 'class="pictofixedwidth"').$langs->trans("SomeNotificationsWillBeSent", $nb); } @@ -485,7 +486,7 @@ class Notify $newval2 = trim($obj->email); $isvalid = isValidEmail($newval2); if (empty($resarray[$newval2])) { - $resarray[$newval2] = array('type'=> 'tocontact', 'code'=>trim($obj->code), 'emaildesc'=>'Contact id '.$obj->rowid, 'email'=>$newval2, 'contactid'=>$obj->rowid, 'isemailvalid'=>$isvalid); + $resarray[$newval2] = array('type' => 'tocontact', 'code' => trim($obj->code), 'emaildesc' => 'Contact id '.$obj->rowid, 'email' => $newval2, 'contactid' => $obj->rowid, 'isemailvalid' => $isvalid); } } $i++; @@ -524,7 +525,7 @@ class Notify $newval2 = trim($obj->email); $isvalid = isValidEmail($newval2); if (empty($resarray[$newval2])) { - $resarray[$newval2] = array('type'=> 'touser', 'code'=>trim($obj->code), 'emaildesc'=>'User id '.$obj->rowid, 'email'=>$newval2, 'userid'=>$obj->rowid, 'isemailvalid'=>$isvalid); + $resarray[$newval2] = array('type' => 'touser', 'code' => trim($obj->code), 'emaildesc' => 'User id '.$obj->rowid, 'email' => $newval2, 'userid' => $obj->rowid, 'isemailvalid' => $isvalid); } } $i++; @@ -575,7 +576,7 @@ class Notify if ($newval2) { $isvalid = isValidEmail($newval2, 0); if (empty($resarray[$newval2])) { - $resarray[$newval2] = array('type'=> 'tofixedemail', 'code'=>trim($key), 'emaildesc'=>trim($val2), 'email'=>$newval2, 'isemailvalid'=>$isvalid); + $resarray[$newval2] = array('type' => 'tofixedemail', 'code' => trim($key), 'emaildesc' => trim($val2), 'email' => $newval2, 'isemailvalid' => $isvalid); } } } @@ -889,7 +890,7 @@ class Notify $dir_output = $conf->$object_type->multidir_output[$object->entity ? $object->entity : $conf->entity]."/".get_exdir(0, 0, 0, 1, $object, $object_type); $template = $notifcode.'_TEMPLATE'; $mesg = $outputlangs->transnoentitiesnoconv('Notify_'.$notifcode).' '.$newref.' '.$dir_output; - break; + break; } include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; @@ -915,7 +916,7 @@ class Notify $ref = dol_sanitizeFileName($newref); $pdf_path = $dir_output."/".$ref.".pdf"; - if (!dol_is_file($pdf_path)||(is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0 && !$arraydefaultmessage->joinfiles)) { + if (!dol_is_file($pdf_path) || (is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0 && !$arraydefaultmessage->joinfiles)) { // We can't add PDF as it is not generated yet. $filepdf = ''; } else { @@ -944,7 +945,7 @@ class Notify $sendto = preg_replace('/[\s,]+$/', '', $sendto); // Clean end of string } - $parameters = array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$filename_list, 'mimefile'=>$mimetype_list, 'filename'=>$mimefilename_list, 'outputlangs'=>$outputlangs, 'labeltouse'=>$labeltouse); + $parameters = array('notifcode' => $notifcode, 'sendto' => $sendto, 'replyto' => $replyto, 'file' => $filename_list, 'mimefile' => $mimetype_list, 'filename' => $mimefilename_list, 'outputlangs' => $outputlangs, 'labeltouse' => $labeltouse); if (!isset($action)) { $action = ''; } @@ -1210,7 +1211,7 @@ class Notify } if ($sendto) { - $parameters = array('notifcode'=>$notifcode, 'sendto'=>$sendto, 'replyto'=>$replyto, 'file'=>$filename_list, 'mimefile'=>$mimetype_list, 'filename'=>$mimefilename_list, 'subject'=>&$subject, 'message'=>&$message); + $parameters = array('notifcode' => $notifcode, 'sendto' => $sendto, 'replyto' => $replyto, 'file' => $filename_list, 'mimefile' => $mimetype_list, 'filename' => $mimefilename_list, 'subject' => &$subject, 'message' => &$message); $reshook = $hookmanager->executeHooks('formatNotificationMessage', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if (empty($reshook)) { if (!empty($hookmanager->resArray['files'])) { From 13043be5c5e284ef99453b32f9ea460e33edae27 Mon Sep 17 00:00:00 2001 From: MDW Date: Sun, 31 Mar 2024 00:00:41 +0100 Subject: [PATCH 3/8] Improve phpdoc typing --- htdocs/core/lib/barcode.lib.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/htdocs/core/lib/barcode.lib.php b/htdocs/core/lib/barcode.lib.php index ca18ed00cb1..f56000ae532 100644 --- a/htdocs/core/lib/barcode.lib.php +++ b/htdocs/core/lib/barcode.lib.php @@ -75,9 +75,9 @@ if (defined('PHP-BARCODE_PATH_COMMAND')) { * * @param string $code Code * @param string $encoding Encoding ('EAN13', 'ISBN', 'C128', 'UPC', 'CBR', 'QRCODE', 'DATAMATRIX', 'ANY'...) - * @param integer $scale Scale + * @param int<1,max> $scale Scale * @param string $mode 'png' or 'jpg' ... - * @return array|string $bars array('encoding': the encoding which has been used, 'bars': the bars, 'text': text-positioning info) or string with error message + * @return array{encoding:string,bars:string,text:string}|string $bars array('encoding': the encoding which has been used, 'bars': the bars, 'text': text-positioning info) or string with error message */ function barcode_print($code, $encoding = "ANY", $scale = 2, $mode = "png") { @@ -124,7 +124,7 @@ function barcode_print($code, $encoding = "ANY", $scale = 2, $mode = "png") * * @param string $code Code * @param string $encoding Encoding - * @return array|false array('encoding': the encoding which has been used, 'bars': the bars, 'text': text-positioning info) + * @return array{encoding:string,bars:string,text:string}|false array('encoding': the encoding which has been used, 'bars': the bars, 'text': text-positioning info) */ function barcode_encode($code, $encoding) { @@ -172,7 +172,7 @@ function barcode_encode($code, $encoding) * Calculate EAN sum * * @param string $ean EAN to encode - * @return integer Sum + * @return int<0,9> EAN Sum */ function barcode_gen_ean_sum($ean) { @@ -206,8 +206,8 @@ function barcode_gen_ean_bars($ean) $line = $guards[0]; for ($i = 1; $i < 13; $i++) { - $str = $digits[$ean[$i]]; - if ($i < 7 && $mirror[$ean[0]][$i - 1] == 1) { + $str = $digits[(int) $ean[$i]]; + if ($i < 7 && $mirror[(int) $ean[0]][$i - 1] == 1) { $line .= strrev($str); } else { $line .= $str; @@ -226,7 +226,7 @@ function barcode_gen_ean_bars($ean) * * @param string $ean Code * @param string $encoding Encoding - * @return array array('encoding': the encoding which has been used, 'bars': the bars, 'text': text-positioning info, 'error': error message if error) + * @return array{encoding:string,bars:string,text:string,error:string}|array{text:string,error:string} array('encoding': the encoding which has been used, 'bars': the bars, 'text': text-positioning info, 'error': error message if error) */ function barcode_encode_ean($ean, $encoding = "EAN-13") { @@ -282,7 +282,7 @@ function barcode_encode_ean($ean, $encoding = "EAN-13") * * @param string $upc Code * @param string $encoding Encoding - * @return array array('encoding': the encoding which has been used, 'bars': the bars, 'text': text-positioning info, 'error': error message if error) + * @return array{encoding:string,bars:string,text:string,error:string}|array{text:string,error:string} array('encoding': the encoding which has been used, 'bars': the bars, 'text': text-positioning info, 'error': error message if error) */ function barcode_encode_upc($upc, $encoding = "UPC") { @@ -332,7 +332,7 @@ function barcode_encode_upc($upc, $encoding = "UPC") * * @param string $code Code * @param string $encoding Encoding - * @return array|false array('encoding': the encoding which has been used, 'bars': the bars, 'text': text-positioning info) + * @return array{encoding:string,bars:string,text:string}|false array('encoding': the encoding which has been used, 'bars': the bars, 'text': text-positioning info) */ function barcode_encode_genbarcode($code, $encoding) { @@ -403,10 +403,10 @@ function barcode_encode_genbarcode($code, $encoding) * * @param string $text the text-line (:: ...) * @param string $bars where to place the bars (...) - * @param int $scale scale factor ( 1 < scale < unlimited (scale 50 will produce 5400x300 pixels when using EAN-13!!!)) + * @param int<1,max> $scale scale factor ( 1 < scale < unlimited (scale 50 will produce 5400x300 pixels when using EAN-13!!!)) * @param string $mode png,gif,jpg (default='png') * @param int $total_y the total height of the image ( default: scale * 60 ) - * @param array $space default: $space[top] = 2 * $scale; $space[bottom]= 2 * $scale; $space[left] = 2 * $scale; $space[right] = 2 * $scale; + * @param array{}|array{top:int,bottom:int,left:int,right:int} $space default: $space[top] = 2 * $scale; $space[bottom]= 2 * $scale; $space[left] = 2 * $scale; $space[right] = 2 * $scale; * @return string|void */ function barcode_outimage($text, $bars, $scale = 1, $mode = "png", $total_y = 0, $space = []) @@ -424,7 +424,7 @@ function barcode_outimage($text, $bars, $scale = 1, $mode = "png", $total_y = 0, if ($total_y < 1) { $total_y = (int) $scale * 60; } - if (!$space) { + if (!is_array($space) || empty($space)) { $space = array('top' => 2 * $scale, 'bottom' => 2 * $scale, 'left' => 2 * $scale, 'right' => 2 * $scale); } @@ -435,7 +435,7 @@ function barcode_outimage($text, $bars, $scale = 1, $mode = "png", $total_y = 0, for ($i = 0; $i < $ln; $i++) { $val = strtolower($bars[$i]); if ($width) { - $xpos += $val * $scale; + $xpos += (int) $val * $scale; $width = false; continue; } From aad8c3d3d27b8ed37a76de8dde1f1eb5ad2e78db Mon Sep 17 00:00:00 2001 From: MDW Date: Sun, 31 Mar 2024 00:22:13 +0100 Subject: [PATCH 4/8] Improve phpdoc for make_substitutions --- htdocs/core/lib/functions.lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index d71455a8044..6584911de3b 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -8992,8 +8992,8 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null, * $mesg = make_substitutions($mesg, $substitutionarray, $langs); * * @param string $text Source string in which we must do substitution - * @param array $substitutionarray Array with key->val to substitute. Example: array('__MYKEY__' => 'MyVal', ...) - * @param Translate $outputlangs Output language + * @param array $substitutionarray Array with key->val to substitute. Example: array('__MYKEY__' => 'MyVal', ...) + * @param ?Translate $outputlangs Output language * @param int $converttextinhtmlifnecessary 0=Convert only value into HTML if text is already in HTML * 1=Will also convert initial $text into HTML if we try to insert one value that is HTML * @return string Output string after substitutions From 5ca5d67939d7dc78cc8a243edc083d2607d06596 Mon Sep 17 00:00:00 2001 From: MDW Date: Sun, 31 Mar 2024 00:24:14 +0100 Subject: [PATCH 5/8] Improve phpdoc typing --- htdocs/hrm/compare.php | 49 +++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/htdocs/hrm/compare.php b/htdocs/hrm/compare.php index 8286c7f0cf4..7e0aab08e4e 100644 --- a/htdocs/hrm/compare.php +++ b/htdocs/hrm/compare.php @@ -5,6 +5,7 @@ * Copyright (C) 2021 Jean-Pascal BOUDET * Copyright (C) 2021 Grégory BLEMAND * 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 @@ -153,16 +154,16 @@ $fk_usergroup1 = GETPOST('fk_usergroup1'); trans('OrJobToCompare') . ''; - $j = new Job($db); - $jobs = $j->fetchAll(); - $TJobs = array(); + echo $langs->trans('OrJobToCompare') . ''; + $j = new Job($db); + $jobs = $j->fetchAll(); + $TJobs = array(); foreach ($jobs as &$j) { $TJobs[$j->id] = $j->label; } - print img_picto('', 'jobprofile', 'class="pictofixedwidth"').$form->selectarray('fk_job', $TJobs, $fk_job, 1); + print img_picto('', 'jobprofile', 'class="pictofixedwidth"').$form->selectarray('fk_job', $TJobs, $fk_job, 1); ?> @@ -502,8 +503,8 @@ function displayUsersListWithPicto(&$TUser, $fk_usergroup = 0, $namelist = 'list * * Allow to get skill(s) of a user * - * @param array $TUser array of employees we need to get skills - * @return array|int + * @param int[] $TUser array of employees we need to get skills + * @return array */ function getSkillForUsers($TUser) { @@ -515,12 +516,12 @@ function getSkillForUsers($TUser) } $sql = 'SELECT sk.rowid, sk.label, sk.description, sk.skill_type, sr.fk_object, sr.objecttype, sr.fk_skill, '; - $sql.= ' MAX(sr.rankorder) as rankorder'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'hrm_skill sk'; - $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'hrm_skillrank sr ON (sk.rowid = sr.fk_skill)'; - $sql.= " WHERE sr.objecttype = '".$db->escape(SkillRank::SKILLRANK_TYPE_USER)."'"; - $sql.= ' AND sr.fk_object IN ('.$db->sanitize(implode(',', $TUser)).')'; - $sql.= " GROUP BY sk.rowid, sk.label, sk.description, sk.skill_type, sr.fk_object, sr.objecttype, sr.fk_skill "; // group par competence + $sql .= ' MAX(sr.rankorder) as rankorder'; + $sql .= ' FROM '.MAIN_DB_PREFIX.'hrm_skill sk'; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'hrm_skillrank sr ON (sk.rowid = sr.fk_skill)'; + $sql .= " WHERE sr.objecttype = '".$db->escape(SkillRank::SKILLRANK_TYPE_USER)."'"; + $sql .= ' AND sr.fk_object IN ('.$db->sanitize(implode(',', $TUser)).')'; + $sql .= " GROUP BY sk.rowid, sk.label, sk.description, sk.skill_type, sr.fk_object, sr.objecttype, sr.fk_skill "; // group par competence $resql = $db->query($sql); $Tab = array(); @@ -530,10 +531,10 @@ function getSkillForUsers($TUser) $num = 0; while ($obj = $db->fetch_object($resql)) { $sql1 = "SELECT COUNT(rowid) as how_many_max FROM ".MAIN_DB_PREFIX."hrm_skillrank as sr"; - $sql1.=" WHERE sr.rankorder = ".((int) $obj->rankorder); - $sql1.=" AND sr.objecttype = '".$db->escape(SkillRank::SKILLRANK_TYPE_USER)."'"; - $sql1.=" AND sr.fk_skill = ".((int) $obj->fk_skill); - $sql1.=" AND sr.fk_object IN (".$db->sanitize(implode(',', $TUser)).")"; + $sql1 .= " WHERE sr.rankorder = ".((int) $obj->rankorder); + $sql1 .= " AND sr.objecttype = '".$db->escape(SkillRank::SKILLRANK_TYPE_USER)."'"; + $sql1 .= " AND sr.fk_skill = ".((int) $obj->fk_skill); + $sql1 .= " AND sr.fk_object IN (".$db->sanitize(implode(',', $TUser)).")"; $resql1 = $db->query($sql1); $objMax = $db->fetch_object($resql1); @@ -561,7 +562,7 @@ function getSkillForUsers($TUser) * Allow to get skill(s) of a job * * @param int $fk_job job we need to get required skills - * @return array|int + * @return stdClass[] */ function getSkillForJob($fk_job) { @@ -572,12 +573,12 @@ function getSkillForJob($fk_job) } $sql = 'SELECT sk.rowid, sk.label, sk.description, sk.skill_type, sr.fk_object, sr.objecttype, sr.fk_skill,'; - $sql.= " MAX(sr.rankorder) as rankorder"; - $sql.=' FROM '.MAIN_DB_PREFIX.'hrm_skill as sk'; - $sql.=' LEFT JOIN '.MAIN_DB_PREFIX.'hrm_skillrank as sr ON (sk.rowid = sr.fk_skill)'; - $sql.=" WHERE sr.objecttype = '".SkillRank::SKILLRANK_TYPE_JOB."'"; - $sql.=' AND sr.fk_object = '.((int) $fk_job); - $sql.=' GROUP BY sk.rowid, sk.label, sk.description, sk.skill_type, sr.fk_object, sr.objecttype, sr.fk_skill'; // group par competence*/ + $sql .= " MAX(sr.rankorder) as rankorder"; + $sql .= ' FROM '.MAIN_DB_PREFIX.'hrm_skill as sk'; + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'hrm_skillrank as sr ON (sk.rowid = sr.fk_skill)'; + $sql .= " WHERE sr.objecttype = '".SkillRank::SKILLRANK_TYPE_JOB."'"; + $sql .= ' AND sr.fk_object = '.((int) $fk_job); + $sql .= ' GROUP BY sk.rowid, sk.label, sk.description, sk.skill_type, sr.fk_object, sr.objecttype, sr.fk_skill'; // group par competence*/ $resql = $db->query($sql); $Tab = array(); From a974df28ab18cfc5b972e00376b5abdadd50f7f8 Mon Sep 17 00:00:00 2001 From: MDW Date: Sun, 31 Mar 2024 00:34:54 +0100 Subject: [PATCH 6/8] Improve doc typing --- .../modules/action/doc/pdf_standard_actions.class.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/htdocs/core/modules/action/doc/pdf_standard_actions.class.php b/htdocs/core/modules/action/doc/pdf_standard_actions.class.php index 6a4a448a43c..bfd1c0b5bc8 100644 --- a/htdocs/core/modules/action/doc/pdf_standard_actions.class.php +++ b/htdocs/core/modules/action/doc/pdf_standard_actions.class.php @@ -2,6 +2,7 @@ /* Copyright (C) 2004 Rodolphe Quiedeville * Copyright (C) 2004-2012 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin + * 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 @@ -160,7 +161,7 @@ class pdf_standard_actions global $action; $object = new stdClass(); - $parameters = array('file'=>$file, 'outputlangs'=>$outputlangs); + $parameters = array('file' => $file, 'outputlangs' => $outputlangs); $reshook = $hookmanager->executeHooks('beforePDFCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks $pdf = pdf_getInstance($this->format); @@ -204,7 +205,7 @@ class pdf_standard_actions $hookmanager = new HookManager($this->db); } $hookmanager->initHooks(array('pdfgeneration')); - $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs); + $parameters = array('file' => $file, 'object' => $object, 'outputlangs' => $outputlangs); global $action; $reshook = $hookmanager->executeHooks('afterPDFCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) { @@ -214,7 +215,7 @@ class pdf_standard_actions dolChmod($file); - $this->result = array('fullpath'=>$file); + $this->result = array('fullpath' => $file); return 1; } @@ -355,7 +356,7 @@ class pdf_standard_actions * @param TCPDF $pdf Object PDF * @param Translate $outputlangs Object lang for output * @param int $pagenb Page nb - * @return float|int Return topshift value + * @return float Return topshift value */ private function _pagehead(&$pdf, $outputlangs, $pagenb) { From fa547c86ef62fd4ac91d01f24b0914af6fece0eb Mon Sep 17 00:00:00 2001 From: MDW Date: Sun, 31 Mar 2024 00:35:25 +0100 Subject: [PATCH 7/8] Improve phpdoc typing --- htdocs/main.inc.php | 60 ++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index 1acf1271eaf..910720b56f2 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -220,10 +220,10 @@ function testSqlAndScriptInject($val, $type) /** * Return true if security check on parameters are OK, false otherwise. * - * @param string|array $var Variable name - * @param int $type 1=GET, 0=POST, 2=PHP_SELF - * @param int $stopcode 0=No stop code, 1=Stop code (default) if injection found - * @return boolean|null True if there is no injection. + * @param string|array $var Variable name + * @param int<0,2> $type 1=GET, 0=POST, 2=PHP_SELF + * @param int<0,1> $stopcode 0=No stop code, 1=Stop code (default) if injection found + * @return boolean True if there is no injection. */ function analyseVarsForSqlAndScriptsInjection(&$var, $type, $stopcode = 1) { @@ -1599,8 +1599,8 @@ if (!function_exists("llxHeader")) { /** * Show HTTP header. Called by top_htmlhead(). * - * @param string $contenttype Content type. For example, 'text/html' - * @param int $forcenocache Force disabling of cache for the page + * @param string $contenttype Content type. For example, 'text/html' + * @param int<0,1> $forcenocache Force disabling of cache for the page * @return void */ function top_httphead($contenttype = 'text/html', $forcenocache = 0) @@ -1730,15 +1730,15 @@ function top_httphead($contenttype = 'text/html', $forcenocache = 0) * Output html header of a page. It calls also top_httphead() * This code is also duplicated into security2.lib.php::dol_loginfunction * - * @param string $head Optional head lines - * @param string $title HTML title - * @param int $disablejs Disable js output - * @param int $disablehead Disable head output - * @param array $arrayofjs Array of complementary js files - * @param array $arrayofcss Array of complementary css files - * @param int $disableforlogin Do not load heavy js and css for login pages - * @param int $disablenofollow Disable nofollow tag for meta robots - * @param int $disablenoindex Disable noindex tag for meta robots + * @param string $head Optional head lines + * @param string $title HTML title + * @param int<0,1> $disablejs Disable js output + * @param int<0,1> $disablehead Disable head output + * @param string[] $arrayofjs Array of complementary js files + * @param string[] $arrayofcss Array of complementary css files + * @param int<0,1> $disableforlogin Do not load heavy js and css for login pages + * @param int<0,1> $disablenofollow Disable nofollow tag for meta robots + * @param int<0,1> $disablenoindex Disable noindex tag for meta robots * @return void */ function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arrayofjs = array(), $arrayofcss = array(), $disableforlogin = 0, $disablenofollow = 0, $disablenoindex = 0) @@ -2146,10 +2146,10 @@ function top_htmlhead($head, $title = '', $disablejs = 0, $disablehead = 0, $arr * @param string $head Lines in the HEAD * @param string $title Title of web page * @param string $target Target to use in menu links (Example: '' or '_top') - * @param int $disablejs Do not output links to js (Ex: qd fonction utilisee par sous formulaire Ajax) - * @param int $disablehead Do not output head section - * @param array $arrayofjs Array of js files to add in header - * @param array $arrayofcss Array of css files to add in header + * @param int<0,1> $disablejs Do not output links to js (Ex: qd fonction utilisee par sous formulaire Ajax) + * @param int<0,1> $disablehead Do not output head section + * @param string[] $arrayofjs Array of js files to add in header + * @param string[] $arrayofcss Array of css files to add in header * @param string $morequerystring Query string to add to the link "print" to get same parameters (use only if autodetect fails) * @param string $helppagename Name of wiki page for help ('' by default). * Syntax is: For a wiki page: EN:EnglishPage|FR:FrenchPage|ES:SpanishPage|DE:GermanPage @@ -2412,7 +2412,7 @@ function top_menu($head, $title = '', $target = '', $disablejs = 0, $disablehead /** * Build the tooltip on user login * - * @param int $hideloginname Hide login name. Show only the image. + * @param int<0,1> $hideloginname Hide login name. Show only the image. * @param string $urllogout URL for logout (Will use DOL_URL_ROOT.'/user/logout.php?token=...' if empty) * @return string HTML content */ @@ -3201,15 +3201,15 @@ function top_menu_search() /** * Show left menu bar * - * @param array $menu_array_before Table of menu entries to show before entries of menu handler. This param is deprecated and must be provided to ''. - * @param string $helppagename Name of wiki page for help ('' by default). - * Syntax is: For a wiki page: EN:EnglishPage|FR:FrenchPage|ES:SpanishPage|DE:GermanPage - * For other external page: http://server/url - * @param string $notused Deprecated. Used in past to add content into left menu. Hooks can be used now. - * @param array $menu_array_after Table of menu entries to show after entries of menu handler - * @param int $leftmenuwithoutmainarea Must be set to 1. 0 by default for backward compatibility with old modules. - * @param string $title Title of web page - * @param int $acceptdelayedhtml 1 if caller request to have html delayed content not returned but saved into global $delayedhtmlcontent (so caller can show it at end of page to avoid flash FOUC effect) + * @param string $menu_array_before Table of menu entries to show before entries of menu handler. This param is deprecated and must be provided to ''. + * @param string $helppagename Name of wiki page for help ('' by default). + * Syntax is: For a wiki page: EN:EnglishPage|FR:FrenchPage|ES:SpanishPage|DE:GermanPage + * For other external page: http://server/url + * @param string $notused Deprecated. Used in past to add content into left menu. Hooks can be used now. + * @param array $menu_array_after Table of menu entries to show after entries of menu handler + * @param int $leftmenuwithoutmainarea Must be set to 1. 0 by default for backward compatibility with old modules. + * @param string $title Title of web page + * @param int<0,1> $acceptdelayedhtml 1 if caller request to have html delayed content not returned but saved into global $delayedhtmlcontent (so caller can show it at end of page to avoid flash FOUC effect) * @return void */ function left_menu($menu_array_before, $helppagename = '', $notused = '', $menu_array_after = array(), $leftmenuwithoutmainarea = 0, $title = '', $acceptdelayedhtml = 0) @@ -3523,7 +3523,7 @@ function main_area($title = '') * * @param string $helppagename Page name ('EN:xxx,ES:eee,FR:fff,DE:ddd...' or 'http://localpage') * @param Translate $langs Language - * @return array Array of help urls + * @return array{helpbaseurl:string,helppage:string,mode:string} Array of help urls */ function getHelpParamFor($helppagename, $langs) { From a0ce1514c137c7957da8d12801fdd311f889e1ab Mon Sep 17 00:00:00 2001 From: MDW Date: Sun, 31 Mar 2024 00:36:03 +0100 Subject: [PATCH 8/8] Improve phpdoc typing --- htdocs/core/lib/modulebuilder.lib.php | 51 ++++++++++++++------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/htdocs/core/lib/modulebuilder.lib.php b/htdocs/core/lib/modulebuilder.lib.php index 200b3422d3a..4e5b480eb73 100644 --- a/htdocs/core/lib/modulebuilder.lib.php +++ b/htdocs/core/lib/modulebuilder.lib.php @@ -31,9 +31,9 @@ * @param string $objectname Name of object * @param string $newmask New mask * @param string $readdir Directory source (use $destdir when not defined) - * @param array $addfieldentry Array of 1 field entry to add array('key'=>,'type'=>,''label'=>,'visible'=>,'enabled'=>,'position'=>,'notnull'=>','index'=>,'searchall'=>,'comment'=>,'help'=>,'isameasure') + * @param array{}|array{name:string,key:string,type:string,label:string,picot?:string,enabled:int<0,1>,notnull:int<0,1>,position:int,visible:int,noteditable?:int<0,1>,alwayseditable?:int<0,1>,default?:string,index?:int,foreignkey?:string,searchall?:int,isameasure?:int<0,1>,css?:string,cssview?:string,csslist?:string,help?:string,showoncombobox?:int<0,1>,disabled?:int<0,1>,autofocusoncreate?:int<0,1>,arrayofkeyval?:array,validate?:int<0,1>,comment?:string} $addfieldentry Array of 1 field entry to add * @param string $delfieldentry Id of field to remove - * @return int|object Return integer <=0 if KO, Object if OK + * @return int<-7,-1>|CommonObject Return integer <=0 if KO, Object if OK * @see rebuildObjectSql() */ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir = '', $addfieldentry = array(), $delfieldentry = '') @@ -89,6 +89,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir = } else { return -4; } + '@phan-var-force CommonObject $object'; // Backup old file dol_copy($pathoffiletoedittarget, $pathoffiletoedittarget.'.back', $newmask, 1); @@ -138,7 +139,7 @@ function rebuildObjectClass($destdir, $module, $objectname, $newmask, $readdir = if (!empty($val['alwayseditable'])) { $texttoinsert .= ' "alwayseditable"=>"'.dol_escape_php($val['alwayseditable']).'",'; } - if (!empty($val['default']) || (isset($val['default']) && $val['default'] === '0')) { + if (array_key_exists('default', $val) && (!empty($val['default']) || $val['default'] === '0')) { $texttoinsert .= ' "default"=>"'.dol_escape_php($val['default']).'",'; } if (!empty($val['index'])) { @@ -549,11 +550,11 @@ function compareFirstValue($a, $b) * @param string $file filename or path * @param array $permissions permissions existing in file * @param int|null $key key for permission needed - * @param array|null $right $right to update or add + * @param array{0:string,1:string}|null $right $right to update or add * @param string|null $objectname name of object * @param string|null $module name of module * @param int<-2,2> $action 0 for delete, 1 for add, 2 for update, -1 when delete object completely, -2 for generate rights after add - * @return int 1 if OK,-1 if KO + * @return int<-1,1> 1 if OK,-1 if KO */ function reWriteAllPermissions($file, $permissions, $key, $right, $objectname, $module, $action) { @@ -672,7 +673,7 @@ function reWriteAllPermissions($file, $permissions, $key, $right, $objectname, $ * Converts a formatted properties string into an associative array. * * @param string $string The formatted properties string. - * @return array The resulting associative array. + * @return array The resulting associative array. */ function parsePropertyString($string) { @@ -874,7 +875,7 @@ function getFromFile($file, $start, $end) * Write all permissions of each object in AsciiDoc format * @param string $file path of the class * @param string $destfile file where write table of permissions - * @return int 1 if OK, -1 if KO + * @return int<-1,1> 1 if OK, -1 if KO */ function writePermsInAsciiDoc($file, $destfile) { @@ -959,9 +960,9 @@ function writePermsInAsciiDoc($file, $destfile) * * @param string $srcfile Source file to use as example * @param string $file Path of modified file - * @param array $objects Array of objects in the module + * @param string[] $objects Array of objects in the module * @param string $modulename Name of module - * @return int Return 1 if OK, -1 if KO + * @return int<-1,1> Return 1 if OK, -1 if KO */ function addObjectsToApiFile($srcfile, $file, $objects, $modulename) { @@ -1044,9 +1045,9 @@ function addObjectsToApiFile($srcfile, $file, $objects, $modulename) * Remove Object variables and methods from API_Module File * * @param string $file File api module - * @param array $objects Array of objects in the module + * @param string[] $objects Array of objects in the module * @param string $objectname Name of object want to remove - * @return int 1 if OK, -1 if KO + * @return int<-1,1> 1 if OK, -1 if KO */ function removeObjectFromApiFile($file, $objects, $objectname) { @@ -1091,12 +1092,12 @@ function removeObjectFromApiFile($file, $objects, $objectname) /** - * @param string $file path of filename - * @param mixed $menus all menus for module - * @param mixed|null $menuWantTo menu get for do actions - * @param int|null $key key for the concerned menu - * @param int $action for specify what action (0 = delete, 1 = add, 2 = update, -1 = when delete object) - * @return int 1 if OK, -1 if KO + * @param string $file path of filename + * @param array $menus all menus for module + * @param mixed|null $menuWantTo menu get for do actions + * @param int|null $key key for the concerned menu + * @param int<-1,2> $action for specify what action (0 = delete, 1 = add, 2 = update, -1 = when delete object) + * @return int<-1,1> 1 if OK, -1 if KO */ function reWriteAllMenus($file, $menus, $menuWantTo, $key, $action) { @@ -1194,7 +1195,7 @@ function reWriteAllMenus($file, $menus, $menuWantTo, $key, $action) * * @param string $module The name of the module. * @param string $file The path to the module descriptor file. - * @param array $dicts The dictionary data to be updated. + * @param array> $dicts The dictionary data to be updated. * @return int Returns the number of replacements made in the file. */ function updateDictionaryInFile($module, $file, $dicts) @@ -1267,8 +1268,8 @@ function updateDictionaryInFile($module, $file, $dicts) * @param string $modulename The lowercase name of the module for which the dictionary table is being created. * @param string $file The file path to the Dolibarr module builder file where the dictionaries are defined. * @param string $namedic The name of the dictionary, which will also be used as the base for the table name. - * @param array|null $dictionnaires An optional array containing pre-existing dictionary data, including 'tabname', 'tablib', 'tabsql', etc. - * @return int|void Return int < 0 if error, return nothing on success + * @param array> $dictionnaires An optional array containing pre-existing dictionary data, including 'tabname', 'tablib', 'tabsql', etc. + * @return int<-1,-1>|void Return int < 0 if error, return nothing on success */ function createNewDictionnary($modulename, $file, $namedic, $dictionnaires = null) { @@ -1289,10 +1290,10 @@ function createNewDictionnary($modulename, $file, $namedic, $dictionnaires = nul $columns = array( 'rowid' => array('type' => 'integer', 'value' => 11, 'extra' => 'AUTO_INCREMENT'), - 'code' => array('type' => 'varchar', 'value' => 255, 'null'=>'NOT NULL'), - 'label' => array('type' => 'varchar', 'value' => 255, 'null'=>'NOT NULL'), - 'position' => array('type' => 'integer', 'value' => 11, 'null'=>'NULL'), - 'use_default' => array('type' => 'varchar', 'value' => 11, 'default'=>'1'), + 'code' => array('type' => 'varchar', 'value' => 255, 'null' => 'NOT NULL'), + 'label' => array('type' => 'varchar', 'value' => 255, 'null' => 'NOT NULL'), + 'position' => array('type' => 'integer', 'value' => 11, 'null' => 'NULL'), + 'use_default' => array('type' => 'varchar', 'value' => 11, 'default' => '1'), 'active' => array('type' => 'integer', 'value' => 3) ); @@ -1348,7 +1349,7 @@ function createNewDictionnary($modulename, $file, $namedic, $dictionnaires = nul * * @param string $file_api filename or path of api * @param string $file_doc filename or path of documentation - * @return int -1 if KO, 1 if OK, 0 if nothing change + * @return int<-1,1> -1 if KO, 1 if OK, 0 if nothing change */ function writeApiUrlsInDoc($file_api, $file_doc) {