diff --git a/src/Features/Clonable.php b/src/Features/Clonable.php index f66e4e81fd2..13935204b65 100644 --- a/src/Features/Clonable.php +++ b/src/Features/Clonable.php @@ -165,7 +165,8 @@ private function cloneRelations(CommonDBTM $source, bool $history): void */ public function prepareInputForClone($input) { - if (\Toolbox::hasTrait(static::class, AssignableAsset::class)) { + if (method_exists($this, 'prepareGroupFields')) { + // Toolbox::hasTrait doesn't work to tell PHPStan this method exists even when using generics and assert-if-true $input = $this->prepareGroupFields($input); } return $input; @@ -323,7 +324,8 @@ public function computeCloneName( */ public function post_clone($source, $history) { - if (\Toolbox::hasTrait(static::class, AssignableAsset::class)) { + if (method_exists($this, 'updateGroupFields')) { + // Toolbox::hasTrait doesn't work to tell PHPStan this method exists even when using generics and assert-if-true $this->updateGroupFields(); } } diff --git a/src/Toolbox.php b/src/Toolbox.php index 1e360d0561e..f10d0825dcc 100644 --- a/src/Toolbox.php +++ b/src/Toolbox.php @@ -3080,11 +3080,9 @@ public static function isValidWebUrl($url): bool * Checks if the given class or object has the specified trait. * This function checks the class itself and all parent classes for the trait. * @since 10.0.0 - * @template T * @param string|object $class The class or object - * @param class-string $trait The trait + * @param class-string $trait The trait * @return bool True if the class or its parents have the specified trait - * @phpstan-assert-if-true class-string $class */ public static function hasTrait($class, string $trait): bool { diff --git a/tests/functional/Glpi/Inventory/Inventory.php b/tests/functional/Glpi/Inventory/Inventory.php index fb5c1d12d7b..b8969ece573 100644 --- a/tests/functional/Glpi/Inventory/Inventory.php +++ b/tests/functional/Glpi/Inventory/Inventory.php @@ -193,7 +193,9 @@ private function checkComputer1($computers_id) 'is_dynamic' => 1, 'autoupdatesystems_id' => 0, 'uuid' => null, - 'is_recursive' => 0 + 'is_recursive' => 0, + 'groups_id' => [], + 'groups_id_tech' => [], ]; $this->array($monitor_fields)->isIdenticalTo($expected); @@ -894,7 +896,9 @@ private function checkComputer1($computers_id) 'sysdescr' => null, 'last_inventory_update' => $_SESSION['glpi_currenttime'], 'snmpcredentials_id' => 0, - 'autoupdatesystems_id' => $autoupdatesystems_id + 'autoupdatesystems_id' => $autoupdatesystems_id, + 'groups_id' => [], + 'groups_id_tech' => [], ]; $this->array($printer_fields)->isIdenticalTo($expected);