diff --git a/src/Transformers/Winner.php b/src/Transformers/Winner.php index 8e182bc..048c200 100644 --- a/src/Transformers/Winner.php +++ b/src/Transformers/Winner.php @@ -11,16 +11,23 @@ class Winner extends Base public function transform(array $data, ?int $roundPrecision): array { foreach ($this->order as $key) { - $values = $data[$key]; + if ($winner = $this->detectWinner($data[$key])) { + return $winner; + } + } + + return $this->detectWinner($data['avg']); + } - $names = $this->find($values); + protected function detectWinner(array $values): ?array + { + $names = $this->find($values); - if (count($names) !== count($values) - 1) { - return $this->winner($values, $names); - } + if (count($names) !== count($values) - 1) { + return $this->winner($values, $names); } - return []; + return null; } protected function winner(array $data, array $names): array