| Conditions | 4 |
| Paths | 1 |
| Total Lines | 27 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 28 | public function report() |
||
| 29 | { |
||
| 30 | $report = array_reduce($this->events, function($reportAccumulator, $event) { |
||
| 31 | /** |
||
| 32 | * @var $event Event |
||
| 33 | */ |
||
| 34 | $key = $event->country . $event->city; |
||
| 35 | if (isset($reportAccumulator[$key])) { |
||
| 36 | $reportAccumulator[$key]['count'] += 1; |
||
| 37 | return $reportAccumulator; |
||
| 38 | } |
||
| 39 | $reportAccumulator[$key] = [ |
||
| 40 | 'country' => $event->country, |
||
| 41 | 'city' => $event->city, |
||
| 42 | 'count' => 1 |
||
| 43 | ]; |
||
| 44 | return $reportAccumulator; |
||
| 45 | }); |
||
| 46 | |||
| 47 | usort($report, function($a, $b) { |
||
| 48 | if ($a['count'] == $b['count']) { |
||
| 49 | return 0; |
||
| 50 | } |
||
| 51 | return ($a['count'] > $b['count']) ? -1 : 1; |
||
| 52 | }); |
||
| 53 | |||
| 54 | return $report; |
||
| 55 | } |
||
| 56 | } |