if ($parsed) { $criteria->
addAggregation($parsed);
} } } public function toArray(array
$aggregations): array
{ $data =
[];
foreach ($aggregations as $aggregation) { $data[] =
$this->
aggregationToArray($aggregation);
} return $data;
} private function aggregationToArray(Aggregation
$aggregation): array
{ if ($aggregation instanceof AvgAggregation
) { return [ 'name' =>
$aggregation->
getName(),
'type' => 'avg',