1 | <?php |
||
17 | class HttpClient |
||
18 | { |
||
19 | /** |
||
20 | * instance of the request headers. |
||
21 | */ |
||
22 | private $headers; |
||
23 | |||
24 | /** |
||
25 | * An instance of the HTTP response. |
||
26 | */ |
||
27 | private $response; |
||
28 | |||
29 | /** |
||
30 | * An instance of Guzzle Http Client. |
||
31 | * |
||
32 | * @var \GuzzleHttp\Client |
||
33 | */ |
||
34 | private $client; |
||
35 | |||
36 | |||
37 | /** |
||
38 | * Create a new request instance. |
||
39 | */ |
||
40 | public function __construct() |
||
44 | |||
45 | /** |
||
46 | * Mock HTTP request. |
||
47 | * |
||
48 | * @param int $statusCode |
||
49 | * @param string $body |
||
50 | * @param array $headers |
||
51 | * |
||
52 | * @return \GuzzleHttp\Client |
||
53 | */ |
||
54 | private function mockClient(int $statusCode = 200, string $body = 'success', $headers = []): Client |
||
64 | |||
65 | /** |
||
66 | * Set request headers. |
||
67 | * |
||
68 | * @param array $headers |
||
69 | * |
||
70 | * @return $this |
||
71 | */ |
||
72 | public function withHeaders(array $headers) |
||
78 | |||
79 | /** |
||
80 | * Enable mocking for request. |
||
81 | * |
||
82 | * @param int $statusCode |
||
83 | * @param string $body |
||
84 | * @param array $headers |
||
85 | * |
||
86 | * @return $this |
||
87 | */ |
||
88 | public function mock(int $statusCode = 200, string $body = '', $headers = []): self |
||
94 | |||
95 | /** |
||
96 | * Send a POST request |
||
97 | * |
||
98 | * @param string $url |
||
99 | * @param array $data |
||
100 | * |
||
101 | * @return $this |
||
102 | * @throws \Exception |
||
103 | */ |
||
104 | public function post(string $url, array $data = []): self |
||
110 | |||
111 | /** |
||
112 | * Send a request |
||
113 | * |
||
114 | * @param string $method |
||
115 | * @param string $url |
||
116 | * @param array $data |
||
117 | * |
||
118 | * @return \Psr\Http\Message\ResponseInterface |
||
119 | * @throws \Exception |
||
120 | */ |
||
121 | public function send(string $method, string $url, array $data) |
||
134 | |||
135 | /** |
||
136 | * Handle possible request exceptions. |
||
137 | * |
||
138 | * @param Exception $exception |
||
139 | * |
||
140 | * @return mixed |
||
141 | * @throws Exception |
||
142 | */ |
||
143 | private function handleException(Exception $exception) |
||
158 | |||
159 | /** |
||
160 | * Send a GET request |
||
161 | * |
||
162 | * @param string $url |
||
163 | * @param array $data |
||
164 | * |
||
165 | * @return $this |
||
166 | * @throws \Exception |
||
167 | */ |
||
168 | public function get(string $url, array $data = []): self |
||
174 | |||
175 | /** |
||
176 | * Send a PUT request |
||
177 | * |
||
178 | * @param string $url |
||
179 | * @param array $data |
||
180 | * |
||
181 | * @return $this |
||
182 | * @throws \Exception |
||
183 | */ |
||
184 | public function put(string $url, array $data = []): self |
||
190 | |||
191 | /** |
||
192 | * Send a DELETE request |
||
193 | * |
||
194 | * @param string $url |
||
195 | * @param array $data |
||
196 | * |
||
197 | * @return $this |
||
198 | * @throws \Exception |
||
199 | */ |
||
200 | public function delete(string $url, array $data = []): self |
||
206 | |||
207 | /** |
||
208 | * Send a PATCH request |
||
209 | * |
||
210 | * @param string $url |
||
211 | * @param array $data |
||
212 | * |
||
213 | * @return $this |
||
214 | * @throws \Exception |
||
215 | */ |
||
216 | public function patch(string $url, array $data = []): self |
||
222 | |||
223 | /** |
||
224 | * Return response as an array. |
||
225 | * |
||
226 | * @return array |
||
227 | */ |
||
228 | public function json() |
||
232 | |||
233 | /** |
||
234 | * Return response status code. |
||
235 | * |
||
236 | * @return int |
||
237 | */ |
||
238 | public function statusCode(): int |
||
242 | } |
||
243 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: