Skip to content

Commit

Permalink
i change my mind about liking traits
Browse files Browse the repository at this point in the history
  • Loading branch information
cconard96 committed Apr 4, 2024
1 parent 08712c9 commit 1e5bfe1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 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

0 comments on commit 1e5bfe1

Please sign in to comment.