Completed
Push — master ( 2f5908...5d4ec2 )
by Nicolas
01:59
created

RotationChooser::getAvailableHost()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 2
eloc 4
nc 2
nop 2
1
<?php
2
3
namespace NBN\LoadBalancer\Chooser;
4
5
use NBN\LoadBalancer\Exception\NoRegisteredHostException;
6
use NBN\LoadBalancer\Host\HostInterface;
7
use Symfony\Component\HttpFoundation\Request;
8
9
/**
10
 * @author Nicolas Bastien <[email protected]>
11
 */
12
class RotationChooser implements ChooserInterface
13
{
14
    /**
15
     * {@inheritdoc}
16
     */
17
    public function getAvailableHost(Request $request, array $hosts)
18
    {
19
        if (count($hosts) == 0) {
20
            throw new NoRegisteredHostException();
21
        }
22
23
        //basic random
24
        return $hosts[array_rand($hosts)];
25
    }
26
}
27