Code Duplication    Length = 34-34 lines in 2 locations

src/DataSource/ArrayDataSource.php 1 location

@@ 389-422 (lines=34) @@
386
	 * get aggregation row
387
	 * @return array
388
	 */
389
	public function getAggregationData()
390
	{
391
		$result = [];
392
		foreach ($this->data as $row) {
393
			foreach ($this->aggregations as $column => $aggregation_type) {
394
				switch ($aggregation_type) {
395
					case ColumnAggregationFunction::$aggregation_type_sum:
396
					case ColumnAggregationFunction::$aggregation_type_avg:
397
						if (!isset($result[$column])) {
398
							$result[$column] = 0;
399
						}
400
						$result[$column] += $row[$column];
401
						break;
402
					case ColumnAggregationFunction::$aggregation_type_min:
403
						if (!isset($result[$column]) || $row[$column] < $result[$column]) {
404
							$result[$column] = $row[$column];
405
						}
406
						break;
407
					case ColumnAggregationFunction::$aggregation_type_max:
408
						if (!isset($result[$column]) || $row[$column] > $result[$column]) {
409
							$result[$column] = $row[$column];
410
						}
411
						break;
412
				}
413
			}
414
		}
415
416
		foreach ($this->aggregations as $column => $aggregation_type) {
417
			if ($aggregation_type == ColumnAggregationFunction::$aggregation_type_avg) {
418
				$result[$column] =  $result[$column] / count($this->data);
419
			}
420
		}
421
		return $result;
422
	}
423
}
424

src/DataSource/DoctrineCollectionDataSource.php 1 location

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