RoundRobin::getConnection()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
4
namespace Manticoresearch\Connection\Strategy;
5
6
use Manticoresearch\Connection;
7
8
/**
9
 * Class RoundRobin
10
 * @package Manticoresearch\Connection\Strategy
11
 */
12
class RoundRobin 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
        $connection = $connections[$this->current % count($connections)];
26
        ++$this->current;
27
        return $connection;
28
    }
29
}
30