Code Duplication    Length = 34-34 lines in 2 locations

src/DataSource/ArrayDataSource.php 1 location

@@ 395-428 (lines=34) @@
392
	 * get aggregation row
393
	 * @return array
394
	 */
395
	public function getAggregationData()
396
	{
397
		$result = [];
398
		foreach ($this->data as $row) {
399
			foreach ($this->aggregations as $column => $aggregation_type) {
400
				switch ($aggregation_type) {
401
					case ColumnAggregationFunction::AGGREGATION_TYPE_SUM:
402
					case ColumnAggregationFunction::AGGREGATION_TYPE_AVG:
403
						if (!isset($result[$column])) {
404
							$result[$column] = 0;
405
						}
406
						$result[$column] += $row[$column];
407
						break;
408
					case ColumnAggregationFunction::AGGREGATION_TYPE_MIN:
409
						if (!isset($result[$column]) || $row[$column] < $result[$column]) {
410
							$result[$column] = $row[$column];
411
						}
412
						break;
413
					case ColumnAggregationFunction::AGGREGATION_TYPE_MAX:
414
						if (!isset($result[$column]) || $row[$column] > $result[$column]) {
415
							$result[$column] = $row[$column];
416
						}
417
						break;
418
				}
419
			}
420
		}
421
422
		foreach ($this->aggregations as $column => $aggregation_type) {
423
			if ($aggregation_type == ColumnAggregationFunction::AGGREGATION_TYPE_AVG) {
424
				$result[$column] =  $result[$column] / count($this->data);
425
			}
426
		}
427
		return $result;
428
	}
429
}
430

src/DataSource/DoctrineCollectionDataSource.php 1 location

@@ 285-318 (lines=34) @@
282
	 * get aggregation row
283
	 * @return array
284
	 */
285
	public function getAggregationData()
286
	{
287
		$result = [];
288
		foreach ($this->data_source as $row) {
289
			foreach ($this->aggregations as $column => $aggregation_type) {
290
				switch ($aggregation_type) {
291
					case ColumnAggregationFunction::AGGREGATION_TYPE_SUM:
292
					case ColumnAggregationFunction::AGGREGATION_TYPE_AVG:
293
						if (!isset($result[$column])) {
294
							$result[$column] = 0;
295
						}
296
						$result[$column] += $row[$column];
297
						break;
298
					case ColumnAggregationFunction::AGGREGATION_TYPE_MIN:
299
						if (!isset($result[$column]) || $row[$column] < $result[$column]) {
300
							$result[$column] = $row[$column];
301
						}
302
						break;
303
					case ColumnAggregationFunction::AGGREGATION_TYPE_MAX:
304
						if (!isset($result[$column]) || $row[$column] > $result[$column]) {
305
							$result[$column] = $row[$column];
306
						}
307
						break;
308
				}
309
			}
310
		}
311
312
		foreach ($this->aggregations as $column => $aggregation_type) {
313
			if ($aggregation_type == ColumnAggregationFunction::AGGREGATION_TYPE_AVG) {
314
				$result[$column] =  $result[$column] / $this->data_source->count();
315
			}
316
		}
317
		return $result;
318
	}
319
}
320