Skip to content

Commit

Permalink
fix: JoinDataTransformer must always transform to an array, even sing…
Browse files Browse the repository at this point in the history
…le objects
  • Loading branch information
ambroisemaupate committed Apr 11, 2023
1 parent 71b5b26 commit e17b804
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ public function __construct(

/**
* @param mixed $value
* @return mixed
* @return array JoinDataTransformer must always return an array for view data.
*/
public function transform(mixed $value): mixed
public function transform(mixed $value): array
{
/*
* If model is already an PersistableInterface
Expand All @@ -49,8 +49,8 @@ public function transform(mixed $value): mixed
!empty($value) &&
$value instanceof PersistableInterface
) {
return $value->getId();
} elseif (!empty($value) && is_array($value)) {
return [$value->getId()];
} elseif (!empty($value) && is_iterable($value)) {
/*
* If model is a collection of AbstractEntity
*/
Expand All @@ -62,14 +62,14 @@ public function transform(mixed $value): mixed
}
return $idArray;
} elseif (!empty($value)) {
return $value;
return [$value];
}
return '';
return [];
}

/**
* @param mixed $value
* @return mixed
* @return array|object|null
*/
public function reverseTransform(mixed $value): mixed
{
Expand Down

0 comments on commit e17b804

Please sign in to comment.