Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
ReportHelper | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
11 | |
100.00% |
1 / 1 |
withMaxAndAverage | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
11 |
1 | <?php |
2 | |
3 | namespace BO\Zmsstatistic\Helper; |
4 | |
5 | class ReportHelper |
6 | { |
7 | public static function withMaxAndAverage($entity, $targetKey) |
8 | { |
9 | foreach ($entity->data as $date => $dateItems) { |
10 | $maxima = 0; |
11 | $total = 0; |
12 | $count = 0; |
13 | foreach ($dateItems as $hourItems) { |
14 | if (is_array($hourItems)) { // Check if $hourItems is an array |
15 | foreach ($hourItems as $key => $value) { |
16 | if (is_numeric($value) && $targetKey == $key && 0 < $value) { |
17 | $total += $value; |
18 | $count += 1; |
19 | $maxima = ($maxima > $value) ? $maxima : $value; |
20 | } |
21 | } |
22 | } |
23 | } |
24 | $entity->data[$date]['max_' . $targetKey] = $maxima; |
25 | $entity->data[$date]['average_' . $targetKey] = (! $total || ! $count) ? 0 : $total / $count; |
26 | } |
27 | return $entity; |
28 | } |
29 | } |