1 | <?php |
||
16 | final class HttpClientRouter implements HttpClient, HttpAsyncClient |
||
17 | { |
||
18 | /** |
||
19 | * @var array |
||
20 | */ |
||
21 | private $clients = []; |
||
22 | |||
23 | /** |
||
24 | * {@inheritdoc} |
||
25 | */ |
||
26 | 2 | public function sendRequest(RequestInterface $request) |
|
27 | { |
||
28 | 2 | $client = $this->chooseHttpClient($request); |
|
29 | |||
30 | 1 | return $client->sendRequest($request); |
|
|
|||
31 | } |
||
32 | |||
33 | /** |
||
34 | * {@inheritdoc} |
||
35 | */ |
||
36 | 2 | public function sendAsyncRequest(RequestInterface $request) |
|
37 | { |
||
38 | 2 | $client = $this->chooseHttpClient($request); |
|
39 | |||
40 | 1 | return $client->sendAsyncRequest($request); |
|
41 | } |
||
42 | |||
43 | /** |
||
44 | * Add a client to the router. |
||
45 | * |
||
46 | * @param HttpClient|HttpAsyncClient $client |
||
47 | * @param RequestMatcher $requestMatcher |
||
48 | */ |
||
49 | 4 | public function addClient($client, RequestMatcher $requestMatcher) |
|
50 | { |
||
51 | 4 | $this->clients[] = [ |
|
52 | 4 | 'matcher' => $requestMatcher, |
|
53 | 4 | 'client' => new FlexibleHttpClient($client), |
|
54 | ]; |
||
55 | 4 | } |
|
56 | |||
57 | /** |
||
58 | * Choose an HTTP client given a specific request. |
||
59 | * |
||
60 | * @param RequestInterface $request |
||
61 | * |
||
62 | * @return HttpClient|HttpAsyncClient |
||
63 | */ |
||
64 | 4 | protected function chooseHttpClient(RequestInterface $request) |
|
74 | } |
||
75 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: