Refactor export manager and normalize configuration handling

Simplified formatter and aggregator logic by removing redundant fields and improving method checks (e.g., `hasAggregator`, `hasFilter`). Adjusted test cases to align with the updated structure and added tests for empty data normalization and denormalization. Improved code readability and ensured better handling of edge cases in export data processing.
This commit is contained in:
2025-03-13 14:18:54 +01:00
parent db073fc920
commit 85a9c6bb67
5 changed files with 167 additions and 19 deletions

View File

@@ -81,10 +81,6 @@ final readonly class ExportGenerator
$result = $export->getResult($query, $data['export'], $context);
if (!is_iterable($result)) {
throw new \UnexpectedValueException(sprintf('The result of the export should be an iterable, %s given', \gettype($result)));
}
$formatter = $this->exportManager->getFormatter($data['pick_formatter']);
$filtersData = [];
$aggregatorsData = [];
@@ -101,7 +97,7 @@ final readonly class ExportGenerator
if (method_exists($formatter, 'generate')) {
return $formatter->generate(
$result,
$data['formatter']['form'],
$data['formatter'],
$exportAlias,
$data['export'],
$filtersData,
@@ -115,7 +111,7 @@ final readonly class ExportGenerator
$result,
$data['formatter'],
$exportAlias,
$data['export']['form'],
$data['export'],
$filtersData,
$aggregatorsData,
);
@@ -194,7 +190,7 @@ final readonly class ExportGenerator
}
foreach ($data as $alias => $aggregatorData) {
if (true === $aggregatorData['enabled']) {
if ($this->exportManager->hasAggregator($alias) && true === $aggregatorData['enabled']) {
yield $alias => $this->exportManager->getAggregator($alias);
}
}
@@ -210,7 +206,7 @@ final readonly class ExportGenerator
}
foreach ($data as $alias => $filterData) {
if (true === $filterData['enabled']) {
if ($this->exportManager->hasFilter($alias) && true === $filterData['enabled']) {
yield $alias => $this->exportManager->getFilter($alias);
}
}
@@ -249,7 +245,7 @@ final readonly class ExportGenerator
* build the array required for defining centers and circles in the initiate
* queries of ExportElementsInterfaces.
*
* @param list<Center>
* @param list<Center> $centers
*/
private function buildCenterReachableScopes(array $centers)
{