Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cconard96 committed Apr 8, 2024
1 parent a8afb44 commit 61eef4c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/Features/Clonable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
Expand Down
4 changes: 1 addition & 3 deletions src/Toolbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> $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<T> $class
*/
public static function hasTrait($class, string $trait): bool
{
Expand Down
8 changes: 6 additions & 2 deletions tests/functional/Glpi/Inventory/Inventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 61eef4c

Please sign in to comment.