diff --git a/src/ApiCall.php b/src/ApiCall.php index afab89e8..45d8616b 100644 --- a/src/ApiCall.php +++ b/src/ApiCall.php @@ -46,12 +46,12 @@ class ApiCall /** * @var array|Node[] */ - private static array $nodes; + private array $nodes; /** * @var Node|null */ - private static ?Node $nearestNode; + private ?Node $nearestNode; /** * @var int @@ -73,8 +73,8 @@ public function __construct(Configuration $config) $this->config = $config; $this->logger = $config->getLogger(); $this->client = $config->getClient(); - static::$nodes = $this->config->getNodes(); - static::$nearestNode = $this->config->getNearestNode(); + $this->nodes = $this->config->getNodes(); + $this->nearestNode = $this->config->getNearestNode(); $this->nodeIndex = 0; $this->initializeNodes(); } @@ -84,11 +84,11 @@ public function __construct(Configuration $config) */ private function initializeNodes(): void { - if (static::$nearestNode !== null) { - $this->setNodeHealthCheck(static::$nearestNode, true); + if ($this->nearestNode !== null) { + $this->setNodeHealthCheck($this->nearestNode, true); } - foreach (static::$nodes as &$node) { + foreach ($this->nodes as &$node) { $this->setNodeHealthCheck($node, true); } } @@ -332,16 +332,16 @@ public function setNodeHealthCheck(Node $node, bool $isHealthy): void */ public function getNode(): Lib\Node { - if (static::$nearestNode !== null) { - if (static::$nearestNode->isHealthy() || $this->nodeDueForHealthCheck(static::$nearestNode)) { - return static::$nearestNode; + if ($this->nearestNode !== null) { + if ($this->nearestNode->isHealthy() || $this->nodeDueForHealthCheck($this->nearestNode)) { + return $this->nearestNode; } } $i = 0; - while ($i < count(static::$nodes)) { + while ($i < count($this->nodes)) { $i++; - $node = static::$nodes[$this->nodeIndex]; - $this->nodeIndex = ($this->nodeIndex + 1) % count(static::$nodes); + $node = $this->nodes[$this->nodeIndex]; + $this->nodeIndex = ($this->nodeIndex + 1) % count($this->nodes); if ($node->isHealthy() || $this->nodeDueForHealthCheck($node)) { return $node; } @@ -351,7 +351,7 @@ public function getNode(): Lib\Node * None of the nodes are marked healthy, but some of them could have become healthy since last health check. * So we will just return the next node. */ - return static::$nodes[$this->nodeIndex]; + return $this->nodes[$this->nodeIndex]; } /**