Skip to content

Commit adfcd5f

Browse files
committed
refactor: orients request shape around body, not data
1 parent f7107db commit adfcd5f

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/Providers/Http/DTO/Request.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* method: string,
2323
* uri: string,
2424
* headers: array<string, list<string>>,
25-
* data?: string|array<string, mixed>|null
25+
* body?: string|null
2626
* }
2727
*
2828
* @extends AbstractDataTransferObject<RequestArrayShape>
@@ -32,7 +32,7 @@ class Request extends AbstractDataTransferObject
3232
public const KEY_METHOD = 'method';
3333
public const KEY_URI = 'uri';
3434
public const KEY_HEADERS = 'headers';
35-
public const KEY_DATA = 'data';
35+
public const KEY_BODY = 'body';
3636

3737
/**
3838
* @var HttpMethodEnum The HTTP method.
@@ -306,9 +306,9 @@ public static function getJsonSchema(): array
306306
],
307307
'description' => 'The request headers.',
308308
],
309-
self::KEY_DATA => [
310-
'type' => ['string', 'array', 'null'],
311-
'description' => 'The request data.',
309+
self::KEY_BODY => [
310+
'type' => ['string', 'null'],
311+
'description' => 'The request body.',
312312
],
313313
],
314314
'required' => [self::KEY_METHOD, self::KEY_URI, self::KEY_HEADERS],
@@ -326,15 +326,14 @@ public function toArray(): array
326326
{
327327
$array = [
328328
self::KEY_METHOD => $this->method->value,
329-
self::KEY_URI => $this->uri,
329+
self::KEY_URI => $this->getUri(), // Include query params if GET with data
330330
self::KEY_HEADERS => $this->headers->getAll(),
331331
];
332332

333-
// Include whichever data type is set
334-
if ($this->body !== null) {
335-
$array[self::KEY_DATA] = $this->body;
336-
} elseif ($this->data !== null) {
337-
$array[self::KEY_DATA] = $this->data;
333+
// Include body if present (getBody() handles the conversion)
334+
$body = $this->getBody();
335+
if ($body !== null) {
336+
$array[self::KEY_BODY] = $body;
338337
}
339338

340339
return $array;
@@ -353,7 +352,7 @@ public static function fromArray(array $array): self
353352
HttpMethodEnum::from($array[self::KEY_METHOD]),
354353
$array[self::KEY_URI],
355354
$array[self::KEY_HEADERS] ?? [],
356-
$array[self::KEY_DATA] ?? null
355+
$array[self::KEY_BODY] ?? null
357356
);
358357
}
359358
}

0 commit comments

Comments
 (0)