From af53604036467279f29c015651af9369be279373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Tue, 8 Nov 2022 14:54:03 +0000 Subject: [PATCH] Fix round robin index --- src/Balancer/Algorithm/RoundRobin.php | 5 ++--- src/Balancer/Balancer.php | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Balancer/Algorithm/RoundRobin.php b/src/Balancer/Algorithm/RoundRobin.php index 04fd81f..586ed1b 100644 --- a/src/Balancer/Algorithm/RoundRobin.php +++ b/src/Balancer/Algorithm/RoundRobin.php @@ -37,14 +37,13 @@ public function run(array $options): ?Option { $this->index++; - $keys = \array_keys($options); $option = null; if (\count($options) === $this->index) { - $option = $options[$keys[0]]; + $option = $options[0]; $this->index = 0; } else { - $option = $options[$keys[$this->index]]; + $option = $options[$this->index]; } return $option; diff --git a/src/Balancer/Balancer.php b/src/Balancer/Balancer.php index e9bd6ba..aecf687 100644 --- a/src/Balancer/Balancer.php +++ b/src/Balancer/Balancer.php @@ -46,6 +46,8 @@ public function run(): ?Option $options = \array_filter($options, $filter); } + $options = \array_values($options); + return $this->algo->run($options); } }