From 3648229b3b9e65ebb2cbbd6b67a01e8d453b85e1 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Tue, 10 Feb 2026 10:07:26 +0100 Subject: [PATCH 1/2] fix(ci): fix ci errors --- inc/container.class.php | 4 +--- inc/field.class.php | 4 +--- inc/labeltranslation.class.php | 4 +--- inc/profile.class.php | 4 +--- inc/statusoverride.class.php | 4 +--- 5 files changed, 5 insertions(+), 15 deletions(-) diff --git a/inc/container.class.php b/inc/container.class.php index f31e4241..6664bfb4 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -97,9 +97,7 @@ public static function installBaseData(Migration $migration, $version) PRIMARY KEY (`id`), KEY `entities_id` (`entities_id`) ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; - if (!$DB->doQuery($query)) { - throw new RuntimeException('Error creating plugin_fields_containers table: ' . $DB->error()); - } + $DB->doQuery($query); } // multiple itemtype for one container diff --git a/inc/field.class.php b/inc/field.class.php index 0939fe9b..a942d646 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -94,9 +94,7 @@ public static function installBaseData(Migration $migration, $version) KEY `is_active` (`is_active`), KEY `is_readonly` (`is_readonly`) ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; - if (!$DB->doQuery($query)) { - throw new RuntimeException('Error creating plugin_fields_fields table: ' . $DB->error()); - } + $DB->doQuery($query); } $migration->displayMessage('Updating ' . $table); diff --git a/inc/labeltranslation.class.php b/inc/labeltranslation.class.php index cc77f060..af965577 100644 --- a/inc/labeltranslation.class.php +++ b/inc/labeltranslation.class.php @@ -72,9 +72,7 @@ public static function installBaseData(Migration $migration, $version) KEY `language` (`language`), UNIQUE KEY `unicity` (`itemtype`, `items_id`, `language`) ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; - if (!$DB->doQuery($query)) { - throw new RuntimeException('Error creating plugin_fields_labeltranslations table: ' . $DB->error()); - } + $DB->doQuery($query); } if ($DB->fieldExists($table, 'plugin_fields_itemtype')) { diff --git a/inc/profile.class.php b/inc/profile.class.php index 8ef44fc7..6cd97e32 100644 --- a/inc/profile.class.php +++ b/inc/profile.class.php @@ -73,9 +73,7 @@ public static function installBaseData(Migration $migration, $version) KEY `profiles_id` (`profiles_id`), KEY `plugin_fields_containers_id` (`plugin_fields_containers_id`) ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; - if (!$DB->doQuery($query)) { - throw new RuntimeException('Error creating plugin_fields_profiles table: ' . $DB->error()); - } + $DB->doQuery($query); } return true; diff --git a/inc/statusoverride.class.php b/inc/statusoverride.class.php index a1a0cb59..e60eda37 100644 --- a/inc/statusoverride.class.php +++ b/inc/statusoverride.class.php @@ -70,9 +70,7 @@ public static function installBaseData(Migration $migration, $version) PRIMARY KEY (`id`), KEY `plugin_fields_fields_id` (`plugin_fields_fields_id`) ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; - if (!$DB->doQuery($query)) { - throw new RuntimeException('Error creating plugin_fields_statusoverrides table: ' . $DB->error()); - } + $DB->doQuery($query); } return true; From b990e1cc692716b301d967a807567573f0e50f08 Mon Sep 17 00:00:00 2001 From: MyuTsu Date: Tue, 10 Feb 2026 10:13:24 +0100 Subject: [PATCH 2/2] fix rector --- ajax/field_specific_fields.php | 2 +- composer.lock | 67 ++++++++++++----------- inc/container.class.php | 12 ++-- inc/field.class.php | 4 +- inc/toolbox.class.php | 2 +- setup.php | 4 +- tests/Units/FieldDestinationFieldTest.php | 1 - 7 files changed, 46 insertions(+), 46 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/composer.lock b/composer.lock index a3d65312..eb63ffd3 100644 --- a/composer.lock +++ b/composer.lock @@ -158,28 +158,28 @@ }, { "name": "symfony/yaml", - "version": "v7.3.5", + "version": "v7.4.1", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "90208e2fc6f68f613eae7ca25a2458a931b1bacc" + "reference": "24dd4de28d2e3988b311751ac49e684d783e2345" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/90208e2fc6f68f613eae7ca25a2458a931b1bacc", - "reference": "90208e2fc6f68f613eae7ca25a2458a931b1bacc", + "url": "https://api.github.com/repos/symfony/yaml/zipball/24dd4de28d2e3988b311751ac49e684d783e2345", + "reference": "24dd4de28d2e3988b311751ac49e684d783e2345", "shasum": "" }, "require": { "php": ">=8.2", - "symfony/deprecation-contracts": "^2.5|^3.0", + "symfony/deprecation-contracts": "^2.5|^3", "symfony/polyfill-ctype": "^1.8" }, "conflict": { "symfony/console": "<6.4" }, "require-dev": { - "symfony/console": "^6.4|^7.0" + "symfony/console": "^6.4|^7.0|^8.0" }, "bin": [ "Resources/bin/yaml-lint" @@ -210,7 +210,7 @@ "description": "Loads and dumps YAML files", "homepage": "https://symfony.com", "support": { - "source": "https://github.com/symfony/yaml/tree/v7.3.5" + "source": "https://github.com/symfony/yaml/tree/v7.4.1" }, "funding": [ { @@ -230,7 +230,7 @@ "type": "tidelift" } ], - "time": "2025-09-27T09:00:46+00:00" + "time": "2025-12-04T18:11:45+00:00" } ], "packages-dev": [ @@ -345,16 +345,16 @@ }, { "name": "symfony/console", - "version": "v6.4.27", + "version": "v6.4.32", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "13d3176cf8ad8ced24202844e9f95af11e2959fc" + "reference": "0bc2199c6c1f05276b05956f1ddc63f6d7eb5fc3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/13d3176cf8ad8ced24202844e9f95af11e2959fc", - "reference": "13d3176cf8ad8ced24202844e9f95af11e2959fc", + "url": "https://api.github.com/repos/symfony/console/zipball/0bc2199c6c1f05276b05956f1ddc63f6d7eb5fc3", + "reference": "0bc2199c6c1f05276b05956f1ddc63f6d7eb5fc3", "shasum": "" }, "require": { @@ -419,7 +419,7 @@ "terminal" ], "support": { - "source": "https://github.com/symfony/console/tree/v6.4.27" + "source": "https://github.com/symfony/console/tree/v6.4.32" }, "funding": [ { @@ -439,7 +439,7 @@ "type": "tidelift" } ], - "time": "2025-10-06T10:25:16+00:00" + "time": "2026-01-13T08:45:59+00:00" }, { "name": "symfony/polyfill-intl-grapheme", @@ -782,22 +782,23 @@ }, { "name": "symfony/string", - "version": "v7.3.4", + "version": "v7.4.4", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "f96476035142921000338bad71e5247fbc138872" + "reference": "1c4b10461bf2ec27537b5f36105337262f5f5d6f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/f96476035142921000338bad71e5247fbc138872", - "reference": "f96476035142921000338bad71e5247fbc138872", + "url": "https://api.github.com/repos/symfony/string/zipball/1c4b10461bf2ec27537b5f36105337262f5f5d6f", + "reference": "1c4b10461bf2ec27537b5f36105337262f5f5d6f", "shasum": "" }, "require": { "php": ">=8.2", + "symfony/deprecation-contracts": "^2.5|^3.0", "symfony/polyfill-ctype": "~1.8", - "symfony/polyfill-intl-grapheme": "~1.0", + "symfony/polyfill-intl-grapheme": "~1.33", "symfony/polyfill-intl-normalizer": "~1.0", "symfony/polyfill-mbstring": "~1.0" }, @@ -805,11 +806,11 @@ "symfony/translation-contracts": "<2.5" }, "require-dev": { - "symfony/emoji": "^7.1", - "symfony/http-client": "^6.4|^7.0", - "symfony/intl": "^6.4|^7.0", + "symfony/emoji": "^7.1|^8.0", + "symfony/http-client": "^6.4|^7.0|^8.0", + "symfony/intl": "^6.4|^7.0|^8.0", "symfony/translation-contracts": "^2.5|^3.0", - "symfony/var-exporter": "^6.4|^7.0" + "symfony/var-exporter": "^6.4|^7.0|^8.0" }, "type": "library", "autoload": { @@ -848,7 +849,7 @@ "utf8" ], "support": { - "source": "https://github.com/symfony/string/tree/v7.3.4" + "source": "https://github.com/symfony/string/tree/v7.4.4" }, "funding": [ { @@ -868,20 +869,20 @@ "type": "tidelift" } ], - "time": "2025-09-11T14:36:48+00:00" + "time": "2026-01-12T10:54:30+00:00" }, { "name": "twig/twig", - "version": "v3.22.0", + "version": "v3.23.0", "source": { "type": "git", "url": "https://github.com/twigphp/Twig.git", - "reference": "4509984193026de413baf4ba80f68590a7f2c51d" + "reference": "a64dc5d2cc7d6cafb9347f6cd802d0d06d0351c9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/twigphp/Twig/zipball/4509984193026de413baf4ba80f68590a7f2c51d", - "reference": "4509984193026de413baf4ba80f68590a7f2c51d", + "url": "https://api.github.com/repos/twigphp/Twig/zipball/a64dc5d2cc7d6cafb9347f6cd802d0d06d0351c9", + "reference": "a64dc5d2cc7d6cafb9347f6cd802d0d06d0351c9", "shasum": "" }, "require": { @@ -935,7 +936,7 @@ ], "support": { "issues": "https://github.com/twigphp/Twig/issues", - "source": "https://github.com/twigphp/Twig/tree/v3.22.0" + "source": "https://github.com/twigphp/Twig/tree/v3.23.0" }, "funding": [ { @@ -947,18 +948,18 @@ "type": "tidelift" } ], - "time": "2025-10-29T15:56:47+00:00" + "time": "2026-01-23T21:00:41+00:00" } ], "aliases": [], "minimum-stability": "stable", - "stability-flags": {}, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { "php": ">=8.2" }, - "platform-dev": {}, + "platform-dev": [], "platform-overrides": { "php": "8.2.99" }, diff --git a/inc/container.class.php b/inc/container.class.php index 6664bfb4..b25fadaf 100644 --- a/inc/container.class.php +++ b/inc/container.class.php @@ -748,7 +748,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) { @@ -1173,7 +1173,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 { @@ -1259,7 +1259,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']); @@ -1292,7 +1292,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); } } @@ -1721,7 +1721,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']; } } @@ -1783,7 +1783,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 a942d646..c33051df 100644 --- a/inc/field.class.php +++ b/inc/field.class.php @@ -628,7 +628,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 { @@ -973,7 +973,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));