2
0
forked from Wavyzz/dolibarr

Improve typing, init var, suppress notification

This commit is contained in:
MDW
2024-03-25 17:44:12 +01:00
parent 7c660d3392
commit cfe66e2f60

View File

@@ -688,8 +688,8 @@ function GETPOSTISARRAY($paramname, $method = 0)
* 'restricthtml'=check html content is restricted to some tags only * 'restricthtml'=check html content is restricted to some tags only
* 'custom'= custom filter specify $filter and $options) * 'custom'= custom filter specify $filter and $options)
* @param int $method Type of method (0 = get then post, 1 = only get, 2 = only post, 3 = post then get) * @param int $method Type of method (0 = get then post, 1 = only get, 2 = only post, 3 = post then get)
* @param int $filter Filter to apply when $check is set to 'custom'. (See http://php.net/manual/en/filter.filters.php for détails) * @param ?int $filter Filter to apply when $check is set to 'custom'. (See http://php.net/manual/en/filter.filters.php for détails)
* @param mixed $options Options to pass to filter_var when $check is set to 'custom' * @param mixed $options Options to pass to filter_var when $check is set to 'custom'
* @param int $noreplace Force disable of replacement of __xxx__ strings. * @param int $noreplace Force disable of replacement of __xxx__ strings.
* @return string|array Value found (string or array), or '' if check fails * @return string|array Value found (string or array), or '' if check fails
*/ */
@@ -718,6 +718,8 @@ function GETPOST($paramname, $check = 'alphanohtml', $method = 0, $filter = null
return 'BadThirdParameterForGETPOST'; return 'BadThirdParameterForGETPOST';
} }
$relativepathstring = ''; // For static analysis - looks possibly undefined if not set.
if (empty($method) || $method == 3 || $method == 4) { if (empty($method) || $method == 3 || $method == 4) {
$relativepathstring = (empty($_SERVER["PHP_SELF"]) ? '' : $_SERVER["PHP_SELF"]); $relativepathstring = (empty($_SERVER["PHP_SELF"]) ? '' : $_SERVER["PHP_SELF"]);
// Clean $relativepathstring // Clean $relativepathstring
@@ -759,6 +761,7 @@ function GETPOST($paramname, $check = 'alphanohtml', $method = 0, $filter = null
if (!empty($_GET['action']) && $_GET['action'] == 'create' && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) { if (!empty($_GET['action']) && $_GET['action'] == 'create' && !isset($_GET[$paramname]) && !isset($_POST[$paramname])) {
// Search default value from $object->field // Search default value from $object->field
global $object; global $object;
'@phan-var-force CommonObject $object'; // Suppose it's a CommonObject for analysis, but other objects have the $fields field as well
if (is_object($object) && isset($object->fields[$paramname]['default'])) { if (is_object($object) && isset($object->fields[$paramname]['default'])) {
$out = $object->fields[$paramname]['default']; $out = $object->fields[$paramname]['default'];
} }
@@ -1191,6 +1194,7 @@ if (!function_exists('dol_getprefix')) {
* *
* @param string $mode '' (prefix for session name) or 'email' (prefix for email id) * @param string $mode '' (prefix for session name) or 'email' (prefix for email id)
* @return string A calculated prefix * @return string A calculated prefix
* @phan-suppress PhanRedefineFunction - Also defined in webportal.main.inc.php
*/ */
function dol_getprefix($mode = '') function dol_getprefix($mode = '')
{ {
@@ -1967,13 +1971,14 @@ function dol_ucwords($string, $encoding = "UTF-8")
* *
* @param string $message Line to log. ''=Show nothing * @param string $message Line to log. ''=Show nothing
* @param int $level Log level * @param int $level Log level
* On Windows LOG_ERR=4, LOG_WARNING=5, LOG_NOTICE=LOG_INFO=6, LOG_DEBUG=6 si define_syslog_variables ou PHP 5.3+, 7 si dolibarr * On Windows LOG_ERR=4, LOG_WARNING=5, LOG_NOTICE=LOG_INFO=6, LOG_DEBUG=6 if define_syslog_variables ou PHP 5.3+, 7 if dolibarr
* On Linux LOG_ERR=3, LOG_WARNING=4, LOG_NOTICE=5, LOG_INFO=6, LOG_DEBUG=7 * On Linux LOG_ERR=3, LOG_WARNING=4, LOG_NOTICE=5, LOG_INFO=6, LOG_DEBUG=7
* @param int $ident 1=Increase ident of 1 (after log), -1=Decrease ident of 1 (before log) * @param int $ident 1=Increase ident of 1 (after log), -1=Decrease ident of 1 (before log)
* @param string $suffixinfilename When output is a file, append this suffix into default log filename. Example '_stripe', '_mail' * @param string $suffixinfilename When output is a file, append this suffix into default log filename. Example '_stripe', '_mail'
* @param string $restricttologhandler Force output of log only to this log handler * @param string $restricttologhandler Force output of log only to this log handler
* @param array|null $logcontext If defined, an array with extra information (can be used by some log handlers) * @param array|null $logcontext If defined, an array with extra information (can be used by some log handlers)
* @return void * @return void
* @phan-suppress PhanPluginUnknownArrayFunctionParamType $logcontext is not defined in detail
*/ */
function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename = '', $restricttologhandler = '', $logcontext = null) function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename = '', $restricttologhandler = '', $logcontext = null)
{ {
@@ -2194,7 +2199,7 @@ function dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $di
/** /**
* Show tab header of a card * Show tab header of a card
* *
* @param array $links Array of tabs (0=>url, 1=>label, 2=>code, 3=>not used, 4=>text after link, 5=>morecssonlink). Currently initialized by calling a function xxx_admin_prepare_head. Note that label into $links[$i][1] must be already HTML escaped. * @param array<string,array<int<0,5>,string>> $links Array of tabs (0=>url, 1=>label, 2=>code, 3=>not used, 4=>text after link, 5=>morecssonlink). Currently initialized by calling a function xxx_admin_prepare_head. Note that label into $links[$i][1] must be already HTML escaped.
* @param string $active Active tab name (document', 'info', 'ldap', ....) * @param string $active Active tab name (document', 'info', 'ldap', ....)
* @param string $title Title * @param string $title Title
* @param int $notab -1 or 0=Add tab header, 1=no tab header (if you set this to 1, using print dol_get_fiche_end() to close tab is not required), -2=Add tab header with no sepaaration under tab (to start a tab just after), -3=Add tab header but no footer separation * @param int $notab -1 or 0=Add tab header, 1=no tab header (if you set this to 1, using print dol_get_fiche_end() to close tab is not required), -2=Add tab header with no sepaaration under tab (to start a tab just after), -3=Add tab header but no footer separation
@@ -2215,7 +2220,7 @@ function dol_fiche_head($links = array(), $active = '0', $title = '', $notab = 0
/** /**
* Show tabs of a record * Show tabs of a record
* *
* @param array $links Array of tabs (0=>url, 1=>label, 2=>code, 3=>not used, 4=>text after link, 5=>morecssonlink). Currently initialized by calling a function xxx_admin_prepare_head. Note that label into $links[$i][1] must be already HTML escaped. * @param array<string,array<int<0,5>,string>> $links Array of tabs (0=>url, 1=>label, 2=>code, 3=>not used, 4=>text after link, 5=>morecssonlink). Currently initialized by calling a function xxx_admin_prepare_head. Note that label into $links[$i][1] must be already HTML escaped.
* @param string $active Active tab name * @param string $active Active tab name
* @param string $title Title * @param string $title Title
* @param int $notab -1 or 0=Add tab header, 1=no tab header (if you set this to 1, using print dol_get_fiche_end() to close tab is not required), -2=Add tab header with no separation under tab (to start a tab just after), -3=-2+'noborderbottom' * @param int $notab -1 or 0=Add tab header, 1=no tab header (if you set this to 1, using print dol_get_fiche_end() to close tab is not required), -2=Add tab header with no separation under tab (to start a tab just after), -3=-2+'noborderbottom'
@@ -2467,6 +2472,7 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi
$maxvisiblephotos = 1; $maxvisiblephotos = 1;
$showimage = 1; $showimage = 1;
$entity = (empty($object->entity) ? $conf->entity : $object->entity); $entity = (empty($object->entity) ? $conf->entity : $object->entity);
// @phan-suppress-next-line PhanUndeclaredMethod
$showbarcode = empty($conf->barcode->enabled) ? 0 : (empty($object->barcode) ? 0 : 1); $showbarcode = empty($conf->barcode->enabled) ? 0 : (empty($object->barcode) ? 0 : 1);
if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('barcode', 'lire_advance')) { if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('barcode', 'lire_advance')) {
$showbarcode = 0; $showbarcode = 0;
@@ -2497,6 +2503,7 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi
if ($object->element == 'product') { if ($object->element == 'product') {
/** @var Product $object */ /** @var Product $object */
'@phan-var-force Product $object';
$width = 80; $width = 80;
$cssclass = 'photowithmargin photoref'; $cssclass = 'photowithmargin photoref';
$showimage = $object->is_photo_available($conf->product->multidir_output[$entity]); $showimage = $object->is_photo_available($conf->product->multidir_output[$entity]);
@@ -2505,7 +2512,7 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi
$maxvisiblephotos = 1; $maxvisiblephotos = 1;
} }
if ($showimage) { if ($showimage) {
$morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">'.$object->show_photos('product', $conf->product->multidir_output[$entity], 'small', $maxvisiblephotos, 0, 0, 0, 0, $width, 0, '').'</div>'; $morehtmlleft .= '<div class="floatleft inline-block valignmiddle divphotoref">'.$object->show_photos('product', $conf->product->multidir_output[$entity], 1, $maxvisiblephotos, 0, 0, 0, 0, $width, 0, '').'</div>';
} else { } else {
if (getDolGlobalString('PRODUCT_NODISPLAYIFNOPHOTO')) { if (getDolGlobalString('PRODUCT_NODISPLAYIFNOPHOTO')) {
$nophoto = ''; $nophoto = '';
@@ -2517,6 +2524,7 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi
} }
} elseif ($object->element == 'category') { } elseif ($object->element == 'category') {
/** @var Categorie $object */ /** @var Categorie $object */
'@phan-var-force Categorie $object';
$width = 80; $width = 80;
$cssclass = 'photowithmargin photoref'; $cssclass = 'photowithmargin photoref';
$showimage = $object->isAnyPhotoAvailable($conf->categorie->multidir_output[$entity]); $showimage = $object->isAnyPhotoAvailable($conf->categorie->multidir_output[$entity]);
@@ -2537,6 +2545,7 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi
} }
} elseif ($object->element == 'bom') { } elseif ($object->element == 'bom') {
/** @var Bom $object */ /** @var Bom $object */
'@phan-var-force Bom $object';
$width = 80; $width = 80;
$cssclass = 'photowithmargin photoref'; $cssclass = 'photowithmargin photoref';
$showimage = $object->is_photo_available($conf->bom->multidir_output[$entity]); $showimage = $object->is_photo_available($conf->bom->multidir_output[$entity]);
@@ -2559,6 +2568,7 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi
$width = 80; $width = 80;
$cssclass = 'photoref'; $cssclass = 'photoref';
/** @var Ticket $object */ /** @var Ticket $object */
'@phan-var-force Ticket $object';
$showimage = $object->is_photo_available($conf->ticket->multidir_output[$entity].'/'.$object->ref); $showimage = $object->is_photo_available($conf->ticket->multidir_output[$entity].'/'.$object->ref);
$maxvisiblephotos = getDolGlobalInt('TICKET_MAX_VISIBLE_PHOTO', 2); $maxvisiblephotos = getDolGlobalInt('TICKET_MAX_VISIBLE_PHOTO', 2);
if ($conf->browser->layout == 'phone') { if ($conf->browser->layout == 'phone') {
@@ -3218,7 +3228,7 @@ function dol_print_date($time, $format = '', $tzoutput = 'auto', $outputlangs =
* @param int $timestamp Timestamp * @param int $timestamp Timestamp
* @param boolean $fast Fast mode. deprecated. * @param boolean $fast Fast mode. deprecated.
* @param string $forcetimezone '' to use the PHP server timezone. Or use a form like 'gmt', 'Europe/Paris' or '+0200' to force timezone. * @param string $forcetimezone '' to use the PHP server timezone. Or use a form like 'gmt', 'Europe/Paris' or '+0200' to force timezone.
* @return array Array of information * @return array{seconds:int<0,59>,minutes:int<0,59>,hours:int<0,23>,mday:int<1,31>,wday:int<0,6>,mon:int<1,12>,year:int<0,9999>,yday:int<0,366>,0:int} Array of information
* 'seconds' => $secs, * 'seconds' => $secs,
* 'minutes' => $min, * 'minutes' => $min,
* 'hours' => $hour, * 'hours' => $hour,
@@ -7345,7 +7355,7 @@ function yn($yesno, $case = 1, $color = 0)
* @param int $level Level of subdirs to return (1, 2 or 3 levels). (deprecated, global option will be used in future) * @param int $level Level of subdirs to return (1, 2 or 3 levels). (deprecated, global option will be used in future)
* @param int $alpha 0=Keep number only to forge path, 1=Use alpha part after the - (By default, use 0). (deprecated, global option will be used in future) * @param int $alpha 0=Keep number only to forge path, 1=Use alpha part after the - (By default, use 0). (deprecated, global option will be used in future)
* @param int $withoutslash 0=With slash at end (except if '/', we return ''), 1=without slash at end * @param int $withoutslash 0=With slash at end (except if '/', we return ''), 1=without slash at end
* @param Object $object Object to use to get ref to forge the path. * @param ?CommonObject $object Object to use to get ref to forge the path.
* @param string $modulepart Type of object ('invoice_supplier, 'donation', 'invoice', ...'). Use '' for autodetect from $object. * @param string $modulepart Type of object ('invoice_supplier, 'donation', 'invoice', ...'). Use '' for autodetect from $object.
* @return string Dir to use ending. Example '' or '1/' or '1/2/' * @return string Dir to use ending. Example '' or '1/' or '1/2/'
* @see getMultiDirOuput() * @see getMultiDirOuput()
@@ -13103,7 +13113,7 @@ function dolForgeCriteriaCallback($matches)
* Get timeline icon * Get timeline icon
* *
* @param ActionComm $actionstatic actioncomm * @param ActionComm $actionstatic actioncomm
* @param array<string,array{percent:int}> $histo histo * @param array<int,array{percent:int}> $histo histo
* @param int $key key * @param int $key key
* @return string String with timeline icon * @return string String with timeline icon
* @deprecated Use actioncomm->getPictoType() instead * @deprecated Use actioncomm->getPictoType() instead
@@ -13603,20 +13613,20 @@ function show_actions_messaging($conf, $langs, $db, $filterobj, $objcon = null,
if ($donetodo) { if ($donetodo) {
$tmp = ''; $tmp = '';
if (get_class($filterobj) == 'Societe') { if ($filterobj instanceof Societe) {
$tmp .= '<a href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&socid='.$filterobj->id.'&status=done">'; $tmp .= '<a href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&socid='.$filterobj->id.'&status=done">';
} }
if (get_class($filterobj) == 'User') { if ($filterobj instanceof User) {
$tmp .= '<a href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&socid='.$filterobj->id.'&status=done">'; $tmp .= '<a href="'.DOL_URL_ROOT.'/comm/action/list.php?mode=show_list&socid='.$filterobj->id.'&status=done">';
} }
$tmp .= ($donetodo != 'done' ? $langs->trans("ActionsToDoShort") : ''); $tmp .= ($donetodo != 'done' ? $langs->trans("ActionsToDoShort") : '');
$tmp .= ($donetodo != 'done' && $donetodo != 'todo' ? ' / ' : ''); $tmp .= ($donetodo != 'done' && $donetodo != 'todo' ? ' / ' : '');
$tmp .= ($donetodo != 'todo' ? $langs->trans("ActionsDoneShort") : ''); $tmp .= ($donetodo != 'todo' ? $langs->trans("ActionsDoneShort") : '');
//$out.=$langs->trans("ActionsToDoShort").' / '.$langs->trans("ActionsDoneShort"); //$out.=$langs->trans("ActionsToDoShort").' / '.$langs->trans("ActionsDoneShort");
if (get_class($filterobj) == 'Societe') { if ($filterobj instanceof Societe) {
$tmp .= '</a>'; $tmp .= '</a>';
} }
if (get_class($filterobj) == 'User') { if ($filterobj instanceof User) {
$tmp .= '</a>'; $tmp .= '</a>';
} }
$out .= getTitleFieldOfList($tmp); $out .= getTitleFieldOfList($tmp);