From 8e54a0e84830fd11c57aa4131d27fbdc3c546e1e Mon Sep 17 00:00:00 2001 From: Andrey Helldar Date: Sat, 4 Feb 2023 02:29:40 +0300 Subject: [PATCH] Improved definition of the winner --- src/Transformers/Winner.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Transformers/Winner.php b/src/Transformers/Winner.php index 3c40a5d..8e182bc 100644 --- a/src/Transformers/Winner.php +++ b/src/Transformers/Winner.php @@ -6,11 +6,21 @@ class Winner extends Base { + protected array $order = ['avg', 'max', 'min']; + public function transform(array $data, ?int $roundPrecision): array { - $values = $data['avg']; + foreach ($this->order as $key) { + $values = $data[$key]; + + $names = $this->find($values); + + if (count($names) !== count($values) - 1) { + return $this->winner($values, $names); + } + } - return $this->winner($values, $this->find($values)); + return []; } protected function winner(array $data, array $names): array