StaticRoundRobin::getConnection()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 7
rs 10
1
<?php
2
3
4
namespace Manticoresearch\Connection\Strategy;
5
6
use Manticoresearch\Connection;
7
8
/**
9
 * Class StaticRoundRobin
10
 * @package Manticoresearch\Connection\Strategy
11
 */
12
class StaticRoundRobin implements SelectorInterface
13
{
14
    /**
15
     * @var int
16
     */
17
    private $current = 0;
18
19
    /**
20
     * @param array $connections
21
     * @return Connection
22
     */
23
    public function getConnection(array $connections):Connection
24
    {
25
        if ($connections[$this->current % count($connections)]->isAlive()) {
26
            return $connections[$this->current];
27
        }
28
        ++$this->current;
29
        return $connections[$this->current % count($connections)];
30
    }
31
}
32