StaticRoundRobin   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 18
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A getConnection() 0 7 2
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