Conditions | 4 |
Paths | 2 |
Total Lines | 24 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 4.074 |
Changes | 0 |
1 | <?php |
||
21 | 6 | protected function chooseHttpClient(): HttpClientPoolItem |
|
22 | { |
||
23 | $clientPool = array_filter($this->clientPool, function (HttpClientPoolItem $clientPoolItem) { |
||
24 | 5 | return !$clientPoolItem->isDisabled(); |
|
25 | 6 | }); |
|
26 | |||
27 | 6 | if (0 === count($clientPool)) { |
|
28 | 2 | throw new HttpClientNotFoundException('Cannot choose a http client as there is no one present in the pool'); |
|
29 | } |
||
30 | |||
31 | usort($clientPool, function (HttpClientPoolItem $clientA, HttpClientPoolItem $clientB) { |
||
32 | 1 | if ($clientA->getSendingRequestCount() === $clientB->getSendingRequestCount()) { |
|
33 | return 0; |
||
34 | } |
||
35 | |||
36 | 1 | if ($clientA->getSendingRequestCount() < $clientB->getSendingRequestCount()) { |
|
37 | return -1; |
||
38 | } |
||
39 | |||
40 | 1 | return 1; |
|
41 | 5 | }); |
|
42 | |||
43 | 5 | return reset($clientPool); |
|
44 | } |
||
45 | } |
||
46 |