Conditions | 6 |
Paths | 5 |
Total Lines | 22 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
34 | public function getAvailableHost(Request $request, array $hosts) |
||
35 | { |
||
36 | if (count($hosts) == 0) { |
||
37 | throw new NoRegisteredHostException(); |
||
38 | } |
||
39 | |||
40 | $currentLoad = 1; |
||
41 | $currentHost = null; |
||
42 | |||
43 | foreach ($hosts as $host) { |
||
44 | $load = $host->getLoad(); |
||
45 | if ($load < $this->loadLimit) { |
||
46 | return $host; |
||
47 | } |
||
48 | if ($currentHost == null || $load < $currentLoad) { |
||
49 | $currentLoad = $load; |
||
50 | $currentHost = $host; |
||
51 | } |
||
52 | } |
||
53 | |||
54 | return $currentHost; |
||
55 | } |
||
56 | } |
||
57 |