From 09dbba836fcabd8941cbe11dc3be2cebe69ed8ce Mon Sep 17 00:00:00 2001 From: Rom1-B Date: Wed, 4 Feb 2026 08:44:18 +0100 Subject: [PATCH] Fix(CI): rector --- ajax/field_specific_fields.php | 2 +- inc/container.class.php | 12 ++++++------ inc/field.class.php | 4 ++-- inc/toolbox.class.php | 2 +- setup.php | 4 ++-- tests/Units/FieldDestinationFieldTest.php | 1 - 6 files changed, 12 insertions(+), 13 deletions(-) diff --git a/ajax/field_specific_fields.php b/ajax/field_specific_fields.php index 9360b99f..61671293 100644 --- a/ajax/field_specific_fields.php +++ b/ajax/field_specific_fields.php @@ -133,7 +133,7 @@ $field->fields['default_value'] = ''; } - $default_value = $multiple ? json_decode($field->fields['default_value']) : $field->fields['default_value']; + $default_value = $multiple ? json_decode((string) $field->fields['default_value']) : $field->fields['default_value']; Dropdown::show( $itemtype, [ diff --git a/inc/container.class.php b/inc/container.class.php index f31e4241..6f02903a 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -750,7 +750,7 @@ public static function create($fields) public static function generateTemplate($fields) { - $itemtypes = strlen((string) $fields['itemtypes']) > 0 + $itemtypes = (string) $fields['itemtypes'] !== '' ? PluginFieldsToolbox::decodeJSONItemtypes($fields['itemtypes'], true) : []; foreach ($itemtypes as $itemtype) { @@ -1175,7 +1175,7 @@ public static function getEntries($type = 'tab', $full = false): array if (!in_array($item['entities_id'], $_SESSION['glpiactiveentities'])) { if ($item['is_recursive'] == 1) { $entities = getSonsOf('glpi_entities', $item['entities_id']); - if (count(array_intersect($entities, $_SESSION['glpiactiveentities'])) == 0) { + if (array_intersect($entities, $_SESSION['glpiactiveentities']) === []) { continue; } } else { @@ -1261,7 +1261,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) // needs to check if entity of item is in hierachy of $tab_name foreach ($container->find(['is_active' => 1, 'name' => $tab_name]) as $data) { $dataitemtypes = PluginFieldsToolbox::decodeJSONItemtypes($data['itemtypes']); - if (in_array($item::class, $dataitemtypes) != false) { + if (in_array($item::class, $dataitemtypes)) { $entities = [$data['entities_id']]; if ($data['is_recursive']) { $entities = getSonsOf(getTableForItemType('Entity'), $data['entities_id']); @@ -1294,7 +1294,7 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $ $container = new self(); if ($container->getFromDB($tabnum)) { $dataitemtypes = PluginFieldsToolbox::decodeJSONItemtypes($container->fields['itemtypes']); - if (in_array($item::class, $dataitemtypes) != false) { + if (in_array($item::class, $dataitemtypes)) { return PluginFieldsField::showForTabContainer($container->fields['id'], $item); } } @@ -1723,7 +1723,7 @@ public static function findContainer($itemtype, $type = 'tab', $subtype = '') foreach ($itemtypes as $data) { $dataitemtypes = PluginFieldsToolbox::decodeJSONItemtypes($data['itemtypes']); - if (in_array($itemtype, $dataitemtypes) != false) { + if (in_array($itemtype, $dataitemtypes)) { $id = $data['id']; } } @@ -1785,7 +1785,7 @@ public static function preItemUpdate(CommonDBTM $item) //update data $container = new self(); if ( - count($data) == 0 + count($data) === 0 || $container->updateFieldsValues($data, $item->getType(), isset($_REQUEST['massiveaction'])) ) { $item->input['date_mod'] = $_SESSION['glpi_currenttime']; diff --git a/inc/field.class.php b/inc/field.class.php index 0939fe9b..319f5f46 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -630,7 +630,7 @@ public function showSummary($container) . sprintf("", $cID, $rand); echo __('Add a new field', 'fields') . '
'; - if (count($iterator) == 0) { + if (count($iterator) === 0) { echo ""; echo "
" . __('No field for this block', 'fields') . '
'; } else { @@ -975,7 +975,7 @@ public static function showForTab($params) $itemtypes = PluginFieldsContainer::getUsedItemtypes($type, true); //if no dom containers defined for this itemtype, do nothing (in_array case insensitive) - if (!in_array(strtolower((string) $item::getType()), array_map('strtolower', $itemtypes))) { + if (!in_array(strtolower((string) $item::getType()), array_map(strtolower(...), $itemtypes))) { return; } diff --git a/inc/toolbox.class.php b/inc/toolbox.class.php index a8e114a7..b0564290 100644 --- a/inc/toolbox.class.php +++ b/inc/toolbox.class.php @@ -50,7 +50,7 @@ public function getSystemNameFromLabel($label) $name = preg_replace('/[^\da-z]/i', '', $name); // 3. if empty, uses a random number - if (strlen((string) $name) == 0) { + if ((string) (string) $name === '') { $name = random_int(0, mt_getrandmax()); } diff --git a/setup.php b/setup.php index bd70ff9a..1f4abb22 100644 --- a/setup.php +++ b/setup.php @@ -278,7 +278,7 @@ function plugin_fields_checkFiles() global $DB; // Clean all existing files - array_map('unlink', glob(PLUGINFIELDS_DOC_DIR . '/*/*')); + array_map(unlink(...), glob(PLUGINFIELDS_DOC_DIR . '/*/*')); // Regenerate dropdowns if ($DB->tableExists(PluginFieldsField::getTable())) { @@ -320,7 +320,7 @@ function plugin_fields_exportBlockAsYaml($container_id = null) $container_obj = new PluginFieldsContainer(); $containers = $container_obj->find($where); foreach ($containers as $container) { - $itemtypes = (strlen((string) $container['itemtypes']) > 0) + $itemtypes = ((string) $container['itemtypes'] !== '') ? PluginFieldsToolbox::decodeJSONItemtypes($container['itemtypes'], true) : []; diff --git a/tests/Units/FieldDestinationFieldTest.php b/tests/Units/FieldDestinationFieldTest.php index 9f7805d7..6804baed 100644 --- a/tests/Units/FieldDestinationFieldTest.php +++ b/tests/Units/FieldDestinationFieldTest.php @@ -293,7 +293,6 @@ private function sendFormAndAssertITILObjectAdditionalFields( $itil_object = array_reduce( $created_items, fn(?CommonITILObject $carry, CommonITILObject $item) => $carry ?? ($item instanceof $itil_class ? $item : null), - null, ); $this->assertNotNull($itil_object, sprintf('No created item of type %s found.', $itil_class));