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