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

RotationChooser   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 15
rs 10

1 Method

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