Skip to content

Commit

Permalink
fix(indexation) remove empty values from subarrays
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioMendolia committed Feb 28, 2025
1 parent 9838945 commit c654e0f
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/Mapper/Fields/FieldMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,30 @@ public function __construct(
$this->type = $type instanceof DataTypeEnum ? $type->value : $type;
}

/**
* @template TKey
* @template TValue
*
* @param array<TKey, TValue> $array
*
* @return array<TKey, TValue>
*/
protected static function array_filter_recursive(array $array, ?callable $callback = null): array
{
$array = is_callable($callback) ? array_filter($array, $callback) : array_filter($array);
foreach ($array as &$value) {
if (is_array($value)) {
$value = self::array_filter_recursive($value, $callback);
}
}

return $array;
}

public function toArray(): array
{
// Make sure to "ksort" values to keep the order consistent
return array_filter([
return self::array_filter_recursive([
'drop' => $this->drop,
'facet' => $this->facet,
'index' => $this->index,
Expand Down

0 comments on commit c654e0f

Please sign in to comment.