Skip to content

Commit

Permalink
Improved definition of the winner
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-helldar committed Feb 3, 2023
1 parent 8cba867 commit 8e54a0e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/Transformers/Winner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8e54a0e

Please sign in to comment.