| Conditions | 6 |
| Paths | 6 |
| Total Lines | 28 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 2 |
| 1 | <?php |
||
| 21 | public function chooseHttpClient() |
||
| 22 | { |
||
| 23 | $clientPool = []; |
||
| 24 | |||
| 25 | foreach ($this->clientPool as $clientPoolItem) { |
||
| 26 | if (!$clientPoolItem->isDisabled()) { |
||
| 27 | $clientPool[] = $clientPoolItem; |
||
| 28 | } |
||
| 29 | } |
||
| 30 | |||
| 31 | if (0 === count($clientPool)) { |
||
| 32 | throw new NotFoundHttpClientException('Cannot choose a http client as there is no one present in the pool'); |
||
| 33 | } |
||
| 34 | |||
| 35 | usort($clientPool, function (HttpClientPoolItem $clientA, HttpClientPoolItem $clientB) { |
||
| 36 | if ($clientA->getSendingRequestCount() === $clientB->getSendingRequestCount()) { |
||
| 37 | return 0; |
||
| 38 | } |
||
| 39 | |||
| 40 | if ($clientA->getSendingRequestCount() < $clientB->getSendingRequestCount()) { |
||
| 41 | return -1; |
||
| 42 | } |
||
| 43 | |||
| 44 | return 1; |
||
| 45 | }); |
||
| 46 | |||
| 47 | return reset($clientPool); |
||
| 48 | } |
||
| 49 | } |
||
| 50 |