From 2fc7ee79181942395717c71779c9c73fef1aa8ed Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Fri, 5 Dec 2025 11:31:13 +0100 Subject: [PATCH 1/2] Add types --- src/CommonITILTask.php | 1 - src/Glpi/Features/PlanningEvent.php | 14 ++-- src/Group_User.php | 2 +- src/LevelAgreementLevel.php | 6 -- src/RSSFeed.php | 4 +- src/RSSFeed_User.php | 8 +- src/Reminder.php | 16 +++- src/Reminder_User.php | 8 +- src/Report.php | 13 ++- src/RequestType.php | 4 +- src/Reservation.php | 17 +++- src/ReservationItem.php | 12 ++- src/Rule.php | 5 ++ src/SLA.php | 12 ++- src/SNMPCredential.php | 5 +- src/SavedSearch.php | 5 ++ src/SavedSearch_Alert.php | 11 ++- src/Search.php | 14 +++- src/Session.php | 15 ++-- src/SingletonRuleList.php | 5 +- src/SlaLevel.php | 6 +- src/SlaLevel_Ticket.php | 4 +- src/Stat.php | 26 +++++- src/State.php | 7 +- src/Supplier.php | 6 +- src/TaskTemplate.php | 12 ++- src/Telemetry.php | 5 ++ src/Ticket.php | 122 +++++++++++++++++++--------- src/Timer.php | 5 +- src/Toolbox.php | 53 ++++++------ src/Update.php | 12 ++- src/User.php | 36 ++++++-- src/UserEmail.php | 12 +-- src/Webhook.php | 18 +++- src/XHProf.php | 13 ++- 35 files changed, 367 insertions(+), 147 deletions(-) diff --git a/src/CommonITILTask.php b/src/CommonITILTask.php index 1e8e2bbbdf2..38cdde7920a 100644 --- a/src/CommonITILTask.php +++ b/src/CommonITILTask.php @@ -1539,7 +1539,6 @@ public static function genericPopulatePlanning($itemtype, $options = []) $interv[$key]["device"] = []; if ( $parentitem instanceof Ticket - && isset($parentitem->hardwaredatas) && !empty($parentitem->hardwaredatas) ) { foreach ($parentitem->hardwaredatas as $hardwaredata) { diff --git a/src/Glpi/Features/PlanningEvent.php b/src/Glpi/Features/PlanningEvent.php index 94e10f92be2..6408184d134 100644 --- a/src/Glpi/Features/PlanningEvent.php +++ b/src/Glpi/Features/PlanningEvent.php @@ -681,15 +681,15 @@ public static function populatePlanning($options = []): array * Generate the html code to display a Planning Item. * Note: despite its name, this method do not display anything by itself. * - * @param $val array of the item to display - * @param $who ID of the user (0 if all) - * @param $type position of the item in the time block (in, through, begin or end) - * default '') - * @param $complete complete display (more details) (default 0) + * @param array $val array of the item to display + * @param int $who ID of the user (0 if all) + * @param string $type position of the item in the time block (in, through, begin or end) + * default '') + * @param bool $complete complete display (more details) (default false) * * @return string - **/ - public static function displayPlanningItem(array $val, $who, $type = "", $complete = 0) + */ + public static function displayPlanningItem(array $val, $who, $type = "", $complete = false) { global $CFG_GLPI; diff --git a/src/Group_User.php b/src/Group_User.php index 496a0244028..77a4c9d1abd 100644 --- a/src/Group_User.php +++ b/src/Group_User.php @@ -249,7 +249,7 @@ public static function showForUser(User $user) */ private static function showAddUserForm(Group $group, array $used_ids, int|array $entityrestrict): void { - $res = User::getSqlSearchResult(true, "all", $entityrestrict, 0, $used_ids, '', 0, -1, false, 1); + $res = User::getSqlSearchResult(true, "all", $entityrestrict, 0, $used_ids, '', 0, -1, false, true); $nb = count($res); if ($nb) { $group_user = new self(); diff --git a/src/LevelAgreementLevel.php b/src/LevelAgreementLevel.php index 5e27c495414..0f3b8853662 100644 --- a/src/LevelAgreementLevel.php +++ b/src/LevelAgreementLevel.php @@ -74,18 +74,12 @@ public function __construct() */ abstract public function showForParent(LevelAgreement $la); - /** - * @since 0.85 - **/ public static function getConditionsArray() { // Override ruleticket one return []; } - /** - * @since 0.84 - **/ public function getForbiddenStandardMassiveAction() { $forbidden = parent::getForbiddenStandardMassiveAction(); diff --git a/src/RSSFeed.php b/src/RSSFeed.php index 753ba9eb639..1cf31ed0087 100644 --- a/src/RSSFeed.php +++ b/src/RSSFeed.php @@ -598,7 +598,9 @@ public function showForm($ID, array $options = []) * Set error field * * @param boolean $error (false by default) - **/ + * + * @return void + */ public function setError($error = false) { if (!isset($this->fields['id']) && !isset($this->fields['have_error'])) { diff --git a/src/RSSFeed_User.php b/src/RSSFeed_User.php index 5caee75133d..b30babfc29c 100644 --- a/src/RSSFeed_User.php +++ b/src/RSSFeed_User.php @@ -38,9 +38,9 @@ class RSSFeed_User extends CommonDBRelation { // From CommonDBRelation - public static $itemtype_1 = 'RSSFeed'; + public static $itemtype_1 = RSSFeed::class; public static $items_id_1 = 'rssfeeds_id'; - public static $itemtype_2 = 'User'; + public static $itemtype_2 = User::class; public static $items_id_2 = 'users_id'; public static $checkItem_2_Rights = self::DONT_CHECK_ITEM_RIGHTS; @@ -50,10 +50,10 @@ class RSSFeed_User extends CommonDBRelation /** * Get users for a rssfeed * - * @param $rssfeeds_id ID of the rssfeed + * @param int $rssfeeds_id ID of the rssfeed * * @return array of users linked to a rssfeed - **/ + */ public static function getUsers($rssfeeds_id) { global $DB; diff --git a/src/Reminder.php b/src/Reminder.php index 00027239632..ca17e0fa832 100644 --- a/src/Reminder.php +++ b/src/Reminder.php @@ -60,6 +60,7 @@ class Reminder extends CommonDBVisible implements // From CommonDBTM public $dohistory = true; + /** @var bool */ public $can_be_translated = true; public static $rightname = 'reminder_public'; @@ -153,6 +154,11 @@ public function cleanDBonPurge() ); } + /** + * @param array $input + * + * @return array + */ public function prepareInputForClone($input) { // regenerate uuid @@ -546,7 +552,15 @@ public function showForm($ID, array $options = []) return true; } - public static function displayPlanningItem(array $val, $who, $type = "", $complete = 0) + /** + * @param array $val + * @param int $who + * @param string $type + * @param bool $complete + * + * @return string + */ + public static function displayPlanningItem(array $val, $who, $type = "", $complete = false) { global $CFG_GLPI; diff --git a/src/Reminder_User.php b/src/Reminder_User.php index 7eb12e21ed6..beaea270ad8 100644 --- a/src/Reminder_User.php +++ b/src/Reminder_User.php @@ -38,9 +38,9 @@ class Reminder_User extends CommonDBRelation { // From CommonDBRelation - public static $itemtype_1 = 'Reminder'; + public static $itemtype_1 = Reminder::class; public static $items_id_1 = 'reminders_id'; - public static $itemtype_2 = 'User'; + public static $itemtype_2 = User::class; public static $items_id_2 = 'users_id'; public static $checkItem_2_Rights = self::DONT_CHECK_ITEM_RIGHTS; @@ -50,10 +50,10 @@ class Reminder_User extends CommonDBRelation /** * Get users for a reminder * - * @param $reminders_id ID of the reminder + * @param int $reminders_id ID of the reminder * * @return array of users linked to a reminder - **/ + */ public static function getUsers($reminders_id) { global $DB; diff --git a/src/Report.php b/src/Report.php index 09f801bfa04..22ecb6f181a 100644 --- a/src/Report.php +++ b/src/Report.php @@ -51,6 +51,7 @@ **/ class Report extends CommonGLPI { + /** @var bool */ protected static $notable = false; public static $rightname = 'reports'; @@ -131,7 +132,9 @@ public static function getReports(): array /** * Show report selector which always appears on the top of the report pages - **/ + * + * @return void + */ public static function title() { $twig_params = [ @@ -1896,11 +1899,19 @@ public static function showOtherInfocomReport(?string $begin, ?string $end): voi TWIG, $twig_params); } + /** + * @param string $interface + * + * @return array + */ public function getRights($interface = 'central') { return [ READ => __('Read')]; } + /** + * @return string + */ public static function getIcon() { return "ti ti-report"; diff --git a/src/RequestType.php b/src/RequestType.php index 20aebd51fec..ce7a87bc456 100644 --- a/src/RequestType.php +++ b/src/RequestType.php @@ -234,10 +234,10 @@ public function post_updateItem($history = true) /** * Get the default request type for a given source (mail, helpdesk) * - * @param $source string + * @param string $source * * @return integer requesttypes_id - **/ + */ public static function getDefault($source) { global $DB; diff --git a/src/Reservation.php b/src/Reservation.php index e3530282319..708fd627c00 100644 --- a/src/Reservation.php +++ b/src/Reservation.php @@ -295,7 +295,9 @@ public function post_addItem() /** * Returns an integer that is not already used as a group for the given reservation item. - * @param $reservationitems_id + * + * @param int $reservationitems_id + * * @return int */ public function getUniqueGroupFor($reservationitems_id): int @@ -511,13 +513,15 @@ public function post_purgeItem() * Show reservation calendar * * @param integer $ID ID of the reservation item (if 0 display all) - **/ + * + * @return void + */ public static function showCalendar(int $ID = 0) { global $CFG_GLPI; if (!Session::haveRightsOr("reservation", [READ, ReservationItem::RESERVEANITEM])) { - return false; + return; } $rand = mt_rand(); @@ -531,7 +535,7 @@ public static function showCalendar(int $ID = 0) echo __s('Device temporarily unavailable'); Html::displayBackLink(); echo ""; - return false; + return; } $type = $m->fields["itemtype"]; $name = NOT_AVAILABLE; @@ -696,6 +700,9 @@ public static function getEvents(array $params): array return $events; } + /** + * @return array + */ public static function getResources() { global $DB; @@ -873,6 +880,8 @@ public function showForm($ID, array $options = []) * @param string $begin Planning start (should be an ISO_8601 date, but could be anything that can be parsed by strtotime) * @param string $end Planning end (should be an ISO_8601 date, but could be anything that can be parsed by strtotime) * @param array{type: 'day'|'week'|'month', end: string, subtype?: string, days?: integer} $options Periodicity parameters + * + * @return array **/ public static function computePeriodicities($begin, $end, $options) { diff --git a/src/ReservationItem.php b/src/ReservationItem.php index 1ac66c4dbf5..94130c8485a 100644 --- a/src/ReservationItem.php +++ b/src/ReservationItem.php @@ -268,6 +268,11 @@ public function rawSearchOptions() return $tab; } + /** + * @param class-string $itemtype + * + * @return array + */ public static function rawSearchOptionsToAdd($itemtype = null) { return [ @@ -381,12 +386,15 @@ public function showForm($ID, array $options = []) return false; } + /** + * @return void + */ public static function showListSimple() { global $CFG_GLPI, $DB; if (!Session::haveRightsOr(self::$rightname, [READ, self::RESERVEANITEM])) { - return false; + return; } $ok = false; @@ -687,7 +695,7 @@ public static function showListSimple() } /** - * @param $name + * @param string $name * * @return array * @used-by CronTask diff --git a/src/Rule.php b/src/Rule.php index dd21a327601..3de2849b058 100644 --- a/src/Rule.php +++ b/src/Rule.php @@ -3419,6 +3419,11 @@ public static function getIcon() return "ti ti-book"; } + /** + * @param array $input + * + * @return array + */ public function prepareInputForClone($input) { // get ranking diff --git a/src/SLA.php b/src/SLA.php index e504332020a..8bbbbd7bf19 100644 --- a/src/SLA.php +++ b/src/SLA.php @@ -43,11 +43,17 @@ **/ class SLA extends LevelAgreement { + /** + * @var string + */ protected static $prefix = 'sla'; + /** + * @var string + */ protected static $prefixticket = ''; - protected static $levelclass = 'SlaLevel'; - protected static $levelticketclass = 'SlaLevel_Ticket'; - protected static $forward_entity_to = ['SlaLevel']; + protected static $levelclass = SlaLevel::class; + protected static $levelticketclass = SlaLevel_Ticket::class; + protected static $forward_entity_to = [SlaLevel::class]; public static function getTypeName($nb = 0) { diff --git a/src/SNMPCredential.php b/src/SNMPCredential.php index 7b94b1bb1e7..0166c9425ab 100644 --- a/src/SNMPCredential.php +++ b/src/SNMPCredential.php @@ -55,6 +55,9 @@ public static function getSectorizedDetails(): array return ['admin', Inventory::class, self::class]; } + /** + * @return array + */ public static function rawSearchOptionsToAdd() { $tab = []; @@ -223,7 +226,7 @@ protected function prepareInputs(array $input): array return $input; } - private function checkRequiredFields($input): bool + private function checkRequiredFields(array $input): bool { // Require a snmpversion if (!isset($input['snmpversion']) || $input['snmpversion'] == '0') { diff --git a/src/SavedSearch.php b/src/SavedSearch.php index 8a5be013763..90c5bbbd12d 100644 --- a/src/SavedSearch.php +++ b/src/SavedSearch.php @@ -1006,6 +1006,11 @@ public function setEntityRecur(array $ids, $eid, $recur) return $result; } + /** + * @param string $name + * + * @return array + */ public static function cronInfo($name) { switch ($name) { diff --git a/src/SavedSearch_Alert.php b/src/SavedSearch_Alert.php index 37ef279457e..b4b59461905 100644 --- a/src/SavedSearch_Alert.php +++ b/src/SavedSearch_Alert.php @@ -259,6 +259,11 @@ public static function getOperators($id = null) return ($id === null ? $ops : $ops[$id]); } + /** + * @param string $name + * + * @return array + */ public static function cronInfo($name) { switch ($name) { @@ -275,7 +280,7 @@ public static function cronInfo($name) * * @return array[] which contains a copy of $_SESSION and $CFG_GLPI */ - private static function saveContext() + private static function saveContext(): array { global $CFG_GLPI; $context = []; @@ -291,9 +296,9 @@ private static function saveContext() * to be sure that logs will be in GLPI default datetime and language * and that session is restored for the next crontaskaction * - * @param mixed $context is the array returned by saveContext + * @param array $context is the array returned by saveContext */ - private static function restoreContext($context) + private static function restoreContext(array $context): void { global $CFG_GLPI; $_SESSION = $context['$_SESSION']; diff --git a/src/Search.php b/src/Search.php index 8a0cc4a9064..3cbdb7ac72d 100644 --- a/src/Search.php +++ b/src/Search.php @@ -152,6 +152,9 @@ class Search * @var int */ public static $output_type = self::HTML_OUTPUT; + /** + * @var array + */ public static $search = []; /** @@ -742,9 +745,10 @@ public static function addLeftJoin( * @param string $from_type Reference item type ID * @param string $to_type Item type to add * @param array $already_link_tables2 Array of tables already joined - *showGenericSearch + * @param array $joinparams Array join parameters (condition / joinbefore...) + * * @return string Meta Left join string - **/ + */ public static function addMetaLeftJoin( $from_type, $to_type, @@ -895,7 +899,9 @@ public static function isInfocomOption($itemtype, $searchID) /** * @param string $itemtype * @param integer $field_num - **/ + * + * @return array + */ public static function getActionsFor($itemtype, $field_num) { return SearchOption::getActionsFor($itemtype, $field_num); @@ -1094,6 +1100,8 @@ public static function showEndLine($type, bool $is_header_line = false) /** * @param array $joinparams + * + * @return string */ public static function computeComplexJoinID(array $joinparams) { diff --git a/src/Session.php b/src/Session.php index 6368e136af0..72e19c6db18 100644 --- a/src/Session.php +++ b/src/Session.php @@ -359,7 +359,9 @@ public static function canViewAllEntities() * * @param string $itemtype Device type * @param integer $ID ID of the item - **/ + * + * @return void + */ public static function addToNavigateListItems($itemtype, $ID) { $_SESSION['glpilistitems'][$itemtype][] = $ID; @@ -368,9 +370,12 @@ public static function addToNavigateListItems($itemtype, $ID) /** Initialise a list of items to use navigate through search results * - * @param string $itemtype Device type - * @param string $title List title (default '') - **/ + * @param string $itemtype Device type + * @param string $title List title (default '') + * @param ?string $url + * + * @return void + */ public static function initNavigateListItems($itemtype, $title = "", $url = null) { if (Request::createFromGlobals()->isXmlHttpRequest() && $url === null) { @@ -2453,7 +2458,7 @@ public static function isRightChecksDisabled(): bool * Is locale RTL * See native PHP 8.5 function locale_is_right_to_left * - * @param $locale + * @param string $locale * * @return bool */ diff --git a/src/SingletonRuleList.php b/src/SingletonRuleList.php index 5716e35edaa..331e4adeb2a 100644 --- a/src/SingletonRuleList.php +++ b/src/SingletonRuleList.php @@ -37,7 +37,10 @@ class SingletonRuleList { /** @var Rule[] */ public $list = []; - /// Items loaded ? + /** + * Items loaded? + * @var int + */ public $load = 0; diff --git a/src/SlaLevel.php b/src/SlaLevel.php index 03bb146b385..0ba903076d2 100644 --- a/src/SlaLevel.php +++ b/src/SlaLevel.php @@ -39,11 +39,11 @@ class SlaLevel extends LevelAgreementLevel { protected $rules_id_field = 'slalevels_id'; - protected $ruleactionclass = 'SlaLevelAction'; - protected static $parentclass = 'SLA'; + protected $ruleactionclass = SlaLevelAction::class; + protected static $parentclass = SLA::class; protected static $fkparent = 'slas_id'; // No criteria - protected $rulecriteriaclass = 'SlaLevelCriteria'; + protected $rulecriteriaclass = SlaLevelCriteria::class; public static function getTable($classname = null) { diff --git a/src/SlaLevel_Ticket.php b/src/SlaLevel_Ticket.php index 64c020a2109..518f09a07ed 100644 --- a/src/SlaLevel_Ticket.php +++ b/src/SlaLevel_Ticket.php @@ -134,7 +134,7 @@ public function deleteForTicket($tickets_id, $slaType) /** * Give cron information * - * @param $name : task's name + * @param string $name task's name * * @return array of information * @used-by CronTask @@ -319,6 +319,8 @@ public static function doLevelForTicket(array $data, $slaType) * @param SLM::TTR|SLM::TTO $slaType * * @since 9.1 2 parameters mandatory + * + * @return void */ public static function replayForTicket($tickets_id, $slaType) { diff --git a/src/Stat.php b/src/Stat.php index b14825854f6..9d259741353 100644 --- a/src/Stat.php +++ b/src/Stat.php @@ -54,6 +54,9 @@ class Stat extends CommonGLPI { public static $rightname = 'statistic'; + /** + * @var array + */ public static $cache = []; public static function getTypeName($nb = 0) @@ -1601,7 +1604,9 @@ public static function getAssetsWithITIL($start_date, $end_date, $itil_type = 'T * @param string $date2 * @param integer $start * @param class-string|null $itemtype - **/ + * + * @return void + */ public static function showItems($target, $date1, $date2, $start, $itemtype = null) { $view_entities = Session::isMultiEntitiesMode(); @@ -1709,6 +1714,9 @@ public static function showItems($target, $date1, $date2, $start, $itemtype = nu } } + /** + * @return array + */ public static function getAvailableStatistics() { global $CFG_GLPI, $PLUGIN_HOOKS; @@ -1858,6 +1866,9 @@ public static function getItemCharacteristicStatFields(): array return $values; } + /** + * @return void + */ public static function title() { $values = self::getAvailableStatistics(); @@ -1879,6 +1890,11 @@ public static function title() ]); } + /** + * @param string $interface + * + * @return array + */ public function getRights($interface = 'central') { $values[READ] = __('Read'); @@ -1887,7 +1903,10 @@ public function getRights($interface = 'central') /** * Call displayLineGraph with arguments from a StatData object + * * @param StatData $stat_data + * + * @return void */ public function displayLineGraphFromData(StatData $stat_data) { @@ -2062,6 +2081,8 @@ function exportToCSV() { /** * Call displayPieGraph with arguments from a StatData object + * + * @return void */ public function displayPieGraphFromData(StatData $stat_data) { @@ -2257,6 +2278,9 @@ private function checkEmptyLabels(&$labels) } } + /** + * @return string + */ public static function getIcon() { return "ti ti-chart-pie"; diff --git a/src/State.php b/src/State.php index 6bf62221ac0..34c56fe8015 100644 --- a/src/State.php +++ b/src/State.php @@ -129,13 +129,18 @@ final public static function getBehaviours(string $lib = "", bool $is_inheritabl * @param integer $value * @param boolean $is_inheritable * @used-by templates/pages/admin/entity/assets.html.twig - **/ + * + * @return void + */ public static function dropdownBehaviour($name, $lib = "", $value = 0, $is_inheritable = false) { $elements = self::getBehaviours($lib, $is_inheritable); Dropdown::showFromArray($name, $elements, ['value' => $value]); } + /** + * @return void + */ public static function showSummary() { global $CFG_GLPI, $DB; diff --git a/src/Supplier.php b/src/Supplier.php index 872c888a5ed..30d82d44ca3 100644 --- a/src/Supplier.php +++ b/src/Supplier.php @@ -378,7 +378,9 @@ public function rawSearchOptions() * Get links for an enterprise (website / edit) * * @param boolean $withname Also display name ? (false by default) - **/ + * + * @return string + */ public function getLinks($withname = false) { $ret = $withname ? ('' . htmlescape($this->fields["name"]) . '') : ''; @@ -611,6 +613,8 @@ public function showInfocoms() * @since 9.5 * * @param string $email Also display name ? (false by default) + * + * @return DBmysqlIterator **/ public static function getSuppliersByEmail($email) { diff --git a/src/TaskTemplate.php b/src/TaskTemplate.php index 184e1858e24..67015ce5ac4 100644 --- a/src/TaskTemplate.php +++ b/src/TaskTemplate.php @@ -313,7 +313,7 @@ public function prepareInputForUpdate($input) return $input; } - private function prepareInput($input) + private function prepareInput(array|false $input): array|false { if ($input === false) { return false; @@ -339,6 +339,16 @@ public function getCloneRelations(): array return []; } + /** + * @param string $link + * @param int $nott + * @param class-string $itemtype + * @param int $ID + * @param string $searchtype + * @param int|string $val + * + * @return false|string + */ public static function addWhere($link, $nott, $itemtype, $ID, $searchtype, $val) { if ($itemtype !== self::class) { diff --git a/src/Telemetry.php b/src/Telemetry.php index 6b193a018e6..c35682a30ab 100644 --- a/src/Telemetry.php +++ b/src/Telemetry.php @@ -283,6 +283,11 @@ public static function getAverage($itemtype) return '500000+'; } + /** + * @param string $name + * + * @return array + */ public static function cronInfo($name) { switch ($name) { diff --git a/src/Ticket.php b/src/Ticket.php index f86083a5975..d70029474b1 100644 --- a/src/Ticket.php +++ b/src/Ticket.php @@ -60,15 +60,18 @@ class Ticket extends CommonITILObject implements DefaultSearchRequestInterface { // From CommonDBTM public $dohistory = true; - protected static $forward_entity_to = ['TicketValidation', 'TicketCost']; + protected static $forward_entity_to = [TicketValidation::class, TicketCost::class]; // From CommonITIL - public $userlinkclass = 'Ticket_User'; - public $grouplinkclass = 'Group_Ticket'; - public $supplierlinkclass = 'Supplier_Ticket'; + public $userlinkclass = Ticket_User::class; + public $grouplinkclass = Group_Ticket::class; + public $supplierlinkclass = Supplier_Ticket::class; public static $rightname = 'ticket'; + /** + * @var bool + */ protected $userentity_oncreate = true; public const MATRIX_FIELD = 'priority_matrix'; @@ -77,9 +80,15 @@ class Ticket extends CommonITILObject implements DefaultSearchRequestInterface public const STATUS_MATRIX_FIELD = 'ticket_status'; // Specific ones - /// Hardware datas used by getFromDBwithData + /** + * Hardware datas used by getFromDBwithData + * @var array + */ public $hardwaredatas = []; - /// Is a hardware found in getHardwareData / getFromDBwithData : hardware link to the job + /** + * Is a hardware found in getHardwareData / getFromDBwithData : hardware link to the job + * @var int + */ public $computerfound = 0; // Request type @@ -170,6 +179,12 @@ public function canAssignToMe() } + /** + * @param int $ticket_id + * @param int $user_id + * + * @return void + */ public static function assignToMe($ticket_id, $user_id) { $ticket = new Ticket(); @@ -1062,9 +1077,11 @@ public function prepareInputForUpdate($input) * * @since 9.1 * - * @param $type - * @param $input - * @param $manual_slas_id + * @param int $type + * @param array $input + * @param array $manual_slas_id + * + * @return void */ public function slaAffect($type, &$input, $manual_slas_id) { @@ -1154,9 +1171,11 @@ public function slaAffect($type, &$input, $manual_slas_id) * * @since 9.1 * - * @param $type - * @param $input - * @param $manual_olas_id + * @param int $type + * @param array $input + * @param array $manual_olas_id + * + * @return void */ public function olaAffect($type, &$input, $manual_olas_id) { @@ -1243,7 +1262,9 @@ public function olaAffect($type, &$input, $manual_olas_id) * * @since 9.1 * - * @param $slas_id + * @param int $slas_id + * + * @return void **/ public function manageSlaLevel($slas_id) { @@ -1271,8 +1292,10 @@ public function manageSlaLevel($slas_id) * * @since 9.1 * - * @param $slas_id - **/ + * @param int $slas_id + * + * @return void + */ public function manageOlaLevel($slas_id) { @@ -1326,7 +1349,9 @@ public function pre_updateInDB() /** * Compute take into account stat of the current ticket - **/ + * + * @return int + */ public function computeTakeIntoAccountDelayStat() { @@ -1350,7 +1375,7 @@ public function computeTakeIntoAccountDelayStat() return 0; } - private function handleContractInputs() + private function handleContractInputs(): void { $contracts_id = $this->input['_contracts_id'] ?? 0; if (!is_array($contracts_id)) { @@ -1798,16 +1823,14 @@ public function post_addItem() /** - * Get active or solved tickets for an hardware last X days - * - * @since 0.83 + * Get active or solved tickets for a hardware last X days * - * @param $itemtype string Item type - * @param $items_id integer ID of the Item - * @param $days integer day number + * @param class-string $itemtype Item type + * @param int $items_id ID of the Item + * @param int $days day number * * @return array - **/ + */ public function getActiveOrSolvedLastDaysTicketsForItem($itemtype, $items_id, $days) { return $this->getActiveOrSolvedLastDaysForItem($itemtype, $items_id, $days); @@ -1817,13 +1840,11 @@ public function getActiveOrSolvedLastDaysTicketsForItem($itemtype, $items_id, $d /** * Count active tickets for an hardware * - * @since 0.83 - * - * @param $itemtype string Item type - * @param $items_id integer ID of the Item + * @param class-string $itemtype Item type + * @param int $items_id ID of the Item * * @return integer - **/ + */ public function countActiveTicketsForItem($itemtype, $items_id) { global $DB; @@ -1899,16 +1920,16 @@ public function getActiveTicketsForItem($itemtype, $items_id, $type) } /** - * Count solved tickets for an hardware last X days + * Count solved tickets for a hardware last X days * * @since 0.83 * - * @param $itemtype string Item type - * @param $items_id integer ID of the Item - * @param $days integer day number + * @param class-string $itemtype Item type + * @param int $items_id ID of the Item + * @param int $days day number * * @return integer - **/ + */ public function countSolvedTicketsForItemLastDays($itemtype, $items_id, $days) { global $DB; @@ -3286,7 +3307,9 @@ public static function getTypes() * Get ticket type Name * * @param integer $value Type ID - **/ + * + * @return string|int + */ public static function getTicketTypeName($value) { @@ -3796,6 +3819,8 @@ public function showForm($ID, array $options = []) * @param string $status (default ''process) * @param boolean $showgrouptickets (true by default) * @param boolean $display set to false to return html + * + * @return void|string|false */ public static function showCentralList($start, $status = "process", bool $showgrouptickets = true, bool $display = true) { @@ -4612,7 +4637,9 @@ private static function showCentralCountCriteria(bool $foruser): array * * @param boolean $foruser Only for current login user as requester or observer (false by default) * @param boolean $display il false return html - **/ + * + * @return string|false|void + */ public static function showCentralCount(bool $foruser = false, bool $display = true) { global $CFG_GLPI, $DB; @@ -4742,12 +4769,15 @@ public static function showCentralCount(bool $foruser = false, bool $display = t } + /** + * @return void + */ public static function showCentralNewList() { global $DB; if (!Session::haveRightsOr(self::$rightname, [self::READALL, self::READNEWTICKET])) { - return false; + return; } $criteria = self::getCommonCriteria(); @@ -4840,9 +4870,11 @@ public static function showListForItem(CommonDBTM $item, $withtemplate = 0) } /** - * @param $ID - * @param $forcetab string name of the tab to force at the display (default '') - **/ + * @param int $ID + * @param string $forcetab name of the tab to force at the display (default '') + * + * @return void + */ public static function showVeryShort($ID, $forcetab = '') { // Prints a job in short form @@ -6192,6 +6224,11 @@ public function processRules(int $condition, array &$input, int $entid = -1): vo } } + /** + * @param class-string $itemtype + * + * @return array + */ public static function rawSearchOptionsToAdd($itemtype) { global $CFG_GLPI; @@ -6222,6 +6259,11 @@ public static function rawSearchOptionsToAdd($itemtype) return $options; } + /** + * @param CommonDBTM $item + * + * @return array + */ public static function getListForItemRestrict(CommonDBTM $item) { $restrict = []; diff --git a/src/Timer.php b/src/Timer.php index 5110f89acca..be042275c1f 100644 --- a/src/Timer.php +++ b/src/Timer.php @@ -39,7 +39,10 @@ */ class Timer { - //! Timer value + /** + * Timer value + * @var int|float + */ public $timer = 0; diff --git a/src/Toolbox.php b/src/Toolbox.php index f527412caed..d85e0df62fe 100644 --- a/src/Toolbox.php +++ b/src/Toolbox.php @@ -276,7 +276,7 @@ public static function strtoupper($str) /** * Is a string seems to be UTF-8 one ? * - * @param $str string string to analyse + * @param string $str string to analyse * * @return boolean * @@ -387,6 +387,8 @@ private static function log($level = LogLevel::WARNING, $args = null) /** * PHP debug log + * + * @return void */ public static function logDebug() { @@ -395,6 +397,8 @@ public static function logDebug() /** * PHP info log + * + * @return void */ public static function logInfo() { @@ -1148,8 +1152,8 @@ public static function testWriteAccessToDirectory($dir) * @param string $itemtype item type * @param boolean $full path or relative one * - * return string itemtype Form URL - **/ + * @return string itemtype Form URL + */ public static function getItemTypeFormURL($itemtype, $full = true) { global $CFG_GLPI; @@ -1176,8 +1180,8 @@ public static function getItemTypeFormURL($itemtype, $full = true) * @param string $itemtype item type * @param boolean $full path or relative one * - * return string itemtype search URL - **/ + * @return string itemtype search URL + */ public static function getItemTypeSearchURL($itemtype, $full = true) { global $CFG_GLPI; @@ -1210,8 +1214,8 @@ public static function getItemTypeSearchURL($itemtype, $full = true) * @param string $itemtype item type * @param boolean $full path or relative one * - * return string itemtype tabs URL - **/ + * @return string itemtype tabs URL + */ public static function getItemTypeTabsURL($itemtype, $full = true) { global $CFG_GLPI; @@ -1355,11 +1359,12 @@ public static function getGuzzleClient(array $extra_options = []): Client /** * Executes a curl call * - * @param string $url URL to retrieve - * @param array $eopts Extra curl opts - * @param string $msgerr will contains a human readable error string if an error occurs of url returns empty contents - * @param bool $check_url_safeness indicated whether the URL have to be filetered by safety checks - * @param array $curl_info will contains contents provided by `curl_getinfo` + * @param string $url URL to retrieve + * @param array $eopts Extra curl opts + * @param ?string $msgerr will contain a human-readable error string if an error occurs of url returns empty contents + * @param ?string $curl_error will contain curl error message if an error occurs + * @param bool $check_url_safeness indicated whether the URL have to be filtered by safety checks + * @param ?array $curl_info will contain contents provided by `curl_getinfo` * * @return string */ @@ -1402,16 +1407,17 @@ public static function callCurl( /** * Executes a curl call * - * @param string $url - * @param array $eopts - * @param string $msgerr - * @param bool $check_url_safeness - * @param array $curl_info + * @param string $url + * @param array $eopts + * @param ?string $msgerr + * @param ?string $curl_error + * @param bool $check_url_safeness + * @param ?array $curl_info * * @return string * * @throws CurlException - * @throws EmptyCurlContentException + * @throws EmptyCurlContentException|UrlException */ private static function doCallCurl( $url, @@ -1507,11 +1513,11 @@ public static function isAjax() /** - * @param $need - * @param $tab + * @param string|int $need + * @param array $tab * * @return boolean - **/ + */ public static function key_exists_deep($need, $tab) { @@ -2896,6 +2902,7 @@ public static function stripTags(string $str): string * * @param string|null $src Source path of the picture * @param string $uniq_prefix Unique prefix that can be used to improve uniqueness of destination filename + * @param boolean $keep_src Whether to keep the source file or not * * @return boolean|string Destination filepath, relative to GLPI_PICTURE_DIR, or false on failure * @@ -3270,10 +3277,10 @@ public static function hasTrait($class, string $trait): bool return false; } - /* + /** * Normalizes file name * - * @param string filename + * @param string $filename * * @return string */ diff --git a/src/Update.php b/src/Update.php index 4623e63e9ac..e4d8fb2385a 100644 --- a/src/Update.php +++ b/src/Update.php @@ -52,21 +52,19 @@ class Update { use LoggerAwareTrait; - private $DB; - private $version; - private $language; + private DBmysql $DB; + private ?string $version = null; + private string $language; /** * Directory containing migrations. - * - * @var string */ - private $migrations_directory; + private string $migrations_directory; /** * Constructor * - * @param object $DB Database instance + * @param DBmysql $DB Database instance * @param string $migrations_directory * * @since 11.0.0 The `$args` parameter has been removed. diff --git a/src/User.php b/src/User.php index ea36b379fde..d1bac40353c 100644 --- a/src/User.php +++ b/src/User.php @@ -67,6 +67,7 @@ class User extends CommonDBTM implements TreeBrowseInterface { + /** @use Clonable */ use Clonable { Clonable::computeCloneName as baseComputeCloneName; } @@ -78,7 +79,7 @@ class User extends CommonDBTM implements TreeBrowseInterface 'publicbookmarkorder', 'privatebookmarkorder', ]; - private $must_process_ruleright = false; + private bool $must_process_ruleright = false; // NAME FIRSTNAME ORDER TYPE public const REALNAME_BEFORE = 0; @@ -100,7 +101,7 @@ class User extends CommonDBTM implements TreeBrowseInterface '2fa', ]; - private $entities = null; + private ?array $entities = null; public function getCloneRelations(): array { @@ -112,6 +113,11 @@ public function getCloneRelations(): array ]; } + /** + * @param array $input + * + * @return array + */ public function prepareInputForClone($input) { unset($input['last_login']); @@ -126,6 +132,12 @@ public function prepareInputForClone($input) return $input; } + /** + * @param CommonDBTM $source + * @param bool $history + * + * @return void + */ public function post_clone($source, $history) { //FIXME? clone config @@ -3773,7 +3785,7 @@ public static function getUsersFromDelegatedGroups($entities_id = ''): array /** * Execute the query to select box with all glpi users where select key = name * - * Internaly used by showGroup_Users, dropdownUsers and ajax/getDropdownUsers.php + * Internally used by showGroup_Users, dropdownUsers and ajax/getDropdownUsers.php * * @param boolean $count true if execute an count(*) (true by default) * @param string|string[] $right limit user who have specific right (default 'all') @@ -3784,6 +3796,7 @@ public static function getUsersFromDelegatedGroups($entities_id = ''): array * @param integer $start start LIMIT value (default 0) * @param integer $limit limit LIMIT value (default -1 no limit) * @param boolean $inactive_deleted true to retrieve also inactive or deleted users + * @param boolean $with_no_right true to include users without any rights assigned * * @return DBmysqlIterator */ @@ -3797,12 +3810,10 @@ public static function getSqlSearchResult( $start = 0, $limit = -1, $inactive_deleted = false, - $with_no_right = 0 + $with_no_right = false ) { global $DB; - - // No entity define : use active ones if (!is_array($entity_restrict) && $entity_restrict < 0) { $entity_restrict = $_SESSION["glpiactiveentities"]; @@ -4946,7 +4957,7 @@ public static function manageDeletedUserInLdap($users_id) * Handle user restored in LDAP using configured policy. * * @since 10.0.0 - * @param $users_id + * @param int $users_id * * @return void */ @@ -5058,7 +5069,7 @@ public function showPasswordUpdateForm(array $error_messages = []) /** * Show new password form of password recovery process. * - * @param $token + * @param string $token * * @return void */ @@ -6162,6 +6173,8 @@ public static function getIcon() /** * Add groups stored in "_ldap_rules/groups_id" special input + * + * @return void */ public function applyGroupsRules() { @@ -6417,6 +6430,13 @@ public function getUserInitials(bool $enable_anonymization = false): string ); } + /** + * @param string $name + * @param string $firstname + * @param string $realname + * + * @return string + */ public static function getInitialsForUserName($name, $firstname, $realname): string { $initials = mb_substr($firstname ?? '', 0, 1) . mb_substr($realname ?? '', 0, 1); diff --git a/src/UserEmail.php b/src/UserEmail.php index 169ba23cad8..53a19b4b312 100644 --- a/src/UserEmail.php +++ b/src/UserEmail.php @@ -119,7 +119,7 @@ public static function getDefaultForUser($users_id) /** * Get all emails for user. * - * @param $users_id user ID + * @param int $users_id user ID * * @return array of emails **/ @@ -147,8 +147,8 @@ public static function getAllForUser($users_id) /** * is an email of the user * - * @param $users_id user ID - * @param $email string email to check user ID + * @param int $users_id user ID + * @param string $email email to check user ID * * @return boolean is this email set for the user ? **/ @@ -266,14 +266,16 @@ public static function showForUser(User $user) /** - * @param $user + * @param User $user + * + * @return void **/ public static function showAddEmailButton(User $user) { $users_id = $user->getID(); if (!$user->can($users_id, READ) && ($users_id != Session::getLoginUserID())) { - return false; + return; } $canedit = $users_id == Session::getLoginUserID(); diff --git a/src/Webhook.php b/src/Webhook.php index 4edc8ead962..7953ee4baf9 100644 --- a/src/Webhook.php +++ b/src/Webhook.php @@ -344,6 +344,8 @@ public static function getHttpMethod(): array /** * Return status icon + * + * @param string $status * * @return string */ @@ -1049,11 +1051,17 @@ private function getSentQueriesSearchParams(): array private function showSentQueries(): void { - // Show embeded search engine for QueuedWebhook with the criteria for the current webhook ID + // Show embedded search engine for QueuedWebhook with the criteria for the current webhook ID $params = $this->getSentQueriesSearchParams(); Search::showList(QueuedWebhook::class, $params); } + /** + * @param string $data + * @param string $secret + * + * @return string + */ public static function getSignature($data, $secret): string { return hash_hmac('sha256', $data, $secret); @@ -1280,11 +1288,19 @@ public function post_getFromDB() $this->fields['custom_headers'] = importArrayFromDB($this->fields['custom_headers']); } + /** + * @return string + */ public static function generateRandomSecret() { return Toolbox::getRandomString(40); } + /** + * @param array $input + * + * @return false|array + */ public function handleInput($input) { $valid_input = true; diff --git a/src/XHProf.php b/src/XHProf.php index bbf270b10ef..0cc8a1ff87c 100644 --- a/src/XHProf.php +++ b/src/XHProf.php @@ -59,11 +59,11 @@ class XHProf public const XHPROF_URL = '/xhprof'; - private static $run = false; + private static bool $run = false; /** - * @param $msg (default '') + * @param string $msg (default '') **/ public function __construct($msg = '') { @@ -78,8 +78,10 @@ public function __destruct() /** - * @param $msg (default '') - **/ + * @param string $msg (default '') + * + * @return void + */ public function start($msg = '') { @@ -101,6 +103,9 @@ public function start($msg = '') } + /** + * @return void + */ public function stop() { if (self::$run) { From ed9a301191a4f0f2ae385a0b223199ecf25cb768 Mon Sep 17 00:00:00 2001 From: Johan Cwiklinski Date: Tue, 9 Dec 2025 13:57:29 +0100 Subject: [PATCH 2/2] Fix tests --- tests/functional/ReservationTest.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/functional/ReservationTest.php b/tests/functional/ReservationTest.php index ab80a511c57..64808df01c6 100644 --- a/tests/functional/ReservationTest.php +++ b/tests/functional/ReservationTest.php @@ -785,20 +785,19 @@ public function testCalendarDisplayPermissions(): void $_SESSION['glpiactiveprofile']['reservation'] = ReservationItem::RESERVEANITEM; ob_start(); - $result = \Reservation::showCalendar($res_item->getID()); + \Reservation::showCalendar($res_item->getID()); $output = ob_get_clean(); - $this->assertNotFalse($result, "showCalendar should work with RESERVEANITEM right"); - $this->assertNotEmpty($output, "showCalendar should produce output"); + $this->assertNotEmpty($output, "showCalendar should work with RESERVEANITEM right"); // Test showCalendar with no rights $_SESSION['glpiactiveprofile']['reservation'] = 0; ob_start(); - $result = \Reservation::showCalendar($res_item->getID()); + \Reservation::showCalendar($res_item->getID()); $output = ob_get_clean(); - $this->assertFalse($result, "showCalendar should not work without any rights"); + $this->assertEmpty($output, "showCalendar should not work without any rights"); } /**