diff --git a/dev/build/phpstan/phpstan-baseline.neon b/dev/build/phpstan/phpstan-baseline.neon index 177dbce72e6..2fcbb8c00b4 100644 --- a/dev/build/phpstan/phpstan-baseline.neon +++ b/dev/build/phpstan/phpstan-baseline.neon @@ -11880,30 +11880,12 @@ parameters: count: 1 path: ../../../htdocs/product/class/productbatch.class.php - - - message: '#^Property Productbatch\:\:\$batch \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 3 - path: ../../../htdocs/product/class/productbatch.class.php - - - - message: '#^Property Productbatch\:\:\$eatby \(int\|string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/product/class/productbatch.class.php - - message: '#^Property Productbatch\:\:\$qty \(float\) in isset\(\) is not nullable\.$#' identifier: isset.property count: 3 path: ../../../htdocs/product/class/productbatch.class.php - - - message: '#^Property Productbatch\:\:\$sellby \(int\|string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 1 - path: ../../../htdocs/product/class/productbatch.class.php - - message: '#^Loose comparison using \=\= between '''' and 0 will always evaluate to false\.$#' identifier: equal.alwaysFalse @@ -12480,30 +12462,6 @@ parameters: count: 1 path: ../../../htdocs/product/stats/supplier_proposal.php - - - message: '#^Call to function method_exists\(\) with \$this\(Entrepot\) and ''getLibStatut'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: ../../../htdocs/product/stock/class/entrepot.class.php - - - - message: '#^Call to function method_exists\(\) with \$this\(Entrepot\) and ''getNomUrl'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: ../../../htdocs/product/stock/class/entrepot.class.php - - - - message: '#^Call to function property_exists\(\) with \$this\(Entrepot\) and ''lieu'' will always evaluate to true\.$#' - identifier: function.alreadyNarrowedType - count: 1 - path: ../../../htdocs/product/stock/class/entrepot.class.php - - - - message: '#^Negated boolean expression is always true\.$#' - identifier: booleanNot.alwaysTrue - count: 2 - path: ../../../htdocs/product/stock/class/entrepot.class.php - - message: '#^Call to function is_object\(\) with object will always evaluate to true\.$#' identifier: function.alreadyNarrowedType @@ -12516,66 +12474,12 @@ parameters: count: 1 path: ../../../htdocs/product/stock/class/productlot.class.php - - - message: '#^Property Productlot\:\:\$batch \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 4 - path: ../../../htdocs/product/stock/class/productlot.class.php - - - - message: '#^Property Productlot\:\:\$eatby \(int\|string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: ../../../htdocs/product/stock/class/productlot.class.php - - - - message: '#^Property Productlot\:\:\$eol_date \(int\|string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: ../../../htdocs/product/stock/class/productlot.class.php - - message: '#^Property Productlot\:\:\$fk_product \(int\) in isset\(\) is not nullable\.$#' identifier: isset.property count: 4 path: ../../../htdocs/product/stock/class/productlot.class.php - - - message: '#^Property Productlot\:\:\$fk_user_creat \(int\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 4 - path: ../../../htdocs/product/stock/class/productlot.class.php - - - - message: '#^Property Productlot\:\:\$fk_user_modif \(int\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 4 - path: ../../../htdocs/product/stock/class/productlot.class.php - - - - message: '#^Property Productlot\:\:\$import_key \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 4 - path: ../../../htdocs/product/stock/class/productlot.class.php - - - - message: '#^Property Productlot\:\:\$manufacturing_date \(int\|string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: ../../../htdocs/product/stock/class/productlot.class.php - - - - message: '#^Property Productlot\:\:\$scrapping_date \(int\|string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: ../../../htdocs/product/stock/class/productlot.class.php - - - - message: '#^Property Productlot\:\:\$sellby \(int\|string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 2 - path: ../../../htdocs/product/stock/class/productlot.class.php - - message: '#^Negated boolean expression is always true\.$#' identifier: booleanNot.alwaysTrue @@ -12594,12 +12498,6 @@ parameters: count: 4 path: ../../../htdocs/product/stock/class/productstockentrepot.class.php - - - message: '#^Property ProductStockEntrepot\:\:\$import_key \(string\) in isset\(\) is not nullable\.$#' - identifier: isset.property - count: 4 - path: ../../../htdocs/product/stock/class/productstockentrepot.class.php - - message: '#^Variable \$action might not be defined\.$#' identifier: variable.undefined diff --git a/dev/tools/phan/baseline.txt b/dev/tools/phan/baseline.txt index bbc33c25795..8599ec4b1cc 100644 --- a/dev/tools/phan/baseline.txt +++ b/dev/tools/phan/baseline.txt @@ -13,7 +13,7 @@ return [ // PhanTypeMismatchProperty : 100+ occurrences // PhanTypeMismatchArgument : 65+ occurrences // PhanUndeclaredGlobalVariable : 60+ occurrences - // PhanTypeMismatchArgumentNullable : 40+ occurrences + // PhanTypeMismatchArgumentNullable : 20+ occurrences // PhanTypeInvalidDimOffset : 15+ occurrences // PhanTypeMismatchDimFetch : 10+ occurrences // PhanUndeclaredMethod : 8 occurrences @@ -82,7 +82,7 @@ return [ 'htdocs/core/class/cgenericdic.class.php' => ['PhanUndeclaredProperty'], 'htdocs/core/class/commonobject.class.php' => ['PhanParamTooMany', 'PhanTypeMismatchArgument', 'PhanUndeclaredProperty'], 'htdocs/core/class/commonpeople.class.php' => ['PhanUndeclaredProperty'], - 'htdocs/core/class/conf.class.php' => ['PhanTypeMismatchArgumentNullableInternal', 'PhanTypeMismatchProperty'], + 'htdocs/core/class/conf.class.php' => ['PhanTypeMismatchProperty'], 'htdocs/core/class/ctyperesource.class.php' => ['PhanUndeclaredProperty'], 'htdocs/core/class/dolgraph.class.php' => ['PhanUndeclaredProperty'], 'htdocs/core/class/emailsenderprofile.class.php' => ['PhanUndeclaredProperty'], @@ -121,7 +121,7 @@ return [ 'htdocs/core/modules/holiday/mod_holiday_immaculate.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/modules/hrm/doc/pdf_standard_evaluation.modules.php' => ['PhanUndeclaredProperty'], 'htdocs/core/modules/hrm/mod_evaluation_advanced.php' => ['PhanUndeclaredProperty'], - 'htdocs/core/modules/import/import_csv.modules.php' => ['PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchArgumentNullable', 'PhanTypeMismatchProperty'], + 'htdocs/core/modules/import/import_csv.modules.php' => ['PhanPossiblyUndeclaredVariable', 'PhanTypeMismatchProperty'], 'htdocs/core/modules/import/import_xlsx.modules.php' => ['PhanTypeMismatchProperty'], 'htdocs/core/modules/member/modules_cards.php' => ['PhanTypeMismatchArgument'], 'htdocs/core/modules/mrp/doc/pdf_vinci.modules.php' => ['PhanUndeclaredProperty'], @@ -162,7 +162,7 @@ return [ 'htdocs/expedition/card.php' => ['PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'], 'htdocs/expedition/class/expedition.class.php' => ['PhanUndeclaredProperty'], 'htdocs/expensereport/card.php' => ['PhanUndeclaredProperty'], - 'htdocs/expensereport/class/expensereport.class.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentNullable'], + 'htdocs/expensereport/class/expensereport.class.php' => ['PhanTypeMismatchArgument'], 'htdocs/expensereport/payment/info.php' => ['PhanUndeclaredGlobalVariable'], 'htdocs/externalsite/frames.php' => ['PhanUndeclaredGlobalVariable'], 'htdocs/fichinter/card-rec.php' => ['PhanUndeclaredGlobalVariable'], @@ -223,7 +223,6 @@ return [ 'htdocs/projet/tasks.php' => ['PhanTypeMismatchArgument'], 'htdocs/projet/tasks/time.php' => ['PhanTypeInvalidDimOffset', 'PhanUndeclaredProperty'], 'htdocs/projet/tasks/tpl/linkedobjectblock.tpl.php' => ['PhanUndeclaredProperty'], - 'htdocs/public/members/new.php' => ['PhanUndeclaredGlobalVariable'], 'htdocs/public/payment/newpayment.php' => ['PhanUndeclaredProperty'], 'htdocs/public/project/suggestbooth.php' => ['PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'], 'htdocs/public/project/suggestconference.php' => ['PhanUndeclaredGlobalVariable', 'PhanUndeclaredProperty'], diff --git a/htdocs/core/boxes/box_members_last_subscriptions.php b/htdocs/core/boxes/box_members_last_subscriptions.php index f6323dd7af9..fee00fbafdd 100644 --- a/htdocs/core/boxes/box_members_last_subscriptions.php +++ b/htdocs/core/boxes/box_members_last_subscriptions.php @@ -2,7 +2,7 @@ /* Copyright (C) 2003-2007 Rodolphe Quiedeville * Copyright (C) 2004-2017 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2015-2024 Frédéric France + * Copyright (C) 2015-2025 Frédéric France * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify @@ -151,10 +151,11 @@ class box_members_last_subscriptions extends ModeleBoxes 'text' => price($obj->subscription), ); - $this->info_box_contents[$line][] = array( - 'td' => 'class="right tdoverflowmax150 maxwidth150onsmartphone" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($obj->datem, 'dayhour', 'tzuserrel')).'"', - 'text' => dol_print_date($this->db->jdate($obj->datem ? $obj->datem : $obj->datec), 'dayhour', 'tzuserrel'), - ); + $datetoprint = dol_print_date($this->db->jdate($obj->datem ? $obj->datem : $obj->datec), 'dayhour', 'tzuserrel'); + $this->info_box_contents[$line][] = [ + 'td' => 'class="right tdoverflowmax150 maxwidth150onsmartphone" title="' . dol_escape_htmltag($langs->trans("DateModification") . ': ' . $datetoprint).'"', + 'text' => $datetoprint, + ]; $line++; } diff --git a/htdocs/core/class/commonsignedobject.class.php b/htdocs/core/class/commonsignedobject.class.php index ccd0549b8e7..7715c5cff04 100644 --- a/htdocs/core/class/commonsignedobject.class.php +++ b/htdocs/core/class/commonsignedobject.class.php @@ -1,6 +1,7 @@ * Copyright (C) 2025 Frédéric France + * Copyright (C) 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 @@ -30,7 +31,7 @@ * @property string $error * @property string $table_element * @property array $context - * @method int call_trigger(string $triggerName, User $user) + * @method int call_trigger(string $triggerName, ?User $user) */ trait CommonSignedObject { diff --git a/htdocs/core/class/commontrigger.class.php b/htdocs/core/class/commontrigger.class.php index 9011a53189f..04e1acab9d4 100644 --- a/htdocs/core/class/commontrigger.class.php +++ b/htdocs/core/class/commontrigger.class.php @@ -76,9 +76,9 @@ trait CommonTrigger * NB: Error from trigger are stacked in interface->errors * NB2: If return code of triggers are < 0, action calling trigger should cancel all transaction. * - * @param string $triggerName trigger's name to execute - * @param User $user Object user - * @return int Result of run_triggers + * @param string $triggerName Trigger's name to execute + * @param ?User $user Object user + * @return int Result of run_triggers */ public function call_trigger($triggerName, $user) { diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index 4e65c73f22d..54c35d7a0fe 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -613,6 +613,7 @@ class Conf extends stdClass } if (!empty($newvalue)) { + // @phan-suppress-next-line PhanTypeMismatchArgumentNullableInternal,PhanTypeMismatchProperty $this->modules_parts[$partname] = array_merge($this->modules_parts[$partname], array($modulename => $newvalue)); // $value may be a string or an array } } elseif (preg_match('/^MAIN_MODULE_([0-9A-Z_]+)$/i', $key, $reg)) { diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 7b393e53283..e8855c426ce 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -145,13 +145,13 @@ class Form * @param string $text Text of label or key to translate * @param string $htmlname Name of select field ('edit' prefix will be added) * @param string $preselected Value to show/edit (not used in this function) - * @param object $object Object (on the page we show) + * @param ?object $object Object (on the page we show) * @param int<0,1>|boolean $perm Permission to allow button to edit parameter. Set it to 0 to have a not edited field. * @param string $typeofdata Type of data ('string' by default, 'email', 'amount:99', 'numeric:99', 'text' or 'textarea:rows:cols', 'datepicker' ('day' do not work, don't know why), 'dayhour' or 'datehourpicker' 'checkbox:ckeditor:dolibarr_zzz:width:height:savemethod:1:rows:cols', 'select;xxx[:class]'...) * @param string $moreparam More param to add on a href URL. * @param int<0,1> $fieldrequired 1 if we want to show field as mandatory using the "fieldrequired" CSS. * @param int<0,3> $notabletag 1=Do not output table tags but output a ':', 2=Do not output table tags and no ':', 3=Do not output table tags but output a ' ' - * @param string $paramid Key of parameter for id ('id', 'socid') + * @param 'id'|'socid'|'projectid' $paramid Key of parameter for id ('id', 'socid') * @param string $help Tooltip help * @return string HTML edit field */ @@ -215,7 +215,7 @@ class Form if (empty($notabletag) && $perm) { $ret .= ''; } - if ($htmlname && GETPOST('action', 'aZ09') != 'edit' . $htmlname && $perm) { + if ($htmlname && GETPOST('action', 'aZ09') != 'edit' . $htmlname && $perm && is_object($object)) { $ret .= ' 'edit' . $htmlname, $paramid => $object->id], true) . $moreparam . '">'; $ret .= img_edit($langs->trans('Edit'), ($notabletag ? 0 : 1)); $ret .= ''; @@ -3345,7 +3345,7 @@ class Form // include search in supplier ref if (getDolGlobalString('MAIN_SEARCH_PRODUCT_BY_FOURN_REF')) { - $sqlSupplierSearch .= !empty($sqlSupplierSearch) ? ' AND ':''; + $sqlSupplierSearch .= !empty($sqlSupplierSearch) ? ' AND ' : ''; $sqlSupplierSearch .= " pfp.ref_fourn LIKE '" . $this->db->escape($prefix . $crit) . "%'"; } $sql .= ")"; @@ -9142,7 +9142,7 @@ class Form * Output html form to select an object. * Note, this function is called by selectForForms or by ajax selectobject.php * - * @param Object $objecttmp Object to know the table to scan for combo. + * @param CommonObject $objecttmp Object to know the table to scan for combo. * @param string $htmlname Name of HTML select component * @param int $preselectedvalue Preselected value (ID of element) * @param string|int<0,1> $showempty ''=empty values not allowed, 'string'=value show if we allow empty values (for example 'All', ...) @@ -9185,7 +9185,7 @@ class Form } } else { // For backward compatibility - $objecttmp->fields['ref'] = array('type' => 'varchar(30)', 'label' => 'Ref', 'showoncombobox' => 1); + $objecttmp->fields['ref'] = array('type' => 'varchar(30)', 'label' => 'Ref', 'enabled' => 1, 'position' => 10, 'visible' => 4, 'showoncombobox' => 1); } if (empty($fieldstoshow)) { @@ -9219,6 +9219,7 @@ class Form $sql .= " LEFT JOIN " . $this->db->prefix() . $this->db->sanitize($objecttmp->table_element) . "_extrafields as e ON t.rowid = e.fk_object"; } if (!empty($objecttmp->parent_element)) { // If parent_element is defined + '@phan-var-force CommonObjectLine $objecttmp'; $parent_properties = getElementProperties($objecttmp->parent_element); $sql .= " INNER JOIN " . $this->db->prefix() . $this->db->sanitize($parent_properties['table_element']) . " as o ON o.rowid = t.".$objecttmp->fk_parent_attribute; } @@ -10518,10 +10519,10 @@ class Form // If we ask a resource form external module (instead of default path) - $module=''; + $module = ''; if (preg_match('/^([^@]+)@([^@]+)$/i', $key, $regs)) { // 'myobject@mymodule' $key = $regs[1]; - $module=$regs[2]; + $module = $regs[2]; } if (!empty($possiblelink['perms']) && (empty($restrictlinksto) || in_array($key, $restrictlinksto)) && (empty($excludelinksto) || !in_array($key, $excludelinksto))) { @@ -10535,7 +10536,7 @@ class Form $htmltoenteralink .= ''; $htmltoenteralink .= ''; $htmltoenteralink .= ''; - $htmltoenteralink .= ''; + $htmltoenteralink .= ''; $htmltoenteralink .= ''; $htmltoenteralink .= ''; //print ''; @@ -10564,7 +10565,7 @@ class Form $htmltoenteralink .= ''; $htmltoenteralink .= ''; $htmltoenteralink .= ''; - $htmltoenteralink .= ''; + $htmltoenteralink .= ''; $htmltoenteralink .= '
' . $langs->trans("Ref") . '
'; $htmltoenteralink .= ''; $htmltoenteralink .= ''; @@ -11055,32 +11056,34 @@ class Form $email = $object->email; } elseif ($modulepart == 'contact') { $dir = $conf->societe->multidir_output[$entity] . '/contact'; - if (!empty($object->photo)) { - if (dolIsAllowedForPreview($object->photo)) { + $photo = $object->photo; // Copy to help static analysis + if (!empty($photo)) { + if (dolIsAllowedForPreview($photo)) { if ((string) $imagesize == 'mini') { - $file = get_exdir(0, 0, 0, 0, $object, 'contact') . 'photos/' . getImageFileNameForSize($object->photo, '_mini'); + $file = get_exdir(0, 0, 0, 0, $object, 'contact') . 'photos/' . getImageFileNameForSize($photo, '_mini'); } elseif ((string) $imagesize == 'small') { - $file = get_exdir(0, 0, 0, 0, $object, 'contact') . 'photos/' . getImageFileNameForSize($object->photo, '_small'); + $file = get_exdir(0, 0, 0, 0, $object, 'contact') . 'photos/' . getImageFileNameForSize($photo, '_small'); } else { - $file = get_exdir(0, 0, 0, 0, $object, 'contact') . 'photos/' . $object->photo; + $file = get_exdir(0, 0, 0, 0, $object, 'contact') . 'photos/' . $photo; } - $originalfile = get_exdir(0, 0, 0, 0, $object, 'contact') . 'photos/' . $object->photo; + $originalfile = get_exdir(0, 0, 0, 0, $object, 'contact') . 'photos/' . $photo; } } $email = $object->email; $capture = 'user'; } elseif ($modulepart == 'userphoto') { $dir = $conf->user->dir_output; - if (!empty($object->photo)) { - if (dolIsAllowedForPreview($object->photo)) { + $photo = $object->photo; // Copy to help static analysis + if (!empty($photo)) { + if (dolIsAllowedForPreview($photo)) { if ((string) $imagesize == 'mini') { - $file = get_exdir(0, 0, 0, 0, $object, 'user') . 'photos/' . getImageFileNameForSize($object->photo, '_mini'); + $file = get_exdir(0, 0, 0, 0, $object, 'user') . 'photos/' . getImageFileNameForSize($photo, '_mini'); } elseif ((string) $imagesize == 'small') { - $file = get_exdir(0, 0, 0, 0, $object, 'user') . 'photos/' . getImageFileNameForSize($object->photo, '_small'); + $file = get_exdir(0, 0, 0, 0, $object, 'user') . 'photos/' . getImageFileNameForSize($photo, '_small'); } else { - $file = get_exdir(0, 0, 0, 0, $object, 'user') . 'photos/' . $object->photo; + $file = get_exdir(0, 0, 0, 0, $object, 'user') . 'photos/' . $photo; } - $originalfile = get_exdir(0, 0, 0, 0, $object, 'user') . 'photos/' . $object->photo; + $originalfile = get_exdir(0, 0, 0, 0, $object, 'user') . 'photos/' . $photo; } } if (getDolGlobalString('MAIN_OLD_IMAGE_LINKS')) { @@ -11090,16 +11093,17 @@ class Form $capture = 'user'; } elseif ($modulepart == 'memberphoto') { $dir = $conf->adherent->dir_output; - if (!empty($object->photo)) { - if (dolIsAllowedForPreview($object->photo)) { + $photo = $object->photo; // Copy to help static analysis + if (!empty($photo)) { + if (dolIsAllowedForPreview($photo)) { if ((string) $imagesize == 'mini') { - $file = get_exdir(0, 0, 0, 0, $object, 'member') . 'photos/' . getImageFileNameForSize($object->photo, '_mini'); + $file = get_exdir(0, 0, 0, 0, $object, 'member') . 'photos/' . getImageFileNameForSize($photo, '_mini'); } elseif ((string) $imagesize == 'small') { - $file = get_exdir(0, 0, 0, 0, $object, 'member') . 'photos/' . getImageFileNameForSize($object->photo, '_small'); + $file = get_exdir(0, 0, 0, 0, $object, 'member') . 'photos/' . getImageFileNameForSize($photo, '_small'); } else { - $file = get_exdir(0, 0, 0, 0, $object, 'member') . 'photos/' . $object->photo; + $file = get_exdir(0, 0, 0, 0, $object, 'member') . 'photos/' . $photo; } - $originalfile = get_exdir(0, 0, 0, 0, $object, 'member') . 'photos/' . $object->photo; + $originalfile = get_exdir(0, 0, 0, 0, $object, 'member') . 'photos/' . $photo; } } if (getDolGlobalString('MAIN_OLD_IMAGE_LINKS')) { diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 6c2d6f13dc1..c51191cbfa6 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -3474,7 +3474,7 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi $object->totaldeposits = $object->getSumDepositsUsed(0); $object->alreadypaid = $object->totalpaid + $object->totalcreditnotes + $object->totaldeposits; } - $tmptxt = $object->getLibStatut(6, $object->alreadypaid); + $tmptxt = $object->getLibStatut(6, (float) $object->alreadypaid); if (empty($tmptxt) || $tmptxt == $object->getLibStatut(3)) { $tmptxt = $object->getLibStatut(5, (float) $object->alreadypaid); } @@ -3857,12 +3857,11 @@ function dol_print_date($time, $format = '', $tzoutput = 'auto', $outputlangs = // Analyze date $reg = array(); if (preg_match('/^([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])([0-9][0-9])$/i', (string) $time, $reg)) { // Deprecated. Ex: 1970-01-01, 1970-01-01 01:00:00, 19700101010000 - dol_print_error(null, "Functions.lib::dol_print_date function called with a bad value from page " . (empty($_SERVER["PHP_SELF"]) ? 'unknown' : $_SERVER["PHP_SELF"])); + dol_print_error(null, "Functions.lib::dol_print_date function called with a bad value" . getCallerInfoString()); return ''; } elseif (preg_match('/^([0-9]+)\-([0-9]+)\-([0-9]+) ?([0-9]+)?:?([0-9]+)?:?([0-9]+)?/i', (string) $time, $reg)) { // Still available to solve problems in extrafields of type date // This part of code should not be used anymore. - dol_syslog("Functions.lib::dol_print_date function called with a bad value from page " . (empty($_SERVER["PHP_SELF"]) ? 'unknown' : $_SERVER["PHP_SELF"]), LOG_WARNING); - //if (function_exists('debug_print_backtrace')) debug_print_backtrace(); + dol_syslog("Functions.lib::dol_print_date function called with a bad value" . getCallerInfoString(), LOG_WARNING); // Date has format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS' $syear = (!empty($reg[1]) ? $reg[1] : ''); $smonth = (!empty($reg[2]) ? $reg[2] : ''); @@ -5220,7 +5219,7 @@ function dolGetFirstLetters($s, $nbofchar = 1) /** * Make a strlen call. Works even if mbstring module not enabled * - * @param string $string String to calculate length + * @param ?string $string String to calculate length * @param string $stringencoding Encoding of string * @return int Length of string */ @@ -7051,7 +7050,7 @@ function load_fiche_titre($title, $morehtmlright = '', $picto = 'generic', $pict $return .= '
'; // margin bottom must be same than into print_barre_list $return .= ''; if ($picto) { - $return .= ''; + $return .= ''; } $return .= ' - @@ -844,7 +846,7 @@ if (!empty($usemargins) && $user->hasRight('margins', 'creer')) { } } }); - /* When changing predefined product, we reload list of supplier prices required for margin combo */ @@ -966,7 +968,7 @@ if (!empty($usemargins) && $user->hasRight('margins', 'creer')) { if (getDolGlobalInt('PRODUIT_AUTOFILL_DESC') == 1) { if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) { ?> var proddesc = data.desc_trans; - var proddesc = data.desc; hasRight('margins', 'creer')) { editor.setData(proddesc); } } - jQuery('#dp_desc').text(proddesc); $movement 0 = add, 1 = remove * @param string $label Label of stock movement * @param int|float $price Price to use for stock eval - * @param int|string $dlc eat-by date - * @param int|string $dluo sell-by date - * @param string $lot Lot number + * @param int|''|null $dlc eat-by date + * @param int|''|null $dluo sell-by date + * @param string|null $lot Lot number * @param string $inventorycode Inventory code * @param string $origin_element Origin element type * @param ?int $origin_id Origin id of element diff --git a/htdocs/product/class/productbatch.class.php b/htdocs/product/class/productbatch.class.php index 8f3ef7185f6..20e117907eb 100644 --- a/htdocs/product/class/productbatch.class.php +++ b/htdocs/product/class/productbatch.class.php @@ -55,7 +55,7 @@ class Productbatch extends CommonObject public $fk_product_stock; /** - * @var string batch number + * @var null|string batch number */ public $batch = ''; @@ -81,12 +81,13 @@ class Productbatch extends CommonObject public $lotid; /** - * @var int|'' + * @var int|''|null * @deprecated */ public $sellby = ''; // dlc + /** - * @var int|'' + * @var int|''|null * @deprecated */ public $eatby = ''; // dmd/dluo diff --git a/htdocs/product/stock/class/entrepot.class.php b/htdocs/product/stock/class/entrepot.class.php index d83b6a56791..6b92d2607d8 100644 --- a/htdocs/product/stock/class/entrepot.class.php +++ b/htdocs/product/stock/class/entrepot.class.php @@ -1,9 +1,9 @@ - * Copyright (C) 2004-2010 Laurent Destailleur - * Copyright (C) 2005-2008 Regis Houssin - * Copyright (C) 2011 Juanjo Menent - * Copyright (C) 2016 Francis Appels +/* Copyright (C) 2003-2006 Rodolphe Quiedeville + * Copyright (C) 2004-2010 Laurent Destailleur + * Copyright (C) 2005-2008 Regis Houssin + * Copyright (C) 2011 Juanjo Menent + * Copyright (C) 2016 Francis Appels * Copyright (C) 2019-2025 Frédéric France * Copyright (C) 2024-2025 MDW * @@ -283,12 +283,9 @@ class Entrepot extends CommonObject $id = $this->db->last_insert_id($this->db->prefix()."entrepot"); if ($id > 0) { $this->id = $id; - - if (!$error) { - $result = $this->update($id, $user); - if ($result <= 0) { - $error++; - } + $result = $this->update($id, $user); + if ($result <= 0) { + $error++; } // Actions on extra fields @@ -449,7 +446,7 @@ class Entrepot extends CommonObject $this->db->begin(); - if (!$error && empty($notrigger)) { + if (empty($notrigger)) { // Call trigger $result = $this->call_trigger('WAREHOUSE_DELETE', $user); if ($result < 0) { @@ -484,7 +481,7 @@ class Entrepot extends CommonObject } } - // Removed extrafields + // Remove extrafields if (!$error) { $result = $this->deleteExtraFields(); if ($result < 0) { @@ -1002,9 +999,7 @@ class Entrepot extends CommonObject { // phpcs:enable - $sql = "SELECT rowid - FROM ".$this->db->prefix()."entrepot - WHERE fk_parent = ".((int) $id); + $sql = "SELECT rowid FROM ".$this->db->prefix()."entrepot WHERE fk_parent = ".((int) $id); $resql = $this->db->query($sql); if ($resql) { @@ -1084,11 +1079,11 @@ class Entrepot extends CommonObject $return .= img_picto('', $this->picto); $return .= ''; $return .= '
'; - $return .= ''.(method_exists($this, 'getNomUrl') ? $this->getNomUrl() : $this->ref).''; + $return .= '' . $this->getNomUrl() . ''; if ($selected >= 0) { $return .= ''; } - if (property_exists($this, 'lieu') && (!empty($this->lieu))) { + if (!empty($this->lieu)) { $return .= '
'.$this->lieu.''; } if ($arraydata['sellvalue'] != 0) { @@ -1098,9 +1093,7 @@ class Entrepot extends CommonObject $return .= '
'.price($arraydata['sellvalue']).''; } } - if (method_exists($this, 'getLibStatut')) { - $return .= '
'.$this->getLibStatut(3).'
'; - } + $return .= '
'.$this->getLibStatut(3).'
'; $return .= '
'; $return .= ''; $return .= ''; diff --git a/htdocs/product/stock/class/mouvementstock.class.php b/htdocs/product/stock/class/mouvementstock.class.php index 33041df8645..4572ab7380f 100644 --- a/htdocs/product/stock/class/mouvementstock.class.php +++ b/htdocs/product/stock/class/mouvementstock.class.php @@ -211,7 +211,7 @@ class MouvementStock extends CommonObject * @param int|string $datem Force date of movement * @param int|'' $eatby eat-by date. Will be used if lot does not exists yet and will be created. * @param int|'' $sellby sell-by date. Will be used if lot does not exists yet and will be created. - * @param string $batch batch number + * @param string|null $batch batch number * @param bool $skip_batch If set to true, stock movement is done without impacting batch record * @param int $id_product_batch Id product_batch (when skip_batch is false and we already know which record of product_batch table to use) * @param int<0,1> $disablestockchangeforsubproduct Disable stock change for sub-products of kit (useful only if product is a kit) @@ -362,8 +362,7 @@ class MouvementStock extends CommonObject $num = $this->db->num_rows($resql); $i = 0; if ($num > 0) { - while ($i < $num) { - $obj = $this->db->fetch_object($resql); + while ($i < $num && $obj = $this->db->fetch_object($resql)) { if ($obj->eatby) { if ($eatby) { $tmparray = dol_getdate((int) $eatby, true); @@ -386,8 +385,7 @@ class MouvementStock extends CommonObject $productlot->eatby = $eatby; $result = $productlot->update($user); if ($result <= 0) { - $this->error = $productlot->error; - $this->errors = $productlot->errors; + $this->setErrorsFromObject($productlot); $this->db->rollback(); return -5; } @@ -414,8 +412,7 @@ class MouvementStock extends CommonObject $productlot->sellby = $sellby; $result = $productlot->update($user); if ($result <= 0) { - $this->error = $productlot->error; - $this->errors = $productlot->errors; + $this->setErrorsFromObject($productlot); $this->db->rollback(); return -5; } @@ -436,8 +433,7 @@ class MouvementStock extends CommonObject $productlot->sellby = $sellby; $result = $productlot->create($user); if ($result <= 0) { - $this->error = $productlot->error; - $this->errors = $productlot->errors; + $this->setErrorsFromObject($productlot); $this->db->rollback(); return -4; } @@ -475,8 +471,8 @@ class MouvementStock extends CommonObject $tmpwarehouse = new Entrepot($this->db); $tmpwarehouse->fetch($entrepot_id); - $this->error = $langs->trans('qtyToTranferLotIsNotEnough', $product->ref, $batch, $qtyisnotenough, $tmpwarehouse->ref); - $this->errors[] = $langs->trans('qtyToTranferLotIsNotEnough', $product->ref, $batch, $qtyisnotenough, $tmpwarehouse->ref); + $this->error = $langs->trans('qtyToTranferLotIsNotEnough', $product->ref, (string) $batch, $qtyisnotenough, $tmpwarehouse->ref); + $this->errors[] = $langs->trans('qtyToTranferLotIsNotEnough', $product->ref, (string) $batch, $qtyisnotenough, $tmpwarehouse->ref); $this->db->rollback(); return -8; } @@ -513,7 +509,7 @@ class MouvementStock extends CommonObject $sql .= " fk_entrepot, value, type_mouvement, fk_user_author, label, inventorycode, price, fk_origin, origintype, fk_projet"; $sql .= ")"; $sql .= " VALUES ('".$this->db->idate($this->datem)."', ".((int) $this->product_id).", "; - $sql .= " ".($batch ? "'".$this->db->escape($batch)."'" : "null").", "; + $sql .= " ".(isset($batch) ? "'".$this->db->escape($batch)."'" : "null").", "; $sql .= " ".($eatby ? "'".$this->db->idate($eatby)."'" : "null").", "; $sql .= " ".($sellby ? "'".$this->db->idate($sellby)."'" : "null").", "; $sql .= " ".((int) $this->entrepot_id).", ".((float) $this->qty).", ".((int) $this->type).","; @@ -621,11 +617,11 @@ class MouvementStock extends CommonObject if ($id_product_batch > 0) { $result = $this->createBatch($id_product_batch, $qty); if ($result == -2 && $fk_product_stock > 0) { // The entry for this product batch does not exists anymore, bu we already have a llx_product_stock, so we recreate the batch entry in product_batch - $param_batch = array('fk_product_stock' => $fk_product_stock, 'batchnumber' => $batch); + $param_batch = array('fk_product_stock' => $fk_product_stock, 'batchnumber' => (string) $batch); $result = $this->createBatch($param_batch, $qty); } } else { - $param_batch = array('fk_product_stock' => $fk_product_stock, 'batchnumber' => $batch); + $param_batch = array('fk_product_stock' => $fk_product_stock, 'batchnumber' => (string) $batch); $result = $this->createBatch($param_batch, $qty); } if ($result < 0) { @@ -678,9 +674,9 @@ class MouvementStock extends CommonObject // Check unicity for serial numbered equipment once all movement were done. if (!$error && isModEnabled('productbatch') && $product->hasbatch() && !$skip_batch) { if ($product->status_batch == 2 && $qty > 0) { // We check only if we increased qty - if ($this->getBatchCount($fk_product, $batch) > 1) { + if ($this->getBatchCount($fk_product, (string) $batch) > 1) { $error++; - $this->errors[] = $langs->trans("TooManyQtyForSerialNumber", $product->ref, $batch); + $this->errors[] = $langs->trans("TooManyQtyForSerialNumber", $product->ref, (string) $batch); } } } @@ -984,8 +980,7 @@ class MouvementStock extends CommonObject $result = $pdluo->create($user, 1); if ($result < 0) { - $this->error = $pdluo->error; - $this->errors = $pdluo->errors; + $this->setErrorsFromObject($pdluo); } } } diff --git a/htdocs/product/stock/class/productlot.class.php b/htdocs/product/stock/class/productlot.class.php index 2f4d9d30626..f51eec1c97d 100644 --- a/htdocs/product/stock/class/productlot.class.php +++ b/htdocs/product/stock/class/productlot.class.php @@ -174,32 +174,32 @@ class Productlot extends CommonObject public $fk_product; /** - * @var string batch ref + * @var ?string batch ref */ public $batch; /** - * @var int|string eatby + * @var int|''|null eatby */ public $eatby = ''; /** - * @var int|string sellby + * @var int|''|null sellby */ public $sellby = ''; /** - * @var int|'' eol_date + * @var int|''|null eol_date */ public $eol_date = ''; /** - * @var int|'' manufacturing_date + * @var int|''|null manufacturing_date */ public $manufacturing_date = ''; /** - * @var int|'' scrapping_date + * @var int|''|null scrapping_date */ public $scrapping_date = ''; //public $commissionning_date = ''; @@ -217,17 +217,17 @@ class Productlot extends CommonObject public $datec = ''; /** - * @var int user ID + * @var int|null user ID */ public $fk_user_creat; /** - * @var int user ID + * @var int|null user ID */ public $fk_user_modif; /** - * @var string import key + * @var null|string import key */ public $import_key; diff --git a/htdocs/product/stock/class/productstockentrepot.class.php b/htdocs/product/stock/class/productstockentrepot.class.php index df9df57846a..dec70ffccb7 100644 --- a/htdocs/product/stock/class/productstockentrepot.class.php +++ b/htdocs/product/stock/class/productstockentrepot.class.php @@ -3,7 +3,7 @@ * Copyright (C) 2014-2016 Juanjo Menent * Copyright (C) 2015 Florian Henry * Copyright (C) 2015 Raphaël Doursenaud - * Copyright (C) 2018-2024 Frédéric France + * Copyright (C) 2018-2025 Frédéric France * Copyright (C) 2024 MDW * * This program is free software; you can redistribute it and/or modify @@ -68,7 +68,7 @@ class ProductStockEntrepot extends CommonObject */ public $desiredstock; /** - * @var string + * @var null|string */ public $import_key;
' . img_picto('', $picto, 'class="valignmiddle pictotitle'.($morecssonpicto ? ' '.$morecssonpicto: '').'"', $pictoisfullpath) . '' . img_picto('', $picto, 'class="valignmiddle pictotitle'.($morecssonpicto ? ' '.$morecssonpicto : '').'"', $pictoisfullpath) . ''; $return .= '
'; @@ -10363,7 +10362,8 @@ function getCommonSubstitutionArray($outputlangs, $onlykey = 0, $exclude = null, $liste_factures[] = ' - '.$outputlangs->trans('Invoice').' '. $objp->ref.' '.$outputlangs->trans('AmountPayed').' '.price($objp->multicurrency_amount, 0, $outputlangs, 0, -1, -1, $objp->multicurrency_code); } } - $substitutionarray['__SUPPLIER_PAYMENT_INVOICES_LIST__'] = implode("\n", $liste_factures);; + $substitutionarray['__SUPPLIER_PAYMENT_INVOICES_LIST__'] = implode("\n", $liste_factures); + ; $substitutionarray['__SUPPLIER_PAYMENT_INVOICES_TOTAL__'] = price($object->multicurrency_amount, 0, $outputlangs, 0, -1, -1, $object->multicurrency_code ? $object->multicurrency_code : $conf->currency); } if (is_object($object) && $object->element == 'shipping') { @@ -11204,6 +11204,7 @@ function dol_sort_array(&$array, $index, $order = 'asc', $natsort = 0, $case_sen // Add other keys if (!empty($tmpmultikey[1])) { $newindex = $tmpmultikey[1]; + // @phan-suppress-next-line PhanTypeArraySuspicious,PhanTypeMismatchDimFetch $temp[$key] .= '__' . (empty($array[$key][$newindex]) ? 0 : $array[$key][$newindex]); } } @@ -11244,8 +11245,8 @@ function dol_sort_array(&$array, $index, $order = 'asc', $natsort = 0, $case_sen /** * Check if a string is in UTF8. Seems similar to utf8_valid() but in pure PHP. * - * @param string $str String to check - * @return boolean True if string is UTF8 or ISO compatible with UTF8, False if not (ISO with special non utf8 char or Binary) + * @param null|string|int $str String to check + * @return boolean True if string is UTF8 or ISO compatible with UTF8, False if not (ISO with special non utf8 char or Binary) * @see utf8_valid() */ function utf8_check($str) @@ -11499,14 +11500,14 @@ function dol_eval_new($s) { // Only this global variables can be read by eval function and returned to caller global $conf, // Read of const is done with getDolGlobalString() but we need $conf->currency for example - $db, $langs, $user, $website, $websitepage, - $action, $mainmenu, $leftmenu, - $mysoc, - $objectoffield, // To allow the use of $objectoffield in computed fields + $db, $langs, $user, $website, $websitepage, + $action, $mainmenu, $leftmenu, + $mysoc, + $objectoffield, // To allow the use of $objectoffield in computed fields - // Old variables used - $object, - $obj; // To get $obj used into list when dol_eval() is used for computed fields and $obj is not yet $object + // Old variables used + $object, + $obj; // To get $obj used into list when dol_eval() is used for computed fields and $obj is not yet $object // PHP < 7.4.0 defined('T_COALESCE_EQUAL') || define('T_COALESCE_EQUAL', PHP_INT_MAX); @@ -14188,7 +14189,6 @@ function dolGetButtonAction($label, $text = '', $actionType = 'default', $url = * * @return array An array where each key corresponds to the attribute name * and each value is a full `key="escaped_value"` string ready for HTML output. - * */ function commonHtmlAttributeBuilder($attr, array $unescapedAttr = []) { @@ -14200,7 +14200,9 @@ function commonHtmlAttributeBuilder($attr, array $unescapedAttr = []) foreach ($attr as $key => $value) { // special boolean attributes case if (in_array($key, getListOfHtmlBooleanAttributes())) { - if ($value) { $TCompiledAttr[$key] = $key; } + if ($value) { + $TCompiledAttr[$key] = $key; + } continue; } diff --git a/htdocs/core/modules/reception/doc/pdf_squille.modules.php b/htdocs/core/modules/reception/doc/pdf_squille.modules.php index ccf9ec0d249..6e6598fde27 100644 --- a/htdocs/core/modules/reception/doc/pdf_squille.modules.php +++ b/htdocs/core/modules/reception/doc/pdf_squille.modules.php @@ -1005,7 +1005,7 @@ class pdf_squille extends ModelePdfReception //$linkedobject->fetchObjectLinked() Get all linked object to the $linkedobject (commonly order) into $linkedobject->linkedObjects $pdf->SetFont('', '', $default_font_size - 2); - $text = $linkedobject->ref; + $text = (string) $linkedobject->ref; if (isset($linkedobject->ref_client) && !empty($linkedobject->ref_client)) { $text .= ' ('.$linkedobject->ref_client.')'; } diff --git a/htdocs/core/tpl/objectline_create.tpl.php b/htdocs/core/tpl/objectline_create.tpl.php index 754ab869a0e..61ee39a88d5 100644 --- a/htdocs/core/tpl/objectline_create.tpl.php +++ b/htdocs/core/tpl/objectline_create.tpl.php @@ -59,6 +59,8 @@ if (empty($object) || !is_object($object)) { ' @phan-var-force CommonObject|Facture $this @phan-var-force CommonObject $object +@phan-var-force CommonObjectLine $line +@phan-var-force ExtraFields $extrafields @phan-var-force Societe $buyer @phan-var-force Societe $seller @phan-var-force int<0,1> $usehm @@ -514,7 +516,7 @@ if ($nolinesbefore) {
">