@@ -82,13 +82,6 @@ public function __debugInfo(): array
82
82
'handlerStats ' => $ this ->handlerStats (),
83
83
'requestSummary ' => $ this ->request instanceof RequestInterface ? Message::toString ($ this ->request ) : null ,
84
84
'responseSummary ' => Message::toString ($ this ),
85
- // 'headers' => Arr::map(
86
- // $this->headers(),
87
- // fn (array $header, string $name): string => $this->getHeaderLine($name),
88
- // ),
89
- // 'status' => $this->status(),
90
- // 'reason' => $this->reason(),
91
- // 'body' => $this->body(),
92
85
'decodedBody ' => $ this ->json (),
93
86
]);
94
87
}
@@ -159,8 +152,10 @@ public function array(mixed $key = null, mixed $default = null): mixed
159
152
* Get the JSON decoded body of the response as an object.
160
153
*
161
154
* @noinspection JsonEncodingApiUsageInspection
155
+ *
156
+ * @return mixed|object
162
157
*/
163
- public function object (): ? object
158
+ public function object (): mixed
164
159
{
165
160
return json_decode ($ this ->body ());
166
161
}
@@ -267,7 +262,7 @@ public function saveAs(mixed $resourceOrPath): void
267
262
fwrite ($ resource , $ stream ->read (1024 ));
268
263
}
269
264
270
- // rewind($resource);
265
+ rewind ($ resource );
271
266
fclose ($ resource );
272
267
}
273
268
@@ -454,15 +449,11 @@ public function toException(): ?RequestException
454
449
*
455
450
* @throws RequestException
456
451
*/
457
- public function throw (): self
452
+ public function throw (? callable $ callback = null ): self
458
453
{
459
- $ callback = \func_get_args ()[0 ] ?? null ;
460
-
461
454
if ($ this ->failed ()) {
462
455
throw tap ($ this ->toException (), function (?RequestException $ requestException ) use ($ callback ): void {
463
- if ($ callback && \is_callable ($ callback )) {
464
- $ callback ($ this , $ requestException );
465
- }
456
+ $ callback and $ callback ($ this , $ requestException );
466
457
});
467
458
}
468
459
@@ -472,11 +463,13 @@ public function throw(): self
472
463
/**
473
464
* Throw an exception if a server or client error occurred and the given condition evaluates to true.
474
465
*
466
+ * @param bool|\Closure|mixed $condition
467
+ *
475
468
* @throws RequestException
476
469
*/
477
- public function throwIf (bool | \ Closure $ condition ): self
470
+ public function throwIf (mixed $ condition, ? callable $ callback = null ): self
478
471
{
479
- return value ($ condition , $ this ) ? $ this ->throw (\func_get_args ()[ 1 ] ?? null ) : $ this ;
472
+ return value ($ condition , $ this ) ? $ this ->throw ($ callback ) : $ this ;
480
473
}
481
474
482
475
/**
0 commit comments