1 | <?php |
||
20 | class ProfileClient implements HttpClient, HttpAsyncClient |
||
21 | { |
||
22 | /** |
||
23 | * @var HttpClient|HttpAsyncClient |
||
24 | */ |
||
25 | private $client; |
||
26 | |||
27 | /** |
||
28 | * @var Collector |
||
29 | */ |
||
30 | private $collector; |
||
31 | |||
32 | /** |
||
33 | * @var Formatter |
||
34 | */ |
||
35 | private $formatter; |
||
36 | |||
37 | /** |
||
38 | * @param HttpClient|HttpAsyncClient $client The client to profile. Client must implement both HttpClient and |
||
39 | * HttpAsyncClient interfaces. |
||
40 | * @param Collector $collector |
||
41 | * @param Formatter $formatter |
||
42 | */ |
||
43 | 4 | public function __construct($client, Collector $collector, Formatter $formatter) |
|
44 | { |
||
45 | 4 | if (!($client instanceof HttpClient && $client instanceof HttpAsyncClient)) { |
|
46 | throw new \RuntimeException(sprintf( |
||
47 | '%s first argument must implement %s and %s. Consider using %s.', |
||
48 | __METHOD__, |
||
49 | HttpClient::class, |
||
50 | HttpAsyncClient::class, |
||
51 | FlexibleHttpClient::class |
||
52 | )); |
||
53 | } |
||
54 | $this->client = $client; |
||
55 | $this->collector = $collector; |
||
56 | $this->formatter = $formatter; |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * {@inheritdoc} |
||
61 | */ |
||
62 | public function sendAsyncRequest(RequestInterface $request) |
||
77 | |||
78 | /** |
||
79 | * {@inheritdoc} |
||
80 | */ |
||
81 | public function sendRequest(RequestInterface $request) |
||
98 | |||
99 | /** |
||
100 | * @param RequestInterface $request |
||
101 | * @param Stack|null $stack |
||
102 | */ |
||
103 | private function collectRequestInformations(RequestInterface $request, Stack $stack = null) |
||
115 | |||
116 | /** |
||
117 | * @param ResponseInterface $response |
||
118 | * @param Stack|null $stack |
||
119 | */ |
||
120 | private function collectResponseInformations(ResponseInterface $response, Stack $stack = null) |
||
129 | |||
130 | /** |
||
131 | * @param \Exception $exception |
||
132 | * @param Stack|null $stack |
||
133 | */ |
||
134 | private function collectExceptionInformations(\Exception $exception, Stack $stack = null) |
||
146 | } |
||
147 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.