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

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