• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

voku / httpful / 31916034391

15 Aug 2026 11:57PM UTC coverage: 95.599%. First build
31916034391

Pull #34

github

web-flow
Merge 6dcedf4fe into 4fb313c5a
Pull Request #34: Add agent-loop tooling and implement QUERY (RFC 10008) through it

9 of 16 new or added lines in 4 files covered. (56.25%)

2737 of 2863 relevant lines covered (95.6%)

59.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.37
/src/Httpful/Client.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Httpful;
6

7
use Psr\Http\Client\ClientInterface;
8
use Psr\Http\Message\RequestInterface;
9
use Psr\Http\Message\ResponseInterface;
10

11
class Client implements ClientInterface
12
{
13
    /**
14
     * @param string                       $uri
15
     * @param array<string|int, mixed>|null $params
16
     * @param string                       $mime
17
     *
18
     * @return Response
19
     */
20
    public static function delete(string $uri, ?array $params = null, string $mime = Mime::JSON): Response
21
    {
22
        return self::delete_request($uri, $params, $mime)->send();
1✔
23
    }
24

25
    /**
26
     * @param string                       $uri
27
     * @param array<string|int, mixed>|null $params
28
     * @param string                       $mime
29
     *
30
     * @return Request
31
     */
32
    public static function delete_request(string $uri, ?array $params = null, string $mime = Mime::JSON): Request
33
    {
34
        return Request::delete($uri, $params, $mime);
2✔
35
    }
36

37
    /**
38
     * @param string    $uri
39
     * @param string    $file_path
40
     * @param float|int $timeout
41
     *
42
     * @return Response
43
     */
44
    public static function download(string $uri, $file_path, $timeout = 0): Response
45
    {
46
        $request = Request::download($uri, $file_path);
1✔
47

48
        if ($timeout > 0) {
1✔
49
            $request->withTimeout($timeout)
1✔
50
                ->withConnectionTimeoutInSeconds($timeout / 10);
1✔
51
        }
52

53
        return $request->send();
1✔
54
    }
55

56
    /**
57
     * @param string                       $uri
58
     * @param array<string|int, mixed>|null $params
59
     * @param string|null                  $mime
60
     *
61
     * @return Response
62
     */
63
    public static function get(string $uri, ?array $params = null, ?string $mime = Mime::PLAIN): Response
64
    {
65
        return self::get_request($uri, $params, $mime)->send();
1✔
66
    }
67

68
    /**
69
     * @param string                       $uri
70
     * @param array<string|int, mixed>|null $param
71
     *
72
     * @return \voku\helper\HtmlDomParser|null
73
     */
74
    public static function get_dom(string $uri, ?array $param = null)
75
    {
76
        return self::get_request($uri, $param, Mime::HTML)->send()->getRawBody();
1✔
77
    }
78

79
    /**
80
     * @param string                       $uri
81
     * @param array<string|int, mixed>|null $param
82
     *
83
     * @return array<string, mixed>
84
     */
85
    public static function get_form(string $uri, ?array $param = null): array
86
    {
87
        return self::get_request($uri, $param, Mime::FORM)->send()->getRawBody();
1✔
88
    }
89

90
    /**
91
     * @param string                       $uri
92
     * @param array<string|int, mixed>|null $param
93
     *
94
     * @return mixed
95
     */
96
    public static function get_json(string $uri, ?array $param = null)
97
    {
98
        return self::get_request($uri, $param, Mime::JSON)->send()->getRawBody();
1✔
99
    }
100

101
    /**
102
     * @param string                       $uri
103
     * @param array<string|int, mixed>|null $param
104
     * @param string|null                  $mime
105
     *
106
     * @return Request
107
     */
108
    public static function get_request(string $uri, ?array $param = null, ?string $mime = Mime::PLAIN): Request
109
    {
110
        return Request::get($uri, $param, $mime)->followRedirects();
7✔
111
    }
112

113
    /**
114
     * @param string                       $uri
115
     * @param array<string|int, mixed>|null $param
116
     *
117
     * @return \SimpleXMLElement|null
118
     */
119
    public static function get_xml(string $uri, ?array $param = null)
120
    {
121
        return self::get_request($uri, $param, Mime::XML)->send()->getRawBody();
1✔
122
    }
123

124
    /**
125
     * @param string $uri
126
     *
127
     * @return Response
128
     */
129
    public static function head(string $uri): Response
130
    {
131
        return self::head_request($uri)->send();
1✔
132
    }
133

134
    /**
135
     * @param string $uri
136
     *
137
     * @return Request
138
     */
139
    public static function head_request(string $uri): Request
140
    {
141
        return Request::head($uri)->followRedirects();
2✔
142
    }
143

144
    /**
145
     * @param string $uri
146
     *
147
     * @return Response
148
     */
149
    public static function options(string $uri): Response
150
    {
151
        return self::options_request($uri)->send();
1✔
152
    }
153

154
    /**
155
     * @param string $uri
156
     *
157
     * @return Request
158
     */
159
    public static function options_request(string $uri): Request
160
    {
161
        return Request::options($uri);
2✔
162
    }
163

164
    /**
165
     * @param string     $uri
166
     * @param mixed|null $payload
167
     * @param string     $mime
168
     *
169
     * @return Response
170
     */
171
    public static function patch(string $uri, $payload = null, string $mime = Mime::PLAIN): Response
172
    {
173
        return self::patch_request($uri, $payload, $mime)->send();
1✔
174
    }
175

176
    /**
177
     * @param string     $uri
178
     * @param mixed|null $payload
179
     * @param string     $mime
180
     *
181
     * @return Request
182
     */
183
    public static function patch_request(string $uri, $payload = null, string $mime = Mime::PLAIN): Request
184
    {
185
        return Request::patch($uri, $payload, $mime);
2✔
186
    }
187

188
    /**
189
     * Send a QUERY request (RFC 10008): a safe, idempotent query carried in the
190
     * request body.
191
     *
192
     * @param string     $uri
193
     * @param mixed|null $payload
194
     * @param string     $mime
195
     *
196
     * @return Response
197
     */
198
    public static function query(string $uri, $payload = null, string $mime = Mime::PLAIN): Response
199
    {
NEW
200
        return self::query_request($uri, $payload, $mime)->send();
×
201
    }
202

203
    /**
204
     * @param string     $uri
205
     * @param mixed|null $payload
206
     * @param string     $mime
207
     *
208
     * @return Request
209
     */
210
    public static function query_request(string $uri, $payload = null, string $mime = Mime::PLAIN): Request
211
    {
212
        return Request::query($uri, $payload, $mime);
1✔
213
    }
214

215
    /**
216
     * @param string     $uri
217
     * @param mixed|null $payload
218
     * @param string     $mime
219
     *
220
     * @return Response
221
     */
222
    public static function post(string $uri, $payload = null, string $mime = Mime::PLAIN): Response
223
    {
224
        return self::post_request($uri, $payload, $mime)->send();
1✔
225
    }
226

227
    /**
228
     * @param string     $uri
229
     * @param mixed|null $payload
230
     *
231
     * @return \voku\helper\HtmlDomParser|null
232
     */
233
    public static function post_dom(string $uri, $payload = null)
234
    {
235
        return self::post_request($uri, $payload, Mime::HTML)->send()->getRawBody();
1✔
236
    }
237

238
    /**
239
     * @param string     $uri
240
     * @param mixed|null $payload
241
     *
242
     * @return array<string, mixed>
243
     */
244
    public static function post_form(string $uri, $payload = null): array
245
    {
246
        return self::post_request($uri, $payload, Mime::FORM)->send()->getRawBody();
1✔
247
    }
248

249
    /**
250
     * @param string     $uri
251
     * @param mixed|null $payload
252
     *
253
     * @return mixed
254
     */
255
    public static function post_json(string $uri, $payload = null)
256
    {
257
        return self::post_request($uri, $payload, Mime::JSON)->send()->getRawBody();
1✔
258
    }
259

260
    /**
261
     * @param string     $uri
262
     * @param mixed|null $payload
263
     * @param string     $mime
264
     *
265
     * @return Request
266
     */
267
    public static function post_request(string $uri, $payload = null, string $mime = Mime::PLAIN): Request
268
    {
269
        return Request::post($uri, $payload, $mime)->followRedirects();
9✔
270
    }
271

272
    /**
273
     * @param string     $uri
274
     * @param mixed|null $payload
275
     *
276
     * @return \SimpleXMLElement|null
277
     */
278
    public static function post_xml(string $uri, $payload = null)
279
    {
280
        return self::post_request($uri, $payload, Mime::XML)->send()->getRawBody();
1✔
281
    }
282

283
    /**
284
     * @param string     $uri
285
     * @param mixed|null $payload
286
     * @param string     $mime
287
     *
288
     * @return Response
289
     */
290
    public static function put(string $uri, $payload = null, string $mime = Mime::PLAIN): Response
291
    {
292
        return self::put_request($uri, $payload, $mime)->send();
1✔
293
    }
294

295
    /**
296
     * @param string     $uri
297
     * @param mixed|null $payload
298
     * @param string     $mime
299
     *
300
     * @return Request
301
     */
302
    public static function put_request(string $uri, $payload = null, string $mime = Mime::JSON): Request
303
    {
304
        return Request::put($uri, $payload, $mime);
2✔
305
    }
306

307
    /**
308
     * @param Request|RequestInterface $request
309
     *
310
     * @return Response|ResponseInterface
311
     */
312
    public function sendRequest(RequestInterface $request): ResponseInterface
313
    {
314
        if (!$request instanceof Request) {
20✔
315
            /** @noinspection PhpSillyAssignmentInspection - helper for PhpStorm */
316
            /** @var RequestInterface $request */
317
            $request = $request;
1✔
318

319
            /** @var Request $requestNew */
320
            $requestNew = Request::{$request->getMethod()}($request->getUri());
1✔
321
            $requestNew->withHeaders($request->getHeaders());
1✔
322
            $requestNew->withProtocolVersion($request->getProtocolVersion());
1✔
323
            $requestNew->withBody($request->getBody());
1✔
324
            $requestNew->withRequestTarget($request->getRequestTarget());
1✔
325

326
            $request = $requestNew;
1✔
327
        }
328

329
        return $request->send();
20✔
330
    }
331
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc